~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisiontree.py

Implement a proper InterCHKRevisionTree.iter_changes and some other cleanups

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