/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

First attempt to merge .dev and resolve the conflicts (but tests are 
failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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 ?
86
87
        self.hit_count = 0
87
88
        self.miss_count = 0
88
89
        self.stat_count = 0
128
129
                self.needs_write = True
129
130
                del self._cache[path]
130
131
 
131
 
    def get_sha1(self, path):
 
132
    def get_sha1(self, path, stat_value=None):
132
133
        """Return the sha1 of a file.
133
134
        """
134
 
        abspath = pathjoin(self.root, path)
 
135
        if path.__class__ is str:
 
136
            abspath = pathjoin(self.root_utf8, path)
 
137
        else:
 
138
            abspath = pathjoin(self.root, path)
135
139
        self.stat_count += 1
136
 
        file_fp = self._fingerprint(abspath)
 
140
        file_fp = self._fingerprint(abspath, stat_value)
137
141
        
138
142
        if not file_fp:
139
143
            # not a regular file or not existing
206
210
            outf.write(CACHE_HEADER)
207
211
 
208
212
            for path, c  in self._cache.iteritems():
209
 
                assert '//' not in path, path
210
213
                line_info = [path.encode('utf-8'), '// ', c[0], ' ']
211
214
                line_info.append(' '.join([str(fld) for fld in c[1]]))
212
215
                line_info.append('\n')
277
280
        """
278
281
        return int(time.time()) - 3
279
282
           
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):
 
283
    def _fingerprint(self, abspath, stat_value=None):
 
284
        if stat_value is None:
 
285
            try:
 
286
                stat_value = os.lstat(abspath)
 
287
            except OSError:
 
288
                # might be missing, etc
 
289
                return None
 
290
        if stat.S_ISDIR(stat_value.st_mode):
287
291
            return None
288
292
        # we discard any high precision because it's not reliable; perhaps we
289
293
        # could do better on some systems?
290
 
        return (fs.st_size, long(fs.st_mtime),
291
 
                long(fs.st_ctime), fs.st_ino, fs.st_dev, fs.st_mode)
 
294
        return (stat_value.st_size, long(stat_value.st_mtime),
 
295
                long(stat_value.st_ctime), stat_value.st_ino, 
 
296
                stat_value.st_dev, stat_value.st_mode)