~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisiontree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-07 08:11:19 UTC
  • mfrom: (4241.6.7 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090407081119-1sok81r9ekyriw0y
(robertc) Add InterCHKRevisionTree. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    osutils,
24
24
    revision,
25
25
    symbol_versioning,
 
26
    tree,
26
27
    )
27
 
from bzrlib.tree import Tree
28
 
 
29
 
 
30
 
class RevisionTree(Tree):
 
28
 
 
29
 
 
30
class RevisionTree(tree.Tree):
31
31
    """Tree viewing a previous revision.
32
32
 
33
33
    File text can be retrieved from the text store.
208
208
            self._rules_searcher = super(RevisionTree,
209
209
                self)._get_rules_searcher(default_searcher)
210
210
        return self._rules_searcher
 
211
 
 
212
 
 
213
class InterCHKRevisionTree(tree.InterTree):
 
214
    """Fast path optimiser for RevisionTrees with CHK inventories."""
 
215
 
 
216
    @staticmethod
 
217
    def is_compatible(source, target):
 
218
        if (isinstance(source, RevisionTree)
 
219
            and isinstance(target, RevisionTree)):
 
220
            try:
 
221
                # Only CHK inventories have id_to_entry attribute
 
222
                source.inventory.id_to_entry
 
223
                target.inventory.id_to_entry
 
224
                return True
 
225
            except AttributeError:
 
226
                pass
 
227
        return False
 
228
 
 
229
    def iter_changes(self, include_unchanged=False,
 
230
                     specific_files=None, pb=None, extra_trees=[],
 
231
                     require_versioned=True, want_unversioned=False):
 
232
        lookup_trees = [self.source]
 
233
        if extra_trees:
 
234
             lookup_trees.extend(extra_trees)
 
235
        if specific_files == []:
 
236
            specific_file_ids = []
 
237
        else:
 
238
            specific_file_ids = self.target.paths2ids(specific_files,
 
239
                lookup_trees, require_versioned=require_versioned)
 
240
 
 
241
        # FIXME: It should be possible to delegate include_unchanged handling
 
242
        # to CHKInventory.iter_changes and do a better job there -- vila
 
243
        # 20090304
 
244
        if include_unchanged:
 
245
            changed_file_ids = []
 
246
        for result in self.target.inventory.iter_changes(self.source.inventory):
 
247
            if (specific_file_ids is not None
 
248
                and not result[0] in specific_file_ids):
 
249
                # CHKMap.iter_changes is clean and fast. Better filter out
 
250
                # the specific files *after* it did its job.
 
251
                continue
 
252
            yield result
 
253
            if include_unchanged:
 
254
                # Keep track of yielded results (cheaper than building the
 
255
                # whole inventory).
 
256
                changed_file_ids.append(result[0])
 
257
        if include_unchanged:
 
258
            # CHKMap avoid being O(tree), so we go to O(tree) only if
 
259
            # required to.
 
260
            # Now walk the whole inventory, excluding the already yielded
 
261
            # file ids
 
262
            changed_file_ids = set(changed_file_ids)
 
263
            for relpath, entry in self.target.inventory.iter_entries():
 
264
                if (specific_file_ids is not None
 
265
                    and not entry.file_id in specific_file_ids):
 
266
                    continue
 
267
                if not entry.file_id in changed_file_ids:
 
268
                    yield (entry.file_id,
 
269
                           (relpath, relpath), # Not renamed
 
270
                           False, # Not modified
 
271
                           (True, True), # Still  versioned
 
272
                           (entry.parent_id, entry.parent_id),
 
273
                           (entry.name, entry.name),
 
274
                           (entry.kind, entry.kind),
 
275
                           (entry.executable, entry.executable))
 
276
 
 
277
 
 
278
tree.InterTree.register_optimiser(InterCHKRevisionTree)