96
97
from bzrlib.workingtree import WorkingTree, WorkingTree3, WorkingTreeFormat3
99
class WorkingTree4(WorkingTree3):
100
"""This is the Format 4 working tree.
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.
108
This is new in bzr 0.15.
100
class DirStateWorkingTree(WorkingTree3):
111
101
def __init__(self, basedir,
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
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
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)
183
174
def break_lock(self):
298
289
def _generate_inventory(self):
299
290
"""Create and set self.inventory from the dirstate object.
301
292
This is relatively expensive: we have to walk the entire dirstate.
302
293
Ideally we would not, and can deprecate this function.
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.
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)
895
886
for tree in trees:
896
887
if not (isinstance(tree, DirStateRevisionTree) and tree._revision_id in
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)
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
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.
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
1295
class WorkingTreeFormat4(WorkingTreeFormat3):
1296
"""The first consolidated dirstate working tree 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.
1307
upgrade_recommended = False
1309
_tree_class = WorkingTree4
1311
def get_format_string(self):
1312
"""See WorkingTreeFormat.get_format_string()."""
1313
return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
1315
def get_format_description(self):
1316
"""See WorkingTreeFormat.get_format_description()."""
1317
return "Working tree format 4"
1287
class WorkingTree4(DirStateWorkingTree):
1288
"""This is the Format 4 working tree.
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.
1296
This is new in bzr 0.15.
1300
class WorkingTree5(DirStateWorkingTree):
1301
"""This is the Format 5 working tree.
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.
1308
This is new in bzr 1.11.
1311
def _make_views(self):
1312
return views.PathBasedViews(self)
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().
1406
1403
def _init_custom_control_files(self, wt):
1407
1404
"""Subclasses with custom control files should override this method.
1409
1406
The working tree and control files are locked for writing when this
1410
1407
method is called.
1412
1409
:param wt: the WorkingTree object
1432
1429
_matchingbzrdir = property(__get_matchingbzrdir)
1432
class WorkingTreeFormat4(DirStateWorkingTreeFormat):
1433
"""The first consolidated dirstate working tree 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.
1444
upgrade_recommended = False
1446
_tree_class = WorkingTree4
1448
def get_format_string(self):
1449
"""See WorkingTreeFormat.get_format_string()."""
1450
return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
1452
def get_format_description(self):
1453
"""See WorkingTreeFormat.get_format_description()."""
1454
return "Working tree format 4"
1457
class WorkingTreeFormat5(DirStateWorkingTreeFormat):
1458
"""WorkingTree format supporting views.
1461
upgrade_recommended = False
1463
_tree_class = WorkingTree5
1465
def get_format_string(self):
1466
"""See WorkingTreeFormat.get_format_string()."""
1467
return "Bazaar Working Tree Format 5 (bzr 1.11)\n"
1469
def get_format_description(self):
1470
"""See WorkingTreeFormat.get_format_description()."""
1471
return "Working tree format 5"
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())
1477
def supports_content_filtering(self):
1480
def supports_views(self):
1435
1484
class DirStateRevisionTree(Tree):
1436
1485
"""A revision tree pulling the inventory from a dirstate."""
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.
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)
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.
1796
1845
class InterDirStateTree(InterTree):
1797
1846
"""Fast path optimiser for changes_from with dirstate trees.
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
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.
1803
1852
# this could be generalized to allow comparisons between any trees in the
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):
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)):
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.
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()
2007
2056
tree._transport.put_bytes('format',
2008
2057
self.target_format.get_format_string(),
2009
2058
mode=tree.bzrdir._get_file_mode())
2061
class Converter4to5(object):
2062
"""Perform an in-place upgrade of format 4 to format 5 trees."""
2065
self.target_format = WorkingTreeFormat5()
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()
2073
self.init_custom_control_files(tree)
2074
self.update_format(tree)
2076
tree._control_files.unlock()
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())
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())