~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-16 11:08:11 UTC
  • mfrom: (6521 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6522.
  • Revision ID: jelmer@samba.org-20120416110811-0y996ihqy9o2bb1t
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    cache_utf8,
39
39
    config,
40
40
    conflicts as _mod_conflicts,
 
41
    controldir,
41
42
    debug,
42
43
    dirstate,
43
44
    errors,
68
69
    realpath,
69
70
    safe_unicode,
70
71
    )
 
72
from bzrlib.symbol_versioning import (
 
73
    deprecated_in,
 
74
    deprecated_method,
 
75
    )
71
76
from bzrlib.transport.local import LocalTransport
72
77
from bzrlib.tree import (
73
78
    InterTree,
255
260
 
256
261
        :return: an integer. -1 means never save.
257
262
        """
258
 
        # FIXME: We want a WorkingTreeStack here -- vila 20110812
259
 
        conf = config.BranchStack(self.branch)
 
263
        conf = self.get_config_stack()
260
264
        return conf.get('bzr.workingtree.worth_saving_limit')
261
265
 
262
266
    def filter_unversioned_files(self, paths):
415
419
                return link_or_sha1
416
420
        return None
417
421
 
418
 
    def _get_inventory(self):
 
422
    def _get_root_inventory(self):
419
423
        """Get the inventory for the tree. This is only valid within a lock."""
420
424
        if 'evil' in debug.debug_flags:
421
425
            trace.mutter_callsite(2,
426
430
        self._generate_inventory()
427
431
        return self._inventory
428
432
 
 
433
    @deprecated_method(deprecated_in((2, 5, 0)))
 
434
    def _get_inventory(self):
 
435
        return self.root_inventory
 
436
 
429
437
    inventory = property(_get_inventory,
430
438
                         doc="Inventory of this Tree")
431
439
 
 
440
    root_inventory = property(_get_root_inventory,
 
441
        "Root inventory of this tree")
 
442
 
432
443
    @needs_read_lock
433
444
    def get_parent_ids(self):
434
445
        """See Tree.get_parent_ids.
681
692
 
682
693
        if self._inventory is not None:
683
694
            update_inventory = True
684
 
            inv = self.inventory
 
695
            inv = self.root_inventory
685
696
            to_dir_id = to_entry[0][2]
686
697
            to_dir_ie = inv[to_dir_id]
687
698
        else:
883
894
    @needs_read_lock
884
895
    def path2id(self, path):
885
896
        """Return the id for path in this tree."""
 
897
        if isinstance(path, list):
 
898
            if path == []:
 
899
                path = [""]
 
900
            path = osutils.pathjoin(*path)
886
901
        path = path.strip('/')
887
902
        entry = self._get_entry(path=path)
888
903
        if entry == (None, None):
1036
1051
 
1037
1052
        This is a meaningless operation for dirstate, but we obey it anyhow.
1038
1053
        """
1039
 
        return self.inventory
 
1054
        return self.root_inventory
1040
1055
 
1041
1056
    @needs_read_lock
1042
1057
    def revision_tree(self, revision_id):
1150
1165
                # _make_delta if we can't get the RevisionTree
1151
1166
                pass
1152
1167
            else:
1153
 
                delta = rev_tree.inventory._make_delta(basis_tree.inventory)
 
1168
                delta = rev_tree.root_inventory._make_delta(
 
1169
                    basis_tree.root_inventory)
1154
1170
                dirstate.update_basis_by_delta(delta, rev_id)
1155
1171
                updated = True
1156
1172
        if not updated:
1327
1343
        # being created.
1328
1344
        self._inventory = None
1329
1345
        # generate a delta,
1330
 
        delta = inv._make_delta(self.inventory)
 
1346
        delta = inv._make_delta(self.root_inventory)
1331
1347
        # and apply it.
1332
1348
        self.apply_inventory_delta(delta)
1333
1349
        if had_inventory:
1353
1369
            base_tree = trees[0][1]
1354
1370
        state = self.current_dirstate()
1355
1371
        # We don't support ghosts yet
1356
 
        state.set_state_from_scratch(base_tree.inventory, trees, [])
 
1372
        state.set_state_from_scratch(base_tree.root_inventory, trees, [])
1357
1373
 
1358
1374
 
1359
1375
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1597
1613
    def _get_matchingbzrdir(self):
1598
1614
        """Overrideable method to get a bzrdir for testing."""
1599
1615
        # please test against something that will let us do tree references
1600
 
        return bzrdir.format_registry.make_bzrdir(
1601
 
            'dirstate-with-subtree')
 
1616
        return controldir.format_registry.make_bzrdir(
 
1617
            'development-subtree')
1602
1618
 
1603
1619
    _matchingbzrdir = property(__get_matchingbzrdir)
1604
1620
 
1765
1781
        if path is not None:
1766
1782
            path = path.encode('utf8')
1767
1783
        parent_index = self._get_parent_index()
1768
 
        return self._dirstate._get_entry(parent_index, fileid_utf8=file_id, path_utf8=path)
 
1784
        return self._dirstate._get_entry(parent_index, fileid_utf8=file_id,
 
1785
            path_utf8=path)
1769
1786
 
1770
1787
    def _generate_inventory(self):
1771
1788
        """Create and set self.inventory from the dirstate object.
1872
1889
 
1873
1890
    @needs_read_lock
1874
1891
    def get_file_revision(self, file_id):
1875
 
        return self.inventory[file_id].revision
 
1892
        inv, inv_file_id = self._unpack_file_id(file_id)
 
1893
        return inv[inv_file_id].revision
1876
1894
 
1877
1895
    def get_file(self, file_id, path=None):
1878
1896
        return StringIO(self.get_file_text(file_id))
1879
1897
 
1880
1898
    def get_file_size(self, file_id):
1881
1899
        """See Tree.get_file_size"""
1882
 
        return self.inventory[file_id].text_size
 
1900
        inv, inv_file_id = self._unpack_file_id(file_id)
 
1901
        return inv[inv_file_id].text_size
1883
1902
 
1884
1903
    def get_file_text(self, file_id, path=None):
1885
1904
        _, content = list(self.iter_files_bytes([(file_id, None)]))[0]
1886
1905
        return ''.join(content)
1887
1906
 
1888
1907
    def get_reference_revision(self, file_id, path=None):
1889
 
        return self.inventory[file_id].reference_revision
 
1908
        inv, inv_file_id = self._unpack_file_id(file_id)
 
1909
        return inv[inv_file_id].reference_revision
1890
1910
 
1891
1911
    def iter_files_bytes(self, desired_files):
1892
1912
        """See Tree.iter_files_bytes.
1916
1936
        """Return the revision id for this tree."""
1917
1937
        return self._revision_id
1918
1938
 
1919
 
    def _get_inventory(self):
 
1939
    def _get_root_inventory(self):
1920
1940
        if self._inventory is not None:
1921
1941
            return self._inventory
1922
1942
        self._must_be_locked()
1923
1943
        self._generate_inventory()
1924
1944
        return self._inventory
1925
1945
 
 
1946
    root_inventory = property(_get_root_inventory,
 
1947
                         doc="Inventory of this Tree")
 
1948
 
 
1949
    @deprecated_method(deprecated_in((2, 5, 0)))
 
1950
    def _get_inventory(self):
 
1951
        return self.root_inventory
 
1952
 
1926
1953
    inventory = property(_get_inventory,
1927
1954
                         doc="Inventory of this Tree")
1928
1955
 
1946
1973
 
1947
1974
    def path_content_summary(self, path):
1948
1975
        """See Tree.path_content_summary."""
1949
 
        id = self.inventory.path2id(path)
1950
 
        if id is None:
 
1976
        inv, inv_file_id = self._path2inv_file_id(path)
 
1977
        if inv_file_id is None:
1951
1978
            return ('missing', None, None, None)
1952
 
        entry = self._inventory[id]
 
1979
        entry = inv[inv_file_id]
1953
1980
        kind = entry.kind
1954
1981
        if kind == 'file':
1955
1982
            return (kind, entry.text_size, entry.executable, entry.text_sha1)
1959
1986
            return (kind, None, None, None)
1960
1987
 
1961
1988
    def is_executable(self, file_id, path=None):
1962
 
        ie = self.inventory[file_id]
 
1989
        inv, inv_file_id = self._unpack_file_id(file_id)
 
1990
        ie = inv[inv_file_id]
1963
1991
        if ie.kind != "file":
1964
1992
            return False
1965
1993
        return ie.executable
1970
1998
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1971
1999
        # We use a standard implementation, because DirStateRevisionTree is
1972
2000
        # dealing with one of the parents of the current state
1973
 
        inv = self._get_inventory()
1974
2001
        if from_dir is None:
 
2002
            inv = self.root_inventory
1975
2003
            from_dir_id = None
1976
2004
        else:
1977
 
            from_dir_id = inv.path2id(from_dir)
 
2005
            inv, from_dir_id = self._path2inv_file_id(from_dir)
1978
2006
            if from_dir_id is None:
1979
2007
                # Directory not versioned
1980
2008
                return
 
2009
        # FIXME: Support nested trees
1981
2010
        entries = inv.iter_entries(from_dir=from_dir_id, recursive=recursive)
1982
2011
        if inv.root is not None and not include_root and from_dir is None:
1983
2012
            entries.next()
2005
2034
    def path2id(self, path):
2006
2035
        """Return the id for path in this tree."""
2007
2036
        # lookup by path: faster than splitting and walking the ivnentory.
 
2037
        if isinstance(path, list):
 
2038
            if path == []:
 
2039
                path = [""]
 
2040
            path = osutils.pathjoin(*path)
2008
2041
        entry = self._get_entry(path=path)
2009
2042
        if entry == (None, None):
2010
2043
            return None
2033
2066
        # So for now, we just build up the parent inventory, and extract
2034
2067
        # it the same way RevisionTree does.
2035
2068
        _directory = 'directory'
2036
 
        inv = self._get_inventory()
 
2069
        inv = self._get_root_inventory()
2037
2070
        top_id = inv.path2id(prefix)
2038
2071
        if top_id is None:
2039
2072
            pending = []