b.h.HashCache(object) : class documentation

Part of bzrlib.hashcache View In Hierarchy

Known subclasses: bzrlib.tests.test_hashcache.FakeHashCache

Cache for looking up file SHA-1.

Files are considered to match the cached value if the fingerprint of the file has not changed. This includes its mtime, ctime, device number, inode number, and size. This should catch modifications or replacement of the file by a new one.

This may not catch modifications that do not change the file's size and that occur within the resolution window of the timestamps. To handle this we specifically do not cache files which have changed since the start of the present second, since they could undetectably change again.

This scheme may fail if the machine's clock steps backwards. Don't do that.

This does not canonicalize the paths passed in; that should be done by the caller.

_cache
Indexed by path, points to a two-tuple of the SHA-1 of the file. and its fingerprint.
stat_count
number of times files have been statted
hit_count
number of times files have been retrieved from the cache, avoiding a re-read
miss_count
number of misses (times files have been completely re-read)
Method __init__ Create a hash cache in base dir, and set the file mode to mode.
Method cache_file_name Undocumented
Method clear Discard all cached information.
Method scan Scan all files and remove entries where the cache entry is obsolete.
Method get_sha1 Return the sha1 of a file.
Method write Write contents of cache to file.
Method read Reinstate cache from file.
Method _really_sha1_file Calculate the SHA1 of a file by reading the full text
Method _cutoff_time Return cutoff time.
Method _fingerprint Undocumented
def __init__(self, root, cache_file_name, mode=None, content_filter_stack_provider=None):
Create a hash cache in base dir, and set the file mode to mode.
Parameterscontent_filter_stack_providera function that takes a path (relative to the top of the tree) and a file-id as parameters and returns a stack of ContentFilters. If None, no content filtering is performed.
def cache_file_name(self):
Undocumented
def clear(self):
Discard all cached information.

This does not reset the counters.

def scan(self):
Scan all files and remove entries where the cache entry is obsolete.

Obsolete entries are those where the file has been modified or deleted since the entry was inserted.

def get_sha1(self, path, stat_value=None):
Return the sha1 of a file.
def _really_sha1_file(self, abspath, filters):
Calculate the SHA1 of a file by reading the full text
def write(self):
Write contents of cache to file.
def read(self):
Reinstate cache from file.

Overwrites existing cache.

If the cache file has the wrong version marker, this just clears the cache.

def _cutoff_time(self):
Return cutoff time.

Files modified more recently than this time are at risk of being undetectably modified and so can't be cached.

def _fingerprint(self, abspath, stat_value=None):
Undocumented
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.