/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

MergeĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
# TODO: Up-front, stat all files in order and remove those which are deleted or
18
18
# out-of-date.  Don't actually re-read them until they're needed.  That ought
31
31
 
32
32
import os, stat, time
33
33
 
 
34
from bzrlib.filters import internal_size_sha_file_byname
34
35
from bzrlib.osutils import sha_file, sha_string, pathjoin, safe_unicode
35
36
from bzrlib.trace import mutter, warning
36
37
from bzrlib.atomicfile import AtomicFile
79
80
    """
80
81
    needs_write = False
81
82
 
82
 
    def __init__(self, root, cache_file_name, mode=None):
83
 
        """Create a hash cache in base dir, and set the file mode to mode."""
 
83
    def __init__(self, root, cache_file_name, mode=None,
 
84
            content_filter_stack_provider=None):
 
85
        """Create a hash cache in base dir, and set the file mode to mode.
 
86
 
 
87
        :param content_filter_stack_provider: a function that takes a
 
88
            path (relative to the top of the tree) and a file-id as
 
89
            parameters and returns a stack of ContentFilters.
 
90
            If None, no content filtering is performed.
 
91
        """
84
92
        self.root = safe_unicode(root)
85
93
        self.root_utf8 = self.root.encode('utf8') # where is the filesystem encoding ?
86
94
        self.hit_count = 0
92
100
        self._cache = {}
93
101
        self._mode = mode
94
102
        self._cache_file_name = safe_unicode(cache_file_name)
 
103
        self._filter_provider = content_filter_stack_provider
95
104
 
96
105
    def cache_file_name(self):
97
106
        return self._cache_file_name
161
170
 
162
171
        mode = file_fp[FP_MODE_COLUMN]
163
172
        if stat.S_ISREG(mode):
164
 
            digest = self._really_sha1_file(abspath)
 
173
            if self._filter_provider is None:
 
174
                filters = []
 
175
            else:
 
176
                filters = self._filter_provider(path=path, file_id=None)
 
177
            digest = self._really_sha1_file(abspath, filters)
165
178
        elif stat.S_ISLNK(mode):
166
179
            digest = sha_string(os.readlink(abspath))
167
180
        else:
198
211
            self._cache[path] = (digest, file_fp)
199
212
        return digest
200
213
 
201
 
    def _really_sha1_file(self, abspath):
 
214
    def _really_sha1_file(self, abspath, filters):
202
215
        """Calculate the SHA1 of a file by reading the full text"""
203
 
        return sha_file(file(abspath, 'rb', buffering=65000))
 
216
        return internal_size_sha_file_byname(abspath, filters)[1]
204
217
 
205
218
    def write(self):
206
219
        """Write contents of cache to file."""