~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Ian Clatworthy
  • Date: 2008-04-17 14:10:33 UTC
  • mto: (4171.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 4173.
  • Revision ID: ian.clatworthy@canonical.com-20080417141033-0fnc7oe07535rw90
make content filter lookup a tree responsibility

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
    """
82
82
    needs_write = False
83
83
 
84
 
    def __init__(self, root, cache_file_name, mode=None):
85
 
        """Create a hash cache in base dir, and set the file mode to mode."""
 
84
    def __init__(self, root, cache_file_name, mode=None,
 
85
            content_filter_stack_provider=None):
 
86
        """Create a hash cache in base dir, and set the file mode to mode.
 
87
 
 
88
        :param content_filter_stack_provider: a function that expects a
 
89
            path (relative to the top of the tree) as a parameter and
 
90
            returns the stack of ContentFilter's for that path. If None,
 
91
            no content filtering is performed.
 
92
        """
86
93
        self.root = safe_unicode(root)
87
94
        self.root_utf8 = self.root.encode('utf8') # where is the filesystem encoding ?
88
95
        self.hit_count = 0
94
101
        self._cache = {}
95
102
        self._mode = mode
96
103
        self._cache_file_name = safe_unicode(cache_file_name)
 
104
        self._cfs_provider = content_filter_stack_provider
97
105
 
98
106
    def cache_file_name(self):
99
107
        return self._cache_file_name
163
171
 
164
172
        mode = file_fp[FP_MODE_COLUMN]
165
173
        if stat.S_ISREG(mode):
166
 
            digest = self._really_sha1_file(abspath)
 
174
            if self._cfs_provider is None:
 
175
                filters = None
 
176
            else:
 
177
                filters = self._cfs_provider(path)
 
178
            digest = self._really_sha1_file(abspath, filters)
167
179
        elif stat.S_ISLNK(mode):
168
180
            digest = sha.new(os.readlink(abspath)).hexdigest()
169
181
        else:
200
212
            self._cache[path] = (digest, file_fp)
201
213
        return digest
202
214
 
203
 
    def _really_sha1_file(self, abspath):
 
215
    def _really_sha1_file(self, abspath, filters):
204
216
        """Calculate the SHA1 of a file by reading the full text"""
205
 
        return sha_file_by_name(abspath)
 
217
        return sha_file_by_name(abspath, filters)
206
218
        
207
219
    def write(self):
208
220
        """Write contents of cache to file."""