~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

Optimize Tree._iter_changes with specific file_ids

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
        """
142
142
        return self.bzrdir.is_control_filename(filename)
143
143
 
144
 
    def iter_entries_by_dir(self):
 
144
    def iter_entries_by_dir(self, specific_file_ids=None):
145
145
        """Walk the tree in 'by_dir' order.
146
146
 
147
147
        This will yield each entry in the tree as a (path, entry) tuple. The
149
149
        preceeded by the parent of a directory, and all the contents of a 
150
150
        directory are grouped together.
151
151
        """
152
 
        return self.inventory.iter_entries_by_dir()
 
152
        return self.inventory.iter_entries_by_dir(
 
153
            specific_file_ids=specific_file_ids)
153
154
 
154
155
    def kind(self, file_id):
155
156
        raise NotImplementedError("subclasses must implement kind")
476
477
        Iteration is done in parent-to-child order, relative to the to_tree.
477
478
        """
478
479
        to_paths = {}
479
 
        from_entries_by_dir = list(from_tree.inventory.iter_entries_by_dir())
 
480
        from_entries_by_dir = list(from_tree.inventory.iter_entries_by_dir(
 
481
            specific_file_ids=specific_file_ids))
480
482
        from_data = dict((e.file_id, (p, e)) for p, e in from_entries_by_dir)
481
 
        to_entries_by_dir = list(to_tree.inventory.iter_entries_by_dir())
482
 
        if specific_file_ids is not None:
483
 
            specific_file_ids = set(specific_file_ids)
484
 
            num_entries = len(specific_file_ids)
485
 
        else:
486
 
            num_entries = len(from_entries_by_dir) + len(to_entries_by_dir)
 
483
        to_entries_by_dir = list(to_tree.inventory.iter_entries_by_dir(specific_file_ids=specific_file_ids))
 
484
        num_entries = len(from_entries_by_dir) + len(to_entries_by_dir)
487
485
        entry_count = 0
488
486
        for to_path, to_entry in to_entries_by_dir:
489
487
            file_id = to_entry.file_id
490
488
            to_paths[file_id] = to_path
491
 
            if (specific_file_ids is not None and 
492
 
                file_id not in specific_file_ids):
493
 
                continue
494
489
            entry_count += 1
495
490
            changed_content = False
496
491
            from_path, from_entry = from_data.get(file_id, (None, None))
501
496
                from_parent = from_entry.parent_id
502
497
                from_kind, from_executable, from_stat = \
503
498
                    from_tree._comparison_data(from_entry, from_path)
504
 
                if specific_file_ids is None:
505
 
                    entry_count += 1
 
499
                entry_count += 1
506
500
            else:
507
501
                from_versioned = False
508
502
                from_kind = None
548
542
                to_path = osutils.pathjoin(to_paths[from_entry.parent_id],
549
543
                                           from_entry.name)
550
544
            to_paths[file_id] = to_path
551
 
            if (specific_file_ids is not None and 
552
 
                file_id not in specific_file_ids):
553
 
                continue
554
545
            entry_count += 1
555
546
            if pb is not None:
556
547
                pb.update('comparing files', entry_count, num_entries)