~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-01-13 20:36:27 UTC
  • mfrom: (1551.9.31 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20070113203627-19221becd2626316
Optimize 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(
 
484
            specific_file_ids=specific_file_ids))
 
485
        num_entries = len(from_entries_by_dir) + len(to_entries_by_dir)
487
486
        entry_count = 0
488
487
        for to_path, to_entry in to_entries_by_dir:
489
488
            file_id = to_entry.file_id
490
489
            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
490
            entry_count += 1
495
491
            changed_content = False
496
492
            from_path, from_entry = from_data.get(file_id, (None, None))
501
497
                from_parent = from_entry.parent_id
502
498
                from_kind, from_executable, from_stat = \
503
499
                    from_tree._comparison_data(from_entry, from_path)
504
 
                if specific_file_ids is None:
505
 
                    entry_count += 1
 
500
                entry_count += 1
506
501
            else:
507
502
                from_versioned = False
508
503
                from_kind = None
538
533
                yield (file_id, to_path, changed_content, versioned, parent,
539
534
                       name, kind, executable)
540
535
 
541
 
        for path, from_entry in from_entries_by_dir:
542
 
            file_id = from_entry.file_id
543
 
            if file_id in to_paths:
544
 
                continue
 
536
        def get_to_path(from_entry):
545
537
            if from_entry.parent_id is None:
546
538
                to_path = ''
547
539
            else:
 
540
                if from_entry.parent_id not in to_paths:
 
541
                    get_to_path(from_tree.inventory[from_entry.parent_id])
548
542
                to_path = osutils.pathjoin(to_paths[from_entry.parent_id],
549
543
                                           from_entry.name)
550
 
            to_paths[file_id] = to_path
551
 
            if (specific_file_ids is not None and 
552
 
                file_id not in specific_file_ids):
 
544
            to_paths[from_entry.file_id] = to_path
 
545
            return to_path
 
546
 
 
547
        for path, from_entry in from_entries_by_dir:
 
548
            file_id = from_entry.file_id
 
549
            if file_id in to_paths:
553
550
                continue
 
551
            to_path = get_to_path(from_entry)
554
552
            entry_count += 1
555
553
            if pb is not None:
556
554
                pb.update('comparing files', entry_count, num_entries)