/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/workingtree_4.py

merge bzr.dev r4042

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    trace,
59
59
    transform,
60
60
    urlutils,
 
61
    views,
61
62
    xml5,
62
63
    xml6,
63
64
    )
96
97
from bzrlib.workingtree import WorkingTree, WorkingTree3, WorkingTreeFormat3
97
98
 
98
99
 
99
 
class WorkingTree4(WorkingTree3):
100
 
    """This is the Format 4 working tree.
101
 
 
102
 
    This differs from WorkingTree3 by:
103
 
     - Having a consolidated internal dirstate, stored in a
104
 
       randomly-accessible sorted file on disk.
105
 
     - Not having a regular inventory attribute.  One can be synthesized 
106
 
       on demand but this is expensive and should be avoided.
107
 
 
108
 
    This is new in bzr 0.15.
109
 
    """
110
 
 
 
100
class DirStateWorkingTree(WorkingTree3):
111
101
    def __init__(self, basedir,
112
102
                 branch,
113
103
                 _control_files=None,
140
130
        self._setup_directory_is_tree_reference()
141
131
        self._detect_case_handling()
142
132
        self._rules_searcher = None
 
133
        self.views = self._make_views()
143
134
        #--- allow tests to select the dirstate iter_changes implementation
144
135
        self._iter_changes = dirstate._process_entry
145
136
 
175
166
    @needs_tree_write_lock
176
167
    def add_reference(self, sub_tree):
177
168
        # use standard implementation, which calls back to self._add
178
 
        # 
 
169
        #
179
170
        # So we don't store the reference_revision in the working dirstate,
180
 
        # it's just recorded at the moment of commit. 
 
171
        # it's just recorded at the moment of commit.
181
172
        self._add_reference(sub_tree)
182
173
 
183
174
    def break_lock(self):
297
288
 
298
289
    def _generate_inventory(self):
299
290
        """Create and set self.inventory from the dirstate object.
300
 
        
 
291
 
301
292
        This is relatively expensive: we have to walk the entire dirstate.
302
293
        Ideally we would not, and can deprecate this function.
303
294
        """
373
364
        If either file_id or path is supplied, it is used as the key to lookup.
374
365
        If both are supplied, the fastest lookup is used, and an error is
375
366
        raised if they do not both point at the same row.
376
 
        
 
367
 
377
368
        :param file_id: An optional unicode file_id to be looked up.
378
369
        :param path: An optional unicode path to be looked up.
379
370
        :return: The dirstate row tuple for path/file_id, or (None, None)
435
426
    @needs_read_lock
436
427
    def get_parent_ids(self):
437
428
        """See Tree.get_parent_ids.
438
 
        
 
429
 
439
430
        This implementation requests the ids list from the dirstate file.
440
431
        """
441
432
        return self.current_dirstate().get_parent_ids()
895
886
        for tree in trees:
896
887
            if not (isinstance(tree, DirStateRevisionTree) and tree._revision_id in
897
888
                parents):
898
 
                return super(WorkingTree4, self).paths2ids(paths, trees, require_versioned)
 
889
                return super(DirStateWorkingTree, self).paths2ids(paths,
 
890
                    trees, require_versioned)
899
891
        search_indexes = [0] + [1 + parents.index(tree._revision_id) for tree in trees]
900
892
        # -- make all paths utf8 --
901
893
        paths_utf8 = set()
962
954
                raise errors.PathsNotVersionedError(paths)
963
955
        # -- remove redundancy in supplied paths to prevent over-scanning --
964
956
        search_paths = osutils.minimum_path_selection(paths)
965
 
        # sketch: 
 
957
        # sketch:
966
958
        # for all search_indexs in each path at or under each element of
967
959
        # search_paths, if the detail is relocated: add the id, and add the
968
960
        # relocated path as one to search if its not searched already. If the
1024
1016
 
1025
1017
    def read_working_inventory(self):
1026
1018
        """Read the working inventory.
1027
 
        
 
1019
 
1028
1020
        This is a meaningless operation for dirstate, but we obey it anyhow.
1029
1021
        """
1030
1022
        return self.inventory
1061
1053
    @needs_tree_write_lock
1062
1054
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
1063
1055
        """Set the parent ids to revision_ids.
1064
 
        
 
1056
 
1065
1057
        See also set_parent_trees. This api will try to retrieve the tree data
1066
1058
        for each element of revision_ids from the trees repository. If you have
1067
1059
        tree data already available, it is more efficient to use
1292
1284
        self.flush()
1293
1285
 
1294
1286
 
1295
 
class WorkingTreeFormat4(WorkingTreeFormat3):
1296
 
    """The first consolidated dirstate working tree format.
1297
 
 
1298
 
    This format:
1299
 
        - exists within a metadir controlling .bzr
1300
 
        - includes an explicit version marker for the workingtree control
1301
 
          files, separate from the BzrDir format
1302
 
        - modifies the hash cache format
1303
 
        - is new in bzr 0.15
1304
 
        - uses a LockDir to guard access to it.
1305
 
    """
1306
 
 
1307
 
    upgrade_recommended = False
1308
 
 
1309
 
    _tree_class = WorkingTree4
1310
 
 
1311
 
    def get_format_string(self):
1312
 
        """See WorkingTreeFormat.get_format_string()."""
1313
 
        return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
1314
 
 
1315
 
    def get_format_description(self):
1316
 
        """See WorkingTreeFormat.get_format_description()."""
1317
 
        return "Working tree format 4"
1318
 
 
 
1287
class WorkingTree4(DirStateWorkingTree):
 
1288
    """This is the Format 4 working tree.
 
1289
 
 
1290
    This differs from WorkingTree3 by:
 
1291
     - Having a consolidated internal dirstate, stored in a
 
1292
       randomly-accessible sorted file on disk.
 
1293
     - Not having a regular inventory attribute.  One can be synthesized
 
1294
       on demand but this is expensive and should be avoided.
 
1295
 
 
1296
    This is new in bzr 0.15.
 
1297
    """
 
1298
 
 
1299
 
 
1300
class WorkingTree5(DirStateWorkingTree):
 
1301
    """This is the Format 5 working tree.
 
1302
 
 
1303
    This differs from WorkingTree4 by:
 
1304
     - Supporting content filtering.
 
1305
     - Supporting a current view that may mask the set of files in a tree
 
1306
       impacted by most user operations.
 
1307
 
 
1308
    This is new in bzr 1.11.
 
1309
    """
 
1310
 
 
1311
    def _make_views(self):
 
1312
        return views.PathBasedViews(self)
 
1313
 
 
1314
 
 
1315
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1319
1316
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1320
1317
                   accelerator_tree=None, hardlink=False):
1321
1318
        """See WorkingTreeFormat.initialize().
1405
1402
 
1406
1403
    def _init_custom_control_files(self, wt):
1407
1404
        """Subclasses with custom control files should override this method.
1408
 
        
 
1405
 
1409
1406
        The working tree and control files are locked for writing when this
1410
1407
        method is called.
1411
 
        
 
1408
 
1412
1409
        :param wt: the WorkingTree object
1413
1410
        """
1414
1411
 
1432
1429
    _matchingbzrdir = property(__get_matchingbzrdir)
1433
1430
 
1434
1431
 
 
1432
class WorkingTreeFormat4(DirStateWorkingTreeFormat):
 
1433
    """The first consolidated dirstate working tree format.
 
1434
 
 
1435
    This format:
 
1436
        - exists within a metadir controlling .bzr
 
1437
        - includes an explicit version marker for the workingtree control
 
1438
          files, separate from the BzrDir format
 
1439
        - modifies the hash cache format
 
1440
        - is new in bzr 0.15
 
1441
        - uses a LockDir to guard access to it.
 
1442
    """
 
1443
 
 
1444
    upgrade_recommended = False
 
1445
 
 
1446
    _tree_class = WorkingTree4
 
1447
 
 
1448
    def get_format_string(self):
 
1449
        """See WorkingTreeFormat.get_format_string()."""
 
1450
        return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
 
1451
 
 
1452
    def get_format_description(self):
 
1453
        """See WorkingTreeFormat.get_format_description()."""
 
1454
        return "Working tree format 4"
 
1455
 
 
1456
 
 
1457
class WorkingTreeFormat5(DirStateWorkingTreeFormat):
 
1458
    """WorkingTree format supporting views.
 
1459
    """
 
1460
 
 
1461
    upgrade_recommended = False
 
1462
 
 
1463
    _tree_class = WorkingTree5
 
1464
 
 
1465
    def get_format_string(self):
 
1466
        """See WorkingTreeFormat.get_format_string()."""
 
1467
        return "Bazaar Working Tree Format 5 (bzr 1.11)\n"
 
1468
 
 
1469
    def get_format_description(self):
 
1470
        """See WorkingTreeFormat.get_format_description()."""
 
1471
        return "Working tree format 5"
 
1472
 
 
1473
    def _init_custom_control_files(self, wt):
 
1474
        """Subclasses with custom control files should override this method."""
 
1475
        wt._transport.put_bytes('views', '', mode=wt.bzrdir._get_file_mode())
 
1476
 
 
1477
    def supports_content_filtering(self):
 
1478
        return True
 
1479
 
 
1480
    def supports_views(self):
 
1481
        return True
 
1482
 
 
1483
 
1435
1484
class DirStateRevisionTree(Tree):
1436
1485
    """A revision tree pulling the inventory from a dirstate."""
1437
1486
 
1508
1557
        If either file_id or path is supplied, it is used as the key to lookup.
1509
1558
        If both are supplied, the fastest lookup is used, and an error is
1510
1559
        raised if they do not both point at the same row.
1511
 
        
 
1560
 
1512
1561
        :param file_id: An optional unicode file_id to be looked up.
1513
1562
        :param path: An optional unicode path to be looked up.
1514
1563
        :return: The dirstate row tuple for path/file_id, or (None, None)
1760
1809
 
1761
1810
    def walkdirs(self, prefix=""):
1762
1811
        # TODO: jam 20070215 This is the lazy way by using the RevisionTree
1763
 
        # implementation based on an inventory.  
 
1812
        # implementation based on an inventory.
1764
1813
        # This should be cleaned up to use the much faster Dirstate code
1765
1814
        # So for now, we just build up the parent inventory, and extract
1766
1815
        # it the same way RevisionTree does.
1795
1844
 
1796
1845
class InterDirStateTree(InterTree):
1797
1846
    """Fast path optimiser for changes_from with dirstate trees.
1798
 
    
1799
 
    This is used only when both trees are in the dirstate working file, and 
1800
 
    the source is any parent within the dirstate, and the destination is 
 
1847
 
 
1848
    This is used only when both trees are in the dirstate working file, and
 
1849
    the source is any parent within the dirstate, and the destination is
1801
1850
    the current working tree of the same dirstate.
1802
1851
    """
1803
1852
    # this could be generalized to allow comparisons between any trees in the
1947
1996
    @staticmethod
1948
1997
    def is_compatible(source, target):
1949
1998
        # the target must be a dirstate working tree
1950
 
        if not isinstance(target, WorkingTree4):
 
1999
        if not isinstance(target, DirStateWorkingTree):
1951
2000
            return False
1952
 
        # the source must be a revtreee or dirstate rev tree.
 
2001
        # the source must be a revtree or dirstate rev tree.
1953
2002
        if not isinstance(source,
1954
2003
            (revisiontree.RevisionTree, DirStateRevisionTree)):
1955
2004
            return False
1956
2005
        # the source revid must be in the target dirstate
1957
2006
        if not (source._revision_id == NULL_REVISION or
1958
2007
            source._revision_id in target.get_parent_ids()):
1959
 
            # TODO: what about ghosts? it may well need to 
 
2008
            # TODO: what about ghosts? it may well need to
1960
2009
            # check for them explicitly.
1961
2010
            return False
1962
2011
        return True
1972
2021
 
1973
2022
    def convert(self, tree):
1974
2023
        # lock the control files not the tree, so that we dont get tree
1975
 
        # on-unlock behaviours, and so that noone else diddles with the 
 
2024
        # on-unlock behaviours, and so that noone else diddles with the
1976
2025
        # tree during upgrade.
1977
2026
        tree._control_files.lock_write()
1978
2027
        try:
2007
2056
        tree._transport.put_bytes('format',
2008
2057
            self.target_format.get_format_string(),
2009
2058
            mode=tree.bzrdir._get_file_mode())
 
2059
 
 
2060
 
 
2061
class Converter4to5(object):
 
2062
    """Perform an in-place upgrade of format 4 to format 5 trees."""
 
2063
 
 
2064
    def __init__(self):
 
2065
        self.target_format = WorkingTreeFormat5()
 
2066
 
 
2067
    def convert(self, tree):
 
2068
        # lock the control files not the tree, so that we don't get tree
 
2069
        # on-unlock behaviours, and so that no-one else diddles with the
 
2070
        # tree during upgrade.
 
2071
        tree._control_files.lock_write()
 
2072
        try:
 
2073
            self.init_custom_control_files(tree)
 
2074
            self.update_format(tree)
 
2075
        finally:
 
2076
            tree._control_files.unlock()
 
2077
 
 
2078
    def init_custom_control_files(self, tree):
 
2079
        """Initialize custom control files."""
 
2080
        tree._transport.put_bytes('views', '',
 
2081
            mode=tree.bzrdir._get_file_mode())
 
2082
 
 
2083
    def update_format(self, tree):
 
2084
        """Change the format marker."""
 
2085
        tree._transport.put_bytes('format',
 
2086
            self.target_format.get_format_string(),
 
2087
            mode=tree.bzrdir._get_file_mode())