/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/inventory.py

  • Committer: Martin
  • Date: 2017-06-05 20:48:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6658.
  • Revision ID: gzlist@googlemail.com-20170605204831-20accykspjcrx0a8
Apply 2to3 dict fixer and clean up resulting mess using view helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    lazy_regex,
49
49
    trace,
50
50
    )
51
 
 
 
51
from .sixish import (
 
52
    viewitems,
 
53
    viewvalues,
 
54
    )
52
55
from .static_tuple import StaticTuple
53
56
 
54
57
 
227
230
 
228
231
    known_kinds = ('file', 'directory', 'symlink')
229
232
 
230
 
    def sorted_children(self):
231
 
        return sorted(self.children.items())
232
 
 
233
233
    @staticmethod
234
234
    def versionable_kind(kind):
235
235
        return (kind in ('file', 'directory', 'symlink', 'tree-reference'))
402
402
        super(InventoryDirectory, self).__init__(file_id, name, parent_id)
403
403
        self.children = {}
404
404
 
 
405
    def sorted_children(self):
 
406
        return sorted(viewitems(self.children))
 
407
 
405
408
    def kind_character(self):
406
409
        """See InventoryEntry.kind_character."""
407
410
        return '/'
665
668
 
666
669
        # unrolling the recursive called changed the time from
667
670
        # 440ms/663ms (inline/total) to 116ms/116ms
668
 
        children = sorted(from_dir.children.items())
 
671
        children = sorted(viewitems(from_dir.children))
669
672
        if not recursive:
670
673
            for name, ie in children:
671
674
                yield name, ie
690
693
                    continue
691
694
 
692
695
                # But do this child first
693
 
                new_children = sorted(ie.children.items())
 
696
                new_children = sorted(viewitems(ie.children))
694
697
                new_children = collections.deque(new_children)
695
698
                stack.append((path, new_children))
696
699
                # Break out of inner loop, so that we start outer loop with child
771
774
            cur_relpath, cur_dir = stack.pop()
772
775
 
773
776
            child_dirs = []
774
 
            for child_name, child_ie in sorted(cur_dir.children.iteritems()):
 
777
            for child_name, child_ie in sorted(viewitems(cur_dir.children)):
775
778
 
776
779
                child_relpath = cur_relpath + child_name
777
780
 
814
817
        """
815
818
        accum = []
816
819
        def descend(dir_ie, dir_path):
817
 
            kids = sorted(dir_ie.children.items())
 
820
            kids = sorted(viewitems(dir_ie.children))
818
821
            for name, ie in kids:
819
822
                child_path = osutils.pathjoin(dir_path, name)
820
823
                accum.append((child_path, ie))
1102
1105
        XXX: We may not want to merge this into bzr.dev.
1103
1106
        """
1104
1107
        if self.root is None:
1105
 
            return
1106
 
        for _, ie in self._byid.iteritems():
1107
 
            yield ie
 
1108
            return ()
 
1109
        return iter(viewvalues(self._byid))
1108
1110
 
1109
1111
    def __len__(self):
1110
1112
        """Returns number of entries."""
1138
1140
                "inventory already contains entry with id {%s}" %
1139
1141
                entry.file_id)
1140
1142
        self._byid[entry.file_id] = entry
1141
 
        for child in getattr(entry, 'children', {}).itervalues():
1142
 
            self._add_child(child)
 
1143
        children = getattr(entry, 'children', {})
 
1144
        if children is not None:
 
1145
            for child in viewvalues(children):
 
1146
                self._add_child(child)
1143
1147
        return entry
1144
1148
 
1145
1149
    def add(self, entry):
1288
1292
            ie = to_find_delete.pop()
1289
1293
            to_delete.append(ie.file_id)
1290
1294
            if ie.kind == 'directory':
1291
 
                to_find_delete.extend(ie.children.values())
 
1295
                to_find_delete.extend(viewvalues(ie.children))
1292
1296
        for file_id in reversed(to_delete):
1293
1297
            ie = self[file_id]
1294
1298
            del self._byid[file_id]
1589
1593
        result = CHKInventory(self._search_key_name)
1590
1594
        if propagate_caches:
1591
1595
            # Just propagate the path-to-fileid cache for now
1592
 
            result._path_to_fileid_cache = dict(self._path_to_fileid_cache.iteritems())
 
1596
            result._path_to_fileid_cache = self._path_to_fileid_cache.copy()
1593
1597
        search_key_func = chk_map.search_key_registry.get(self._search_key_name)
1594
1598
        self.id_to_entry._ensure_root()
1595
1599
        maximum_size = self.id_to_entry._root_node.maximum_size
1708
1712
                continue
1709
1713
            # This loop could potentially be better by using the id_basename
1710
1714
            # map to just get the child file ids.
1711
 
            for child in entry.children.values():
 
1715
            for child in viewvalues(entry.children):
1712
1716
                if child.file_id not in altered:
1713
1717
                    raise errors.InconsistentDelta(self.id2path(child.file_id),
1714
1718
                        child.file_id, "Child not deleted or reparented when "
1720
1724
            # re-keying, but its simpler to just output that as a delete+add
1721
1725
            # to spend less time calculating the delta.
1722
1726
            delta_list = []
1723
 
            for key, (old_key, value) in parent_id_basename_delta.iteritems():
 
1727
            for key, (old_key, value) in viewitems(parent_id_basename_delta):
1724
1728
                if value is not None:
1725
1729
                    delta_list.append((old_key, key, value))
1726
1730
                else: