132
132
self._format = _format
133
133
self.bzrdir = _bzrdir
134
assert isinstance(basedir, basestring), \
135
"base directory %r is not a string" % basedir
136
134
basedir = safe_unicode(basedir)
137
135
mutter("opening working tree %r", basedir)
138
136
self._branch = branch
139
assert isinstance(self.branch, bzrlib.branch.Branch), \
140
"branch %r is not a Branch" % self.branch
141
137
self.basedir = realpath(basedir)
142
138
# if branch is at our basedir and is a format 6 or less
143
139
# assume all other formats have their own control files.
144
assert isinstance(_control_files, LockableFiles), \
145
"_control_files must be a LockableFiles, not %r" % _control_files
146
140
self._control_files = _control_files
147
141
self._dirty = None
317
311
state._read_dirblocks_if_needed()
318
312
root_key, current_entry = self._get_entry(path='')
319
313
current_id = root_key[2]
320
assert current_entry[0][0] == 'd' # directory
314
if not (current_entry[0][0] == 'd'): # directory
315
raise AssertionError(current_entry)
321
316
inv = Inventory(root_id=current_id)
322
317
# Turn some things into local variables
323
318
minikind_to_kind = dirstate.DirState._minikind_to_kind
356
351
# add this entry to the parent map.
357
352
parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
358
353
elif kind == 'tree-reference':
359
assert self._repo_supports_tree_reference, \
360
"repository of %r " \
361
"doesn't support tree references " \
362
"required by entry %r" \
354
if not self._repo_supports_tree_reference:
355
raise AssertionError(
357
"doesn't support tree references "
358
"required by entry %r"
364
360
inv_entry.reference_revision = link_or_sha1 or None
365
361
elif kind != 'symlink':
366
362
raise AssertionError("unknown kind %r" % kind)
367
363
# These checks cost us around 40ms on a 55k entry tree
368
assert file_id not in inv_byid, ('file_id %s already in'
369
' inventory as %s' % (file_id, inv_byid[file_id]))
370
assert name_unicode not in parent_ie.children
364
if file_id in inv_byid:
365
raise AssertionError('file_id %s already in'
366
' inventory as %s' % (file_id, inv_byid[file_id]))
367
if name_unicode in parent_ie.children:
368
raise AssertionError('name %r already in parent'
371
370
inv_byid[file_id] = inv_entry
372
371
parent_ie.children[name_unicode] = inv_entry
373
372
self._inventory = inv
552
551
Note: The caller is expected to take a read-lock before calling this.
554
553
relpath = self.id2path(file_id)
555
assert relpath != None, \
556
"path for id {%s} is None!" % file_id
555
raise AssertionError(
556
"path for id {%s} is None!" % file_id)
557
557
return self._kind(relpath)
559
559
def _kind(self, relpath):
632
632
if not from_paths:
635
634
state = self.current_dirstate()
637
assert not isinstance(from_paths, basestring)
635
if isinstance(from_paths, basestring):
638
637
to_dir_utf8 = to_dir.encode('utf8')
639
638
to_entry_dirname, to_basename = os.path.split(to_dir_utf8)
640
639
id_index = state._get_id_index()
795
794
if minikind == 'd':
796
795
def update_dirblock(from_dir, to_key, to_dir_utf8):
797
796
"""Recursively update all entries in this dirblock."""
798
assert from_dir != '', "renaming root not supported"
798
raise AssertionError("renaming root not supported")
799
799
from_key = (from_dir, '')
800
800
from_block_idx, present = \
801
801
state._find_block_index_from_key(from_key)
815
815
# Grab a copy since move_one may update the list.
816
816
for entry in from_block[1][:]:
817
assert entry[0][0] == from_dir
817
if not (entry[0][0] == from_dir):
818
raise AssertionError()
818
819
cur_details = entry[1][0]
819
820
to_key = (to_dir_utf8, entry[0][1], entry[0][2])
820
821
from_path_utf8 = osutils.pathjoin(entry[0][0], entry[0][1])
1033
1034
"""Change the last revision in the working tree."""
1034
1035
parents = self.get_parent_ids()
1035
1036
if new_revision in (NULL_REVISION, None):
1036
assert len(parents) < 2, (
1037
"setting the last parent to none with a pending merge is "
1037
if len(parents) >= 2:
1038
raise AssertionError(
1039
"setting the last parent to none with a pending merge is "
1039
1041
self.set_parent_ids([])
1041
1043
self.set_parent_ids([new_revision] + parents[1:],
1241
1243
def update_basis_by_delta(self, new_revid, delta):
1242
1244
"""See MutableTree.update_basis_by_delta."""
1243
assert self.last_revision() != new_revid
1245
if self.last_revision() == new_revid:
1246
raise AssertionError()
1244
1247
self.current_dirstate().update_basis_by_delta(delta, new_revid)
1246
1249
@needs_read_lock
1250
1253
@needs_tree_write_lock
1251
1254
def _write_inventory(self, inv):
1252
1255
"""Write inventory as the current inventory."""
1253
assert not self._dirty, ("attempting to write an inventory when the "
1254
"dirstate is dirty will cause data loss")
1257
raise AssertionError("attempting to write an inventory when the "
1258
"dirstate is dirty will lose pending changes")
1255
1259
self.current_dirstate().set_state_from_inventory(inv)
1256
1260
self._make_dirty(reset_inventory=False)
1257
1261
if self._inventory is not None:
1468
1472
This is relatively expensive: we have to walk the entire dirstate.
1470
assert self._locked, 'cannot generate inventory of an unlocked '\
1471
'dirstate revision tree'
1474
if not self._locked:
1475
raise AssertionError(
1476
'cannot generate inventory of an unlocked '
1477
'dirstate revision tree')
1472
1478
# separate call for profiling - makes it clear where the costs are.
1473
1479
self._dirstate._read_dirblocks_if_needed()
1474
assert self._revision_id in self._dirstate.get_parent_ids(), \
1475
'parent %s has disappeared from %s' % (
1476
self._revision_id, self._dirstate.get_parent_ids())
1480
if self._revision_id not in self._dirstate.get_parent_ids():
1481
raise AssertionError(
1482
'parent %s has disappeared from %s' % (
1483
self._revision_id, self._dirstate.get_parent_ids()))
1477
1484
parent_index = self._dirstate.get_parent_ids().index(self._revision_id) + 1
1478
1485
# This is identical now to the WorkingTree _generate_inventory except
1479
1486
# for the tree index use.
1480
1487
root_key, current_entry = self._dirstate._get_entry(parent_index, path_utf8='')
1481
1488
current_id = root_key[2]
1482
assert current_entry[parent_index][0] == 'd'
1489
if current_entry[parent_index][0] != 'd':
1490
raise AssertionError()
1483
1491
inv = Inventory(root_id=current_id, revision_id=self._revision_id)
1484
1492
inv.root.revision = current_entry[parent_index][4]
1485
1493
# Turn some things into local variables
1525
1533
raise AssertionError("cannot convert entry %r into an InventoryEntry"
1527
1535
# These checks cost us around 40ms on a 55k entry tree
1528
assert file_id not in inv_byid
1529
assert name_unicode not in parent_ie.children
1536
if file_id in inv_byid:
1537
raise AssertionError('file_id %s already in'
1538
' inventory as %s' % (file_id, inv_byid[file_id]))
1539
if name_unicode in parent_ie.children:
1540
raise AssertionError('name %r already in parent'
1530
1542
inv_byid[file_id] = inv_entry
1531
1543
parent_ie.children[name_unicode] = inv_entry
1532
1544
self._inventory = inv
1798
1810
parent_ids = self.target.get_parent_ids()
1799
assert (self.source._revision_id in parent_ids
1800
or self.source._revision_id == NULL_REVISION), \
1801
"revision {%s} is not stored in {%s}, but %s " \
1802
"can only be used for trees stored in the dirstate" \
1803
% (self.source._revision_id, self.target, self.iter_changes)
1811
if not (self.source._revision_id in parent_ids
1812
or self.source._revision_id == NULL_REVISION):
1813
raise AssertionError(
1814
"revision {%s} is not stored in {%s}, but %s "
1815
"can only be used for trees stored in the dirstate"
1816
% (self.source._revision_id, self.target, self.iter_changes))
1804
1817
target_index = 0
1805
1818
if self.source._revision_id == NULL_REVISION:
1806
1819
source_index = None
1807
1820
indices = (target_index,)
1809
assert (self.source._revision_id in parent_ids), \
1810
"Failure: source._revision_id: %s not in target.parent_ids(%s)" % (
1811
self.source._revision_id, parent_ids)
1822
if not (self.source._revision_id in parent_ids):
1823
raise AssertionError(
1824
"Failure: source._revision_id: %s not in target.parent_ids(%s)" % (
1825
self.source._revision_id, parent_ids))
1812
1826
source_index = 1 + parent_ids.index(self.source._revision_id)
1813
1827
indices = (source_index, target_index)
1814
1828
# -- make all specific_files utf8 --
1952
1966
target_details = entry[1][target_index]
1953
1967
target_minikind = target_details[0]
1954
1968
if path_info is not None and target_minikind in 'fdlt':
1955
assert target_index == 0
1969
if not (target_index == 0):
1970
raise AssertionError()
1956
1971
link_or_sha1 = state.update_entry(entry, abspath=path_info[4],
1957
1972
stat_value=path_info[3])
1958
1973
# The entry may have been modified by update_entry
2071
2086
# parent entry will be the same as the source entry.
2072
2087
target_parent_entry = state._get_entry(target_index,
2073
2088
path_utf8=new_dirname)
2074
assert target_parent_entry != (None, None), (
2075
"Could not find target parent in wt: %s\nparent of: %s"
2076
% (new_dirname, entry))
2089
if target_parent_entry == (None, None):
2090
raise AssertionError(
2091
"Could not find target parent in wt: %s\nparent of: %s"
2092
% (new_dirname, entry))
2077
2093
target_parent_id = target_parent_entry[0][2]
2078
2094
if target_parent_id == entry[0][2]:
2079
2095
# This is the root, so the parent is None
2262
2278
if current_dir_info[0][0] == '':
2263
2279
# remove .bzr from iteration
2264
2280
bzr_index = bisect_left(current_dir_info[1], ('.bzr',))
2265
assert current_dir_info[1][bzr_index][0] == '.bzr'
2281
if current_dir_info[1][bzr_index][0] != '.bzr':
2282
raise AssertionError()
2266
2283
del current_dir_info[1][bzr_index]
2267
2284
# walk until both the directory listing and the versioned metadata
2268
2285
# are exhausted.