/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 bzrlib/inventory.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-21 16:52:18 UTC
  • mfrom: (4761 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4771.
  • Revision ID: john@arbash-meinel.com-20091021165218-rxk2tt2ks7amc6m9
Bring in bzr.dev 4761 which includes CHKMap and CHKInventory tweaks.
It also brings in StaticTuple concatenation, and ability to hold None, etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
1600
1600
        interesting.add(None) # this will auto-filter it in the loop
1601
1601
        remaining_parents.discard(None) 
1602
1602
        while remaining_parents:
 
1603
            if None in remaining_parents:
 
1604
                import pdb; pdb.set_trace()
1603
1605
            next_parents = set()
1604
1606
            for entry in self._getitems(remaining_parents):
1605
1607
                next_parents.add(entry.parent_id)
1614
1616
        while directories_to_expand:
1615
1617
            # Expand directories by looking in the
1616
1618
            # parent_id_basename_to_file_id map
1617
 
            keys = [StaticTuple(f,).intern() for f in directories_to_expand]
 
1619
            keys = [(f,) for f in directories_to_expand]
1618
1620
            directories_to_expand = set()
1619
1621
            items = self.parent_id_basename_to_file_id.iteritems(keys)
1620
1622
            next_file_ids = set([item[1] for item in items])
1677
1679
        # to filter out empty names because of non rich-root...
1678
1680
        sections = bytes.split('\n')
1679
1681
        kind, file_id = sections[0].split(': ')
1680
 
        return (sections[2], intern(file_id), intern(sections[3]))
 
1682
        return (sections[2], file_id, sections[3])
1681
1683
 
1682
1684
    def _bytes_to_entry(self, bytes):
1683
1685
        """Deserialise a serialised entry."""
1705
1707
            result.reference_revision = sections[4]
1706
1708
        else:
1707
1709
            raise ValueError("Not a serialised entry %r" % bytes)
1708
 
        result.file_id = intern(result.file_id)
1709
 
        result.revision = intern(sections[3])
 
1710
        result.revision = sections[3]
1710
1711
        if result.parent_id == '':
1711
1712
            result.parent_id = None
1712
1713
        self._fileid_to_entry_cache[result.file_id] = result
1815
1816
                # Update caches. It's worth doing this whether
1816
1817
                # we're propagating the old caches or not.
1817
1818
                result._path_to_fileid_cache[new_path] = file_id
1818
 
                parents.add((split(new_path)[0], entry.parent_id))
 
1819
                if entry.parent_id is not None:
 
1820
                    parents.add((split(new_path)[0], entry.parent_id))
1819
1821
            if old_path is None:
1820
1822
                old_key = None
1821
1823
            else:
1825
1827
                        "Entry was at wrong other path %r." %
1826
1828
                        self.id2path(file_id))
1827
1829
                altered.add(file_id)
1828
 
            id_to_entry_delta.append(StaticTuple(old_key, new_key, new_value))
 
1830
            # TODO: use a StaticTuple here, though a value may be None
 
1831
            id_to_entry_delta.append((old_key, new_key, new_value))
1829
1832
            if result.parent_id_basename_to_file_id is not None:
1830
1833
                # parent_id, basename changes
1831
1834
                if old_path is None:
2013
2016
            return result
2014
2017
        try:
2015
2018
            return self._bytes_to_entry(
2016
 
                self.id_to_entry.iteritems([StaticTuple(file_id,)]).next()[1])
 
2019
                self.id_to_entry.iteritems([(file_id,)]).next()[1])
2017
2020
        except StopIteration:
2018
2021
            # really we're passing an inventory, not a tree...
2019
2022
            raise errors.NoSuchId(self, file_id)
2032
2035
                remaining.append(file_id)
2033
2036
            else:
2034
2037
                result.append(entry)
2035
 
        file_keys = [StaticTuple(f,).intern() for f in remaining]
 
2038
        file_keys = [(f,) for f in remaining]
2036
2039
        for file_key, value in self.id_to_entry.iteritems(file_keys):
2037
2040
            entry = self._bytes_to_entry(value)
2038
2041
            result.append(entry)
2043
2046
        # Perhaps have an explicit 'contains' method on CHKMap ?
2044
2047
        if self._fileid_to_entry_cache.get(file_id, None) is not None:
2045
2048
            return True
2046
 
        return len(list(
2047
 
            self.id_to_entry.iteritems([StaticTuple(file_id,)]))) == 1
 
2049
        return len(list(self.id_to_entry.iteritems([(file_id,)]))) == 1
2048
2050
 
2049
2051
    def is_root(self, file_id):
2050
2052
        return file_id == self.root_id
2202
2204
            basename_utf8 = basename.encode('utf8')
2203
2205
            file_id = self._path_to_fileid_cache.get(cur_path, None)
2204
2206
            if file_id is None:
2205
 
                key_filter = [StaticTuple(current_id, basename_utf8)]
 
2207
                key_filter = [(current_id, basename_utf8)]
2206
2208
                items = parent_id_index.iteritems(key_filter)
2207
2209
                for (parent_id, name_utf8), file_id in items:
2208
2210
                    if parent_id != current_id or name_utf8 != basename_utf8:
2232
2234
            lines.append("root_id: %s\n" % self.root_id)
2233
2235
            if self.parent_id_basename_to_file_id is not None:
2234
2236
                lines.append('parent_id_basename_to_file_id: %s\n' %
2235
 
                    (self.parent_id_basename_to_file_id.key()[0],))
2236
 
            lines.append("id_to_entry: %s\n" % (self.id_to_entry.key()[0],))
 
2237
                    self.parent_id_basename_to_file_id.key())
 
2238
            lines.append("id_to_entry: %s\n" % self.id_to_entry.key())
2237
2239
        return lines
2238
2240
 
2239
2241
    @property
2280
2282
        parent_id_index = self._chk_inventory.parent_id_basename_to_file_id
2281
2283
        child_keys = set()
2282
2284
        for (parent_id, name_utf8), file_id in parent_id_index.iteritems(
2283
 
            key_filter=[StaticTuple(self.file_id,)]):
2284
 
            child_keys.add(StaticTuple(file_id,))
 
2285
            key_filter=[(self.file_id,)]):
 
2286
            child_keys.add((file_id,))
2285
2287
        cached = set()
2286
2288
        for file_id_key in child_keys:
2287
2289
            entry = self._chk_inventory._fileid_to_entry_cache.get(