~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
83
83
    def __init__(self, root, cache_file_name, mode=None):
84
84
        """Create a hash cache in base dir, and set the file mode to mode."""
85
85
        self.root = safe_unicode(root)
86
 
        self.root_utf8 = self.root.encode('utf8') # where is the filesystem encoding ?
87
86
        self.hit_count = 0
88
87
        self.miss_count = 0
89
88
        self.stat_count = 0
129
128
                self.needs_write = True
130
129
                del self._cache[path]
131
130
 
132
 
    def get_sha1(self, path, stat_value=None):
 
131
    def get_sha1(self, path):
133
132
        """Return the sha1 of a file.
134
133
        """
135
 
        if path.__class__ is str:
136
 
            abspath = pathjoin(self.root_utf8, path)
137
 
        else:
138
 
            abspath = pathjoin(self.root, path)
 
134
        abspath = pathjoin(self.root, path)
139
135
        self.stat_count += 1
140
 
        file_fp = self._fingerprint(abspath, stat_value)
 
136
        file_fp = self._fingerprint(abspath)
141
137
        
142
138
        if not file_fp:
143
139
            # not a regular file or not existing
281
277
        """
282
278
        return int(time.time()) - 3
283
279
           
284
 
    def _fingerprint(self, abspath, stat_value=None):
285
 
        if stat_value is None:
286
 
            try:
287
 
                stat_value = os.lstat(abspath)
288
 
            except OSError:
289
 
                # might be missing, etc
290
 
                return None
291
 
        if stat.S_ISDIR(stat_value.st_mode):
 
280
    def _fingerprint(self, abspath):
 
281
        try:
 
282
            fs = os.lstat(abspath)
 
283
        except OSError:
 
284
            # might be missing, etc
 
285
            return None
 
286
        if stat.S_ISDIR(fs.st_mode):
292
287
            return None
293
288
        # we discard any high precision because it's not reliable; perhaps we
294
289
        # could do better on some systems?
295
 
        return (stat_value.st_size, long(stat_value.st_mtime),
296
 
                long(stat_value.st_ctime), stat_value.st_ino, 
297
 
                stat_value.st_dev, stat_value.st_mode)
 
290
        return (fs.st_size, long(fs.st_mtime),
 
291
                long(fs.st_ctime), fs.st_ino, fs.st_dev, fs.st_mode)