~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-20 05:08:48 UTC
  • mfrom: (4171.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090320050848-c1wdgzf5kkfdt1ys
Content filters (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
 
70
70
from bzrlib import symbol_versioning
71
71
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
72
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
72
73
from bzrlib.inventory import InventoryEntry, Inventory, ROOT_ID, entry_factory
73
74
import bzrlib.mutabletree
74
75
from bzrlib.mutabletree import needs_tree_write_lock
246
247
            return self._dirstate
247
248
        local_path = self.bzrdir.get_workingtree_transport(None
248
249
            ).local_abspath('dirstate')
249
 
        self._dirstate = dirstate.DirState.on_file(local_path)
 
250
        self._dirstate = dirstate.DirState.on_file(local_path,
 
251
            self._sha1_provider())
250
252
        return self._dirstate
251
253
 
 
254
    def _sha1_provider(self):
 
255
        """A function that returns a SHA1Provider suitable for this tree.
 
256
 
 
257
        :return: None if content filtering is not supported by this tree.
 
258
          Otherwise, a SHA1Provider is returned that sha's the canonical
 
259
          form of files, i.e. after read filters are applied.
 
260
        """
 
261
        if self.supports_content_filtering():
 
262
            return ContentFilterAwareSHA1Provider(self)
 
263
        else:
 
264
            return None
 
265
 
252
266
    def filter_unversioned_files(self, paths):
253
267
        """Filter out paths that are versioned.
254
268
 
1283
1297
        self.flush()
1284
1298
 
1285
1299
 
 
1300
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
 
1301
 
 
1302
    def __init__(self, tree):
 
1303
        self.tree = tree
 
1304
 
 
1305
    def sha1(self, abspath):
 
1306
        """Return the sha1 of a file given its absolute path."""
 
1307
        filters = self.tree._content_filter_stack(self.tree.relpath(abspath))
 
1308
        return internal_size_sha_file_byname(abspath, filters)[1]
 
1309
 
 
1310
    def stat_and_sha1(self, abspath):
 
1311
        """Return the stat and sha1 of a file given its absolute path."""
 
1312
        filters = self.tree._content_filter_stack(self.tree.relpath(abspath))
 
1313
        file_obj = file(abspath, 'rb', 65000)
 
1314
        try:
 
1315
            statvalue = os.fstat(file_obj.fileno())
 
1316
            if filters:
 
1317
                file_obj = filtered_input_file(file_obj, filters)
 
1318
            sha1 = osutils.size_sha_file(file_obj)[1]
 
1319
        finally:
 
1320
            file_obj.close()
 
1321
        return statvalue, sha1
 
1322
 
 
1323
 
1286
1324
class WorkingTree4(DirStateWorkingTree):
1287
1325
    """This is the Format 4 working tree.
1288
1326