/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 breezy/hashcache.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# TODO: Perhaps use a Python pickle instead of a text file; might be faster.
29
29
 
30
30
 
31
 
 
32
31
CACHE_HEADER = b"### bzr hashcache v5\n"
33
32
 
34
33
import os
53
52
FP_MODE_COLUMN = 5
54
53
 
55
54
 
56
 
 
57
55
class HashCache(object):
58
56
    """Cache for looking up file SHA-1.
59
57
 
91
89
    needs_write = False
92
90
 
93
91
    def __init__(self, root, cache_file_name, mode=None,
94
 
            content_filter_stack_provider=None):
 
92
                 content_filter_stack_provider=None):
95
93
        """Create a hash cache in base dir, and set the file mode to mode.
96
94
 
97
95
        :param content_filter_stack_provider: a function that takes a
165
163
            cache_sha1, cache_fp = None, None
166
164
 
167
165
        if cache_fp == file_fp:
168
 
            ## mutter("hashcache hit for %s %r -> %s", path, file_fp, cache_sha1)
169
 
            ## mutter("now = %s", time.time())
170
166
            self.hit_count += 1
171
167
            return cache_sha1
172
168
 
177
173
            if self._filter_provider is None:
178
174
                filters = []
179
175
            else:
180
 
                filters = self._filter_provider(path=path, file_id=None)
 
176
                filters = self._filter_provider(path=path)
181
177
            digest = self._really_sha1_file(abspath, filters)
182
178
        elif stat.S_ISLNK(mode):
183
179
            target = osutils.readlink(abspath)
209
205
                self.needs_write = True
210
206
                del self._cache[path]
211
207
        else:
212
 
            ## mutter('%r added to cache: now=%f, mtime=%d, ctime=%d',
 
208
            # mutter('%r added to cache: now=%f, mtime=%d, ctime=%d',
213
209
            ##        path, time.time(), file_fp[FP_MTIME_COLUMN],
214
 
            ##        file_fp[FP_CTIME_COLUMN])
 
210
            # file_fp[FP_CTIME_COLUMN])
215
211
            self.update_count += 1
216
212
            self.needs_write = True
217
213
            self._cache[path] = (digest, file_fp)
224
220
    def write(self):
225
221
        """Write contents of cache to file."""
226
222
        with atomicfile.AtomicFile(self.cache_file_name(), 'wb',
227
 
                new_mode=self._mode) as outf:
 
223
                                   new_mode=self._mode) as outf:
228
224
            outf.write(CACHE_HEADER)
229
225
 
230
 
            for path, c  in viewitems(self._cache):
 
226
            for path, c in viewitems(self._cache):
231
227
                line_info = [path.encode('utf-8'), b'// ', c[0], b' ']
232
228
                line_info.append(b'%d %d %d %d %d %d' % c[1])
233
229
                line_info.append(b'\n')
234
230
                outf.write(b''.join(line_info))
235
231
            self.needs_write = False
236
 
            ## mutter("write hash cache: %s hits=%d misses=%d stat=%d recent=%d updates=%d",
237
 
            ##        self.cache_file_name(), self.hit_count, self.miss_count,
238
 
            ##        self.stat_count,
239
 
            ##        self.danger_count, self.update_count)
 
232
            # mutter("write hash cache: %s hits=%d misses=%d stat=%d recent=%d updates=%d",
 
233
            #        self.cache_file_name(), self.hit_count, self.miss_count,
 
234
            # self.stat_count,
 
235
            # self.danger_count, self.update_count)
240
236
 
241
237
    def read(self):
242
238
        """Reinstate cache from file.