1192
1289
# have to change the legacy inventory too.
1193
1290
if self._inventory is not None:
1194
1291
for file_id in file_ids:
1195
self._inventory.remove_recursive_id(file_id)
1292
if self._inventory.has_id(file_id):
1293
self._inventory.remove_recursive_id(file_id)
1295
@needs_tree_write_lock
1296
def rename_one(self, from_rel, to_rel, after=False):
1297
"""See WorkingTree.rename_one"""
1299
super(DirStateWorkingTree, self).rename_one(from_rel, to_rel, after)
1301
@needs_tree_write_lock
1302
def apply_inventory_delta(self, changes):
1303
"""See MutableTree.apply_inventory_delta"""
1304
state = self.current_dirstate()
1305
state.update_by_delta(changes)
1306
self._make_dirty(reset_inventory=True)
1308
def update_basis_by_delta(self, new_revid, delta):
1309
"""See MutableTree.update_basis_by_delta."""
1310
if self.last_revision() == new_revid:
1311
raise AssertionError()
1312
self.current_dirstate().update_basis_by_delta(delta, new_revid)
1315
def _validate(self):
1316
self._dirstate._validate()
1197
1318
@needs_tree_write_lock
1198
1319
def _write_inventory(self, inv):
1199
1320
"""Write inventory as the current inventory."""
1200
assert not self._dirty, "attempting to write an inventory when the dirstate is dirty will cause data loss"
1201
self.current_dirstate().set_state_from_inventory(inv)
1202
self._make_dirty(reset_inventory=False)
1203
if self._inventory is not None:
1322
raise AssertionError("attempting to write an inventory when the "
1323
"dirstate is dirty will lose pending changes")
1324
had_inventory = self._inventory is not None
1325
# Setting self._inventory = None forces the dirstate to regenerate the
1326
# working inventory. We do this because self.inventory may be inv, or
1327
# may have been modified, and either case would prevent a clean delta
1329
self._inventory = None
1331
delta = inv._make_delta(self.inventory)
1333
self.apply_inventory_delta(delta)
1204
1335
self._inventory = inv
1208
class WorkingTreeFormat4(WorkingTreeFormat3):
1209
"""The first consolidated dirstate working tree format.
1212
- exists within a metadir controlling .bzr
1213
- includes an explicit version marker for the workingtree control
1214
files, separate from the BzrDir format
1215
- modifies the hash cache format
1216
- is new in bzr 0.15
1217
- uses a LockDir to guard access to it.
1220
def get_format_string(self):
1221
"""See WorkingTreeFormat.get_format_string()."""
1222
return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
1224
def get_format_description(self):
1225
"""See WorkingTreeFormat.get_format_description()."""
1226
return "Working tree format 4"
1228
def initialize(self, a_bzrdir, revision_id=None):
1338
@needs_tree_write_lock
1339
def reset_state(self, revision_ids=None):
1340
"""Reset the state of the working tree.
1342
This does a hard-reset to a last-known-good state. This is a way to
1343
fix if something got corrupted (like the .bzr/checkout/dirstate file)
1345
if revision_ids is None:
1346
revision_ids = self.get_parent_ids()
1347
if not revision_ids:
1348
base_tree = self.branch.repository.revision_tree(
1349
_mod_revision.NULL_REVISION)
1352
trees = zip(revision_ids,
1353
self.branch.repository.revision_trees(revision_ids))
1354
base_tree = trees[0][1]
1355
state = self.current_dirstate()
1356
# We don't support ghosts yet
1357
state.set_state_from_scratch(base_tree.inventory, trees, [])
1360
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1362
def __init__(self, tree):
1365
def sha1(self, abspath):
1366
"""See dirstate.SHA1Provider.sha1()."""
1367
filters = self.tree._content_filter_stack(
1368
self.tree.relpath(osutils.safe_unicode(abspath)))
1369
return _mod_filters.internal_size_sha_file_byname(abspath, filters)[1]
1371
def stat_and_sha1(self, abspath):
1372
"""See dirstate.SHA1Provider.stat_and_sha1()."""
1373
filters = self.tree._content_filter_stack(
1374
self.tree.relpath(osutils.safe_unicode(abspath)))
1375
file_obj = file(abspath, 'rb', 65000)
1377
statvalue = os.fstat(file_obj.fileno())
1379
file_obj = _mod_filters.filtered_input_file(file_obj, filters)
1380
sha1 = osutils.size_sha_file(file_obj)[1]
1383
return statvalue, sha1
1386
class ContentFilteringDirStateWorkingTree(DirStateWorkingTree):
1387
"""Dirstate working tree that supports content filtering.
1389
The dirstate holds the hash and size of the canonical form of the file,
1390
and most methods must return that.
1393
def _file_content_summary(self, path, stat_result):
1394
# This is to support the somewhat obsolete path_content_summary method
1395
# with content filtering: see
1396
# <https://bugs.launchpad.net/bzr/+bug/415508>.
1398
# If the dirstate cache is up to date and knows the hash and size,
1400
# Otherwise if there are no content filters, return the on-disk size
1401
# and leave the hash blank.
1402
# Otherwise, read and filter the on-disk file and use its size and
1405
# The dirstate doesn't store the size of the canonical form so we
1406
# can't trust it for content-filtered trees. We just return None.
1407
dirstate_sha1 = self._dirstate.sha1_from_stat(path, stat_result)
1408
executable = self._is_executable_from_path_and_stat(path, stat_result)
1409
return ('file', None, executable, dirstate_sha1)
1412
class WorkingTree4(DirStateWorkingTree):
1413
"""This is the Format 4 working tree.
1415
This differs from WorkingTree by:
1416
- Having a consolidated internal dirstate, stored in a
1417
randomly-accessible sorted file on disk.
1418
- Not having a regular inventory attribute. One can be synthesized
1419
on demand but this is expensive and should be avoided.
1421
This is new in bzr 0.15.
1425
class WorkingTree5(ContentFilteringDirStateWorkingTree):
1426
"""This is the Format 5 working tree.
1428
This differs from WorkingTree4 by:
1429
- Supporting content filtering.
1431
This is new in bzr 1.11.
1435
class WorkingTree6(ContentFilteringDirStateWorkingTree):
1436
"""This is the Format 6 working tree.
1438
This differs from WorkingTree5 by:
1439
- Supporting a current view that may mask the set of files in a tree
1440
impacted by most user operations.
1442
This is new in bzr 1.14.
1445
def _make_views(self):
1446
return views.PathBasedViews(self)
1449
class DirStateWorkingTreeFormat(WorkingTreeFormat):
1451
missing_parent_conflicts = True
1453
supports_versioned_directories = True
1455
_lock_class = LockDir
1456
_lock_file_name = 'lock'
1458
def _open_control_files(self, a_bzrdir):
1459
transport = a_bzrdir.get_workingtree_transport(None)
1460
return LockableFiles(transport, self._lock_file_name,
1463
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1464
accelerator_tree=None, hardlink=False):
1229
1465
"""See WorkingTreeFormat.initialize().
1231
1467
:param revision_id: allows creating a working tree at a different
1232
revision than the branch is at.
1468
revision than the branch is at.
1469
:param accelerator_tree: A tree which can be used for retrieving file
1470
contents more quickly than the revision tree, i.e. a workingtree.
1471
The revision tree will be used for cases where accelerator_tree's
1472
content is different.
1473
:param hardlink: If true, hard-link files from accelerator_tree,
1234
These trees get an initial random root id.
1476
These trees get an initial random root id, if their repository supports
1477
rich root data, TREE_ROOT otherwise.
1236
revision_id = osutils.safe_revision_id(revision_id)
1237
1479
if not isinstance(a_bzrdir.transport, LocalTransport):
1238
1480
raise errors.NotLocalUrl(a_bzrdir.transport.base)
1239
1481
transport = a_bzrdir.get_workingtree_transport(self)
1240
1482
control_files = self._open_control_files(a_bzrdir)
1241
1483
control_files.create_lock()
1242
1484
control_files.lock_write()
1243
control_files.put_utf8('format', self.get_format_string())
1244
branch = a_bzrdir.open_branch()
1485
transport.put_bytes('format', self.get_format_string(),
1486
mode=a_bzrdir._get_file_mode())
1487
if from_branch is not None:
1488
branch = from_branch
1490
branch = a_bzrdir.open_branch()
1245
1491
if revision_id is None:
1246
1492
revision_id = branch.last_revision()
1247
1493
local_path = transport.local_abspath('dirstate')
1248
1494
# write out new dirstate (must exist when we create the tree)
1249
1495
state = dirstate.DirState.initialize(local_path)
1251
wt = WorkingTree4(a_bzrdir.root_transport.local_abspath('.'),
1498
wt = self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
1254
1501
_bzrdir=a_bzrdir,
1255
1502
_control_files=control_files)
1257
1504
wt.lock_tree_write()
1260
if revision_id in (None, NULL_REVISION):
1261
wt._set_root_id(generate_ids.gen_root_id())
1506
self._init_custom_control_files(wt)
1507
if revision_id in (None, _mod_revision.NULL_REVISION):
1508
if branch.repository.supports_rich_root():
1509
wt._set_root_id(generate_ids.gen_root_id())
1511
wt._set_root_id(ROOT_ID)
1263
wt.current_dirstate()._validate()
1264
wt.set_last_revision(revision_id)
1266
basis = wt.basis_tree()
1514
# frequently, we will get here due to branching. The accelerator
1515
# tree will be the tree from the branch, so the desired basis
1516
# tree will often be a parent of the accelerator tree.
1517
if accelerator_tree is not None:
1519
basis = accelerator_tree.revision_tree(revision_id)
1520
except errors.NoSuchRevision:
1523
basis = branch.repository.revision_tree(revision_id)
1524
if revision_id == _mod_revision.NULL_REVISION:
1527
parents_list = [(revision_id, basis)]
1267
1528
basis.lock_read()
1268
# if the basis has a root id we have to use that; otherwise we use
1270
basis_root_id = basis.get_root_id()
1271
if basis_root_id is not None:
1272
wt._set_root_id(basis_root_id)
1530
wt.set_parent_trees(parents_list, allow_leftmost_as_ghost=True)
1274
transform.build_tree(basis, wt)
1532
# if the basis has a root id we have to use that; otherwise we
1533
# use a new random one
1534
basis_root_id = basis.get_root_id()
1535
if basis_root_id is not None:
1536
wt._set_root_id(basis_root_id)
1538
if wt.supports_content_filtering():
1539
# The original tree may not have the same content filters
1540
# applied so we can't safely build the inventory delta from
1542
delta_from_tree = False
1544
delta_from_tree = True
1545
# delta_from_tree is safe even for DirStateRevisionTrees,
1546
# because wt4.apply_inventory_delta does not mutate the input
1547
# inventory entries.
1548
transform.build_tree(basis, wt, accelerator_tree,
1550
delta_from_tree=delta_from_tree)
1277
1554
control_files.unlock()
1558
def _init_custom_control_files(self, wt):
1559
"""Subclasses with custom control files should override this method.
1561
The working tree and control files are locked for writing when this
1564
:param wt: the WorkingTree object
1567
def open(self, a_bzrdir, _found=False):
1568
"""Return the WorkingTree object for a_bzrdir
1570
_found is a private parameter, do not use it. It is used to indicate
1571
if format probing has already been done.
1574
# we are being called directly and must probe.
1575
raise NotImplementedError
1576
if not isinstance(a_bzrdir.transport, LocalTransport):
1577
raise errors.NotLocalUrl(a_bzrdir.transport.base)
1578
wt = self._open(a_bzrdir, self._open_control_files(a_bzrdir))
1281
1581
def _open(self, a_bzrdir, control_files):
1282
1582
"""Open the tree itself.
1284
1584
:param a_bzrdir: the dir for the tree.
1285
1585
:param control_files: the control files for the tree.
1287
return WorkingTree4(a_bzrdir.root_transport.local_abspath('.'),
1587
return self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
1288
1588
branch=a_bzrdir.open_branch(),
1290
1590
_bzrdir=a_bzrdir,
1291
1591
_control_files=control_files)
1293
1593
def __get_matchingbzrdir(self):
1594
return self._get_matchingbzrdir()
1596
def _get_matchingbzrdir(self):
1597
"""Overrideable method to get a bzrdir for testing."""
1294
1598
# please test against something that will let us do tree references
1295
1599
return bzrdir.format_registry.make_bzrdir(
1296
1600
'dirstate-with-subtree')
1723
2188
if not found_versioned:
1724
2189
# none of the indexes was not 'absent' at all ids for this
1726
all_versioned = False
1728
if not all_versioned:
1729
raise errors.PathsNotVersionedError(specific_files)
2191
not_versioned.append(path)
2192
if len(not_versioned) > 0:
2193
raise errors.PathsNotVersionedError(not_versioned)
1730
2194
# -- remove redundancy in supplied specific_files to prevent over-scanning --
1731
search_specific_files = set()
1732
for path in specific_files:
1733
other_specific_files = specific_files.difference(set([path]))
1734
if not osutils.is_inside_any(other_specific_files, path):
1735
# this is a top level path, we must check it.
1736
search_specific_files.add(path)
1738
# compare source_index and target_index at or under each element of search_specific_files.
1739
# follow the following comparison table. Note that we only want to do diff operations when
1740
# the target is fdl because thats when the walkdirs logic will have exposed the pathinfo
1744
# Source | Target | disk | action
1745
# r | fdlt | | add source to search, add id path move and perform
1746
# | | | diff check on source-target
1747
# r | fdlt | a | dangling file that was present in the basis.
1749
# r | a | | add source to search
1751
# r | r | | this path is present in a non-examined tree, skip.
1752
# r | r | a | this path is present in a non-examined tree, skip.
1753
# a | fdlt | | add new id
1754
# a | fdlt | a | dangling locally added file, skip
1755
# a | a | | not present in either tree, skip
1756
# a | a | a | not present in any tree, skip
1757
# a | r | | not present in either tree at this path, skip as it
1758
# | | | may not be selected by the users list of paths.
1759
# a | r | a | not present in either tree at this path, skip as it
1760
# | | | may not be selected by the users list of paths.
1761
# fdlt | fdlt | | content in both: diff them
1762
# fdlt | fdlt | a | deleted locally, but not unversioned - show as deleted ?
1763
# fdlt | a | | unversioned: output deleted id for now
1764
# fdlt | a | a | unversioned and deleted: output deleted id
1765
# fdlt | r | | relocated in this tree, so add target to search.
1766
# | | | Dont diff, we will see an r,fd; pair when we reach
1767
# | | | this id at the other path.
1768
# fdlt | r | a | relocated in this tree, so add target to search.
1769
# | | | Dont diff, we will see an r,fd; pair when we reach
1770
# | | | this id at the other path.
1772
# for all search_indexs in each path at or under each element of
1773
# search_specific_files, if the detail is relocated: add the id, and add the
1774
# relocated path as one to search if its not searched already. If the
1775
# detail is not relocated, add the id.
1776
searched_specific_files = set()
1777
NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS
1778
# Using a list so that we can access the values and change them in
1779
# nested scope. Each one is [path, file_id, entry]
1780
last_source_parent = [None, None, None]
1781
last_target_parent = [None, None, None]
2195
search_specific_files = osutils.minimum_path_selection(specific_files)
1783
2197
use_filesystem_for_exec = (sys.platform != 'win32')
1785
def _process_entry(entry, path_info):
1786
"""Compare an entry and real disk to generate delta information.
1788
:param path_info: top_relpath, basename, kind, lstat, abspath for
1789
the path of entry. If None, then the path is considered absent.
1790
(Perhaps we should pass in a concrete entry for this ?)
1791
Basename is returned as a utf8 string because we expect this
1792
tuple will be ignored, and don't want to take the time to
1795
if source_index is None:
1796
source_details = NULL_PARENT_DETAILS
1798
source_details = entry[1][source_index]
1799
target_details = entry[1][target_index]
1800
target_minikind = target_details[0]
1801
if path_info is not None and target_minikind in 'fdlt':
1802
assert target_index == 0
1803
link_or_sha1 = state.update_entry(entry, abspath=path_info[4],
1804
stat_value=path_info[3])
1805
# The entry may have been modified by update_entry
1806
target_details = entry[1][target_index]
1807
target_minikind = target_details[0]
1810
source_minikind = source_details[0]
1811
if source_minikind in 'fdltr' and target_minikind in 'fdlt':
1812
# claimed content in both: diff
1813
# r | fdlt | | add source to search, add id path move and perform
1814
# | | | diff check on source-target
1815
# r | fdlt | a | dangling file that was present in the basis.
1817
if source_minikind in 'r':
1818
# add the source to the search path to find any children it
1819
# has. TODO ? : only add if it is a container ?
1820
if not osutils.is_inside_any(searched_specific_files,
1822
search_specific_files.add(source_details[1])
1823
# generate the old path; this is needed for stating later
1825
old_path = source_details[1]
1826
old_dirname, old_basename = os.path.split(old_path)
1827
path = pathjoin(entry[0][0], entry[0][1])
1828
old_entry = state._get_entry(source_index,
1830
# update the source details variable to be the real
1832
source_details = old_entry[1][source_index]
1833
source_minikind = source_details[0]
1835
old_dirname = entry[0][0]
1836
old_basename = entry[0][1]
1837
old_path = path = pathjoin(old_dirname, old_basename)
1838
if path_info is None:
1839
# the file is missing on disk, show as removed.
1840
content_change = True
1844
# source and target are both versioned and disk file is present.
1845
target_kind = path_info[2]
1846
if target_kind == 'directory':
1847
if source_minikind != 'd':
1848
content_change = True
1850
# directories have no fingerprint
1851
content_change = False
1853
elif target_kind == 'file':
1854
if source_minikind != 'f':
1855
content_change = True
1857
# We could check the size, but we already have the
1859
content_change = (link_or_sha1 != source_details[1])
1860
# Target details is updated at update_entry time
1861
if use_filesystem_for_exec:
1862
# We don't need S_ISREG here, because we are sure
1863
# we are dealing with a file.
1864
target_exec = bool(stat.S_IEXEC & path_info[3].st_mode)
1866
target_exec = target_details[3]
1867
elif target_kind == 'symlink':
1868
if source_minikind != 'l':
1869
content_change = True
1871
content_change = (link_or_sha1 != source_details[1])
1873
elif target_kind == 'tree-reference':
1874
if source_minikind != 't':
1875
content_change = True
1877
content_change = False
1880
raise Exception, "unknown kind %s" % path_info[2]
1881
# parent id is the entry for the path in the target tree
1882
if old_dirname == last_source_parent[0]:
1883
source_parent_id = last_source_parent[1]
1885
source_parent_entry = state._get_entry(source_index,
1886
path_utf8=old_dirname)
1887
source_parent_id = source_parent_entry[0][2]
1888
if source_parent_id == entry[0][2]:
1889
# This is the root, so the parent is None
1890
source_parent_id = None
1892
last_source_parent[0] = old_dirname
1893
last_source_parent[1] = source_parent_id
1894
last_source_parent[2] = source_parent_entry
1895
new_dirname = entry[0][0]
1896
if new_dirname == last_target_parent[0]:
1897
target_parent_id = last_target_parent[1]
1899
# TODO: We don't always need to do the lookup, because the
1900
# parent entry will be the same as the source entry.
1901
target_parent_entry = state._get_entry(target_index,
1902
path_utf8=new_dirname)
1903
target_parent_id = target_parent_entry[0][2]
1904
if target_parent_id == entry[0][2]:
1905
# This is the root, so the parent is None
1906
target_parent_id = None
1908
last_target_parent[0] = new_dirname
1909
last_target_parent[1] = target_parent_id
1910
last_target_parent[2] = target_parent_entry
1912
source_exec = source_details[3]
1913
return ((entry[0][2], (old_path, path), content_change,
1915
(source_parent_id, target_parent_id),
1916
(old_basename, entry[0][1]),
1917
(_minikind_to_kind[source_minikind], target_kind),
1918
(source_exec, target_exec)),)
1919
elif source_minikind in 'a' and target_minikind in 'fdlt':
1920
# looks like a new file
1921
if path_info is not None:
1922
path = pathjoin(entry[0][0], entry[0][1])
1923
# parent id is the entry for the path in the target tree
1924
# TODO: these are the same for an entire directory: cache em.
1925
parent_id = state._get_entry(target_index,
1926
path_utf8=entry[0][0])[0][2]
1927
if parent_id == entry[0][2]:
1929
if use_filesystem_for_exec:
1930
# We need S_ISREG here, because we aren't sure if this
1933
stat.S_ISREG(path_info[3].st_mode)
1934
and stat.S_IEXEC & path_info[3].st_mode)
1936
target_exec = target_details[3]
1937
return ((entry[0][2], (None, path), True,
1940
(None, entry[0][1]),
1941
(None, path_info[2]),
1942
(None, target_exec)),)
1944
# but its not on disk: we deliberately treat this as just
1945
# never-present. (Why ?! - RBC 20070224)
1947
elif source_minikind in 'fdlt' and target_minikind in 'a':
1948
# unversioned, possibly, or possibly not deleted: we dont care.
1949
# if its still on disk, *and* theres no other entry at this
1950
# path [we dont know this in this routine at the moment -
1951
# perhaps we should change this - then it would be an unknown.
1952
old_path = pathjoin(entry[0][0], entry[0][1])
1953
# parent id is the entry for the path in the target tree
1954
parent_id = state._get_entry(source_index, path_utf8=entry[0][0])[0][2]
1955
if parent_id == entry[0][2]:
1957
return ((entry[0][2], (old_path, None), True,
1960
(entry[0][1], None),
1961
(_minikind_to_kind[source_minikind], None),
1962
(source_details[3], None)),)
1963
elif source_minikind in 'fdlt' and target_minikind in 'r':
1964
# a rename; could be a true rename, or a rename inherited from
1965
# a renamed parent. TODO: handle this efficiently. Its not
1966
# common case to rename dirs though, so a correct but slow
1967
# implementation will do.
1968
if not osutils.is_inside_any(searched_specific_files, target_details[1]):
1969
search_specific_files.add(target_details[1])
1970
elif source_minikind in 'ra' and target_minikind in 'ra':
1971
# neither of the selected trees contain this file,
1972
# so skip over it. This is not currently directly tested, but
1973
# is indirectly via test_too_much.TestCommands.test_conflicts.
1976
raise AssertionError("don't know how to compare "
1977
"source_minikind=%r, target_minikind=%r"
1978
% (source_minikind, target_minikind))
1979
## import pdb;pdb.set_trace()
1982
while search_specific_files:
1983
# TODO: the pending list should be lexically sorted? the
1984
# interface doesn't require it.
1985
current_root = search_specific_files.pop()
1986
searched_specific_files.add(current_root)
1987
# process the entries for this containing directory: the rest will be
1988
# found by their parents recursively.
1989
root_entries = _entries_for_path(current_root)
1990
root_abspath = self.target.abspath(current_root)
1992
root_stat = os.lstat(root_abspath)
1994
if e.errno == errno.ENOENT:
1995
# the path does not exist: let _process_entry know that.
1996
root_dir_info = None
1998
# some other random error: hand it up.
2001
root_dir_info = ('', current_root,
2002
osutils.file_kind_from_stat_mode(root_stat.st_mode), root_stat,
2004
if root_dir_info[2] == 'directory':
2005
if self.target._directory_is_tree_reference(
2006
current_root.decode('utf8')):
2007
root_dir_info = root_dir_info[:2] + \
2008
('tree-reference',) + root_dir_info[3:]
2010
if not root_entries and not root_dir_info:
2011
# this specified path is not present at all, skip it.
2013
path_handled = False
2014
for entry in root_entries:
2015
for result in _process_entry(entry, root_dir_info):
2016
# this check should probably be outside the loop: one
2017
# 'iterate two trees' api, and then _iter_changes filters
2018
# unchanged pairs. - RBC 20070226
2020
if (include_unchanged
2021
or result[2] # content change
2022
or result[3][0] != result[3][1] # versioned status
2023
or result[4][0] != result[4][1] # parent id
2024
or result[5][0] != result[5][1] # name
2025
or result[6][0] != result[6][1] # kind
2026
or result[7][0] != result[7][1] # executable
2028
result = (result[0],
2029
((utf8_decode(result[1][0])[0]),
2030
utf8_decode(result[1][1])[0]),) + result[2:]
2032
if want_unversioned and not path_handled:
2033
new_executable = bool(
2034
stat.S_ISREG(root_dir_info[3].st_mode)
2035
and stat.S_IEXEC & root_dir_info[3].st_mode)
2036
yield (None, (None, current_root), True, (False, False),
2038
(None, splitpath(current_root)[-1]),
2039
(None, root_dir_info[2]), (None, new_executable))
2040
initial_key = (current_root, '', '')
2041
block_index, _ = state._find_block_index_from_key(initial_key)
2042
if block_index == 0:
2043
# we have processed the total root already, but because the
2044
# initial key matched it we should skip it here.
2046
if root_dir_info and root_dir_info[2] == 'tree-reference':
2047
current_dir_info = None
2049
dir_iterator = osutils._walkdirs_utf8(root_abspath, prefix=current_root)
2051
current_dir_info = dir_iterator.next()
2053
if e.errno in (errno.ENOENT, errno.ENOTDIR):
2054
# there may be directories in the inventory even though
2055
# this path is not a file on disk: so mark it as end of
2057
current_dir_info = None
2061
if current_dir_info[0][0] == '':
2062
# remove .bzr from iteration
2063
bzr_index = bisect_left(current_dir_info[1], ('.bzr',))
2064
assert current_dir_info[1][bzr_index][0] == '.bzr'
2065
del current_dir_info[1][bzr_index]
2066
# walk until both the directory listing and the versioned metadata
2068
if (block_index < len(state._dirblocks) and
2069
osutils.is_inside(current_root, state._dirblocks[block_index][0])):
2070
current_block = state._dirblocks[block_index]
2072
current_block = None
2073
while (current_dir_info is not None or
2074
current_block is not None):
2075
if (current_dir_info and current_block
2076
and current_dir_info[0][0] != current_block[0]):
2077
if current_dir_info[0][0] < current_block[0] :
2078
# filesystem data refers to paths not covered by the dirblock.
2079
# this has two possibilities:
2080
# A) it is versioned but empty, so there is no block for it
2081
# B) it is not versioned.
2082
# in either case it was processed by the containing directories walk:
2083
# if it is root/foo, when we walked root we emitted it,
2084
# or if we ere given root/foo to walk specifically, we
2085
# emitted it when checking the walk-root entries
2086
# advance the iterator and loop - we dont need to emit it.
2088
current_dir_info = dir_iterator.next()
2089
except StopIteration:
2090
current_dir_info = None
2092
# We have a dirblock entry for this location, but there
2093
# is no filesystem path for this. This is most likely
2094
# because a directory was removed from the disk.
2095
# We don't have to report the missing directory,
2096
# because that should have already been handled, but we
2097
# need to handle all of the files that are contained
2099
for current_entry in current_block[1]:
2100
# entry referring to file not present on disk.
2101
# advance the entry only, after processing.
2102
for result in _process_entry(current_entry, None):
2103
# this check should probably be outside the loop: one
2104
# 'iterate two trees' api, and then _iter_changes filters
2105
# unchanged pairs. - RBC 20070226
2106
if (include_unchanged
2107
or result[2] # content change
2108
or result[3][0] != result[3][1] # versioned status
2109
or result[4][0] != result[4][1] # parent id
2110
or result[5][0] != result[5][1] # name
2111
or result[6][0] != result[6][1] # kind
2112
or result[7][0] != result[7][1] # executable
2114
result = (result[0],
2115
((utf8_decode(result[1][0])[0]),
2116
utf8_decode(result[1][1])[0]),) + result[2:]
2119
if (block_index < len(state._dirblocks) and
2120
osutils.is_inside(current_root,
2121
state._dirblocks[block_index][0])):
2122
current_block = state._dirblocks[block_index]
2124
current_block = None
2127
if current_block and entry_index < len(current_block[1]):
2128
current_entry = current_block[1][entry_index]
2130
current_entry = None
2131
advance_entry = True
2133
if current_dir_info and path_index < len(current_dir_info[1]):
2134
current_path_info = current_dir_info[1][path_index]
2135
if current_path_info[2] == 'directory':
2136
if self.target._directory_is_tree_reference(
2137
current_path_info[0].decode('utf8')):
2138
current_path_info = current_path_info[:2] + \
2139
('tree-reference',) + current_path_info[3:]
2141
current_path_info = None
2143
path_handled = False
2144
while (current_entry is not None or
2145
current_path_info is not None):
2146
if current_entry is None:
2147
# the check for path_handled when the path is adnvaced
2148
# will yield this path if needed.
2150
elif current_path_info is None:
2151
# no path is fine: the per entry code will handle it.
2152
for result in _process_entry(current_entry, current_path_info):
2153
# this check should probably be outside the loop: one
2154
# 'iterate two trees' api, and then _iter_changes filters
2155
# unchanged pairs. - RBC 20070226
2156
if (include_unchanged
2157
or result[2] # content change
2158
or result[3][0] != result[3][1] # versioned status
2159
or result[4][0] != result[4][1] # parent id
2160
or result[5][0] != result[5][1] # name
2161
or result[6][0] != result[6][1] # kind
2162
or result[7][0] != result[7][1] # executable
2164
result = (result[0],
2165
((utf8_decode(result[1][0])[0]),
2166
utf8_decode(result[1][1])[0]),) + result[2:]
2168
elif current_entry[0][1] != current_path_info[1]:
2169
if current_path_info[1] < current_entry[0][1]:
2170
# extra file on disk: pass for now, but only
2171
# increment the path, not the entry
2172
advance_entry = False
2174
# entry referring to file not present on disk.
2175
# advance the entry only, after processing.
2176
for result in _process_entry(current_entry, None):
2177
# this check should probably be outside the loop: one
2178
# 'iterate two trees' api, and then _iter_changes filters
2179
# unchanged pairs. - RBC 20070226
2181
if (include_unchanged
2182
or result[2] # content change
2183
or result[3][0] != result[3][1] # versioned status
2184
or result[4][0] != result[4][1] # parent id
2185
or result[5][0] != result[5][1] # name
2186
or result[6][0] != result[6][1] # kind
2187
or result[7][0] != result[7][1] # executable
2189
result = (result[0],
2190
((utf8_decode(result[1][0])[0]),
2191
utf8_decode(result[1][1])[0]),) + result[2:]
2193
advance_path = False
2195
for result in _process_entry(current_entry, current_path_info):
2196
# this check should probably be outside the loop: one
2197
# 'iterate two trees' api, and then _iter_changes filters
2198
# unchanged pairs. - RBC 20070226
2200
if (include_unchanged
2201
or result[2] # content change
2202
or result[3][0] != result[3][1] # versioned status
2203
or result[4][0] != result[4][1] # parent id
2204
or result[5][0] != result[5][1] # name
2205
or result[6][0] != result[6][1] # kind
2206
or result[7][0] != result[7][1] # executable
2208
result = (result[0],
2209
((utf8_decode(result[1][0])[0]),
2210
utf8_decode(result[1][1])[0]),) + result[2:]
2212
if advance_entry and current_entry is not None:
2214
if entry_index < len(current_block[1]):
2215
current_entry = current_block[1][entry_index]
2217
current_entry = None
2219
advance_entry = True # reset the advance flaga
2220
if advance_path and current_path_info is not None:
2221
if not path_handled:
2222
# unversioned in all regards
2223
if want_unversioned:
2224
new_executable = bool(
2225
stat.S_ISREG(current_path_info[3].st_mode)
2226
and stat.S_IEXEC & current_path_info[3].st_mode)
2227
if want_unversioned:
2228
yield (None, (None, current_path_info[0]),
2232
(None, current_path_info[1]),
2233
(None, current_path_info[2]),
2234
(None, new_executable))
2235
# dont descend into this unversioned path if it is
2237
if current_path_info[2] in ('directory'):
2238
del current_dir_info[1][path_index]
2240
# dont descend the disk iterator into any tree
2242
if current_path_info[2] == 'tree-reference':
2243
del current_dir_info[1][path_index]
2246
if path_index < len(current_dir_info[1]):
2247
current_path_info = current_dir_info[1][path_index]
2248
if current_path_info[2] == 'directory':
2249
if self.target._directory_is_tree_reference(
2250
current_path_info[0].decode('utf8')):
2251
current_path_info = current_path_info[:2] + \
2252
('tree-reference',) + current_path_info[3:]
2254
current_path_info = None
2255
path_handled = False
2257
advance_path = True # reset the advance flagg.
2258
if current_block is not None:
2260
if (block_index < len(state._dirblocks) and
2261
osutils.is_inside(current_root, state._dirblocks[block_index][0])):
2262
current_block = state._dirblocks[block_index]
2264
current_block = None
2265
if current_dir_info is not None:
2267
current_dir_info = dir_iterator.next()
2268
except StopIteration:
2269
current_dir_info = None
2198
iter_changes = self.target._iter_changes(include_unchanged,
2199
use_filesystem_for_exec, search_specific_files, state,
2200
source_index, target_index, want_unversioned, self.target)
2201
return iter_changes.iter_changes()
2273
2204
def is_compatible(source, target):
2274
2205
# the target must be a dirstate working tree
2275
if not isinstance(target, WorkingTree4):
2206
if not isinstance(target, DirStateWorkingTree):
2277
# the source must be a revtreee or dirstate rev tree.
2208
# the source must be a revtree or dirstate rev tree.
2278
2209
if not isinstance(source,
2279
2210
(revisiontree.RevisionTree, DirStateRevisionTree)):
2281
2212
# the source revid must be in the target dirstate
2282
if not (source._revision_id == NULL_REVISION or
2213
if not (source._revision_id == _mod_revision.NULL_REVISION or
2283
2214
source._revision_id in target.get_parent_ids()):
2284
# TODO: what about ghosts? it may well need to
2215
# TODO: what about ghosts? it may well need to
2285
2216
# check for them explicitly.