1008
1300
block_index += 1
1009
1301
if ids_to_unversion:
1010
1302
raise errors.NoSuchId(self, iter(ids_to_unversion).next())
1303
self._make_dirty(reset_inventory=False)
1012
1304
# have to change the legacy inventory too.
1013
1305
if self._inventory is not None:
1014
1306
for file_id in file_ids:
1015
self._inventory.remove_recursive_id(file_id)
1307
if self._inventory.has_id(file_id):
1308
self._inventory.remove_recursive_id(file_id)
1310
@needs_tree_write_lock
1311
def rename_one(self, from_rel, to_rel, after=False):
1312
"""See WorkingTree.rename_one"""
1314
super(DirStateWorkingTree, self).rename_one(from_rel, to_rel, after)
1316
@needs_tree_write_lock
1317
def apply_inventory_delta(self, changes):
1318
"""See MutableTree.apply_inventory_delta"""
1319
state = self.current_dirstate()
1320
state.update_by_delta(changes)
1321
self._make_dirty(reset_inventory=True)
1323
def update_basis_by_delta(self, new_revid, delta):
1324
"""See MutableTree.update_basis_by_delta."""
1325
if self.last_revision() == new_revid:
1326
raise AssertionError()
1327
self.current_dirstate().update_basis_by_delta(delta, new_revid)
1330
def _validate(self):
1331
self._dirstate._validate()
1017
1333
@needs_tree_write_lock
1018
1334
def _write_inventory(self, inv):
1019
1335
"""Write inventory as the current inventory."""
1020
assert not self._dirty, "attempting to write an inventory when the dirstate is dirty will cause data loss"
1021
self.current_dirstate().set_state_from_inventory(inv)
1337
raise AssertionError("attempting to write an inventory when the "
1338
"dirstate is dirty will lose pending changes")
1339
had_inventory = self._inventory is not None
1340
# Setting self._inventory = None forces the dirstate to regenerate the
1341
# working inventory. We do this because self.inventory may be inv, or
1342
# may have been modified, and either case would prevent a clean delta
1344
self._inventory = None
1346
delta = inv._make_delta(self.root_inventory)
1348
self.apply_inventory_delta(delta)
1350
self._inventory = inv
1026
class WorkingTreeFormat4(WorkingTreeFormat3):
1027
"""The first consolidated dirstate working tree format.
1030
- exists within a metadir controlling .bzr
1031
- includes an explicit version marker for the workingtree control
1032
files, separate from the BzrDir format
1033
- modifies the hash cache format
1034
- is new in bzr TODO FIXME SETBEFOREMERGE
1035
- uses a LockDir to guard access to it.
1038
def get_format_string(self):
1039
"""See WorkingTreeFormat.get_format_string()."""
1040
return "Bazaar Working Tree format 4\n"
1042
def get_format_description(self):
1043
"""See WorkingTreeFormat.get_format_description()."""
1044
return "Working tree format 4"
1046
def initialize(self, a_bzrdir, revision_id=None):
1353
@needs_tree_write_lock
1354
def reset_state(self, revision_ids=None):
1355
"""Reset the state of the working tree.
1357
This does a hard-reset to a last-known-good state. This is a way to
1358
fix if something got corrupted (like the .bzr/checkout/dirstate file)
1360
if revision_ids is None:
1361
revision_ids = self.get_parent_ids()
1362
if not revision_ids:
1363
base_tree = self.branch.repository.revision_tree(
1364
_mod_revision.NULL_REVISION)
1367
trees = zip(revision_ids,
1368
self.branch.repository.revision_trees(revision_ids))
1369
base_tree = trees[0][1]
1370
state = self.current_dirstate()
1371
# We don't support ghosts yet
1372
state.set_state_from_scratch(base_tree.root_inventory, trees, [])
1375
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1377
def __init__(self, tree):
1380
def sha1(self, abspath):
1381
"""See dirstate.SHA1Provider.sha1()."""
1382
filters = self.tree._content_filter_stack(
1383
self.tree.relpath(osutils.safe_unicode(abspath)))
1384
return _mod_filters.internal_size_sha_file_byname(abspath, filters)[1]
1386
def stat_and_sha1(self, abspath):
1387
"""See dirstate.SHA1Provider.stat_and_sha1()."""
1388
filters = self.tree._content_filter_stack(
1389
self.tree.relpath(osutils.safe_unicode(abspath)))
1390
file_obj = file(abspath, 'rb', 65000)
1392
statvalue = os.fstat(file_obj.fileno())
1394
file_obj = _mod_filters.filtered_input_file(file_obj, filters)
1395
sha1 = osutils.size_sha_file(file_obj)[1]
1398
return statvalue, sha1
1401
class ContentFilteringDirStateWorkingTree(DirStateWorkingTree):
1402
"""Dirstate working tree that supports content filtering.
1404
The dirstate holds the hash and size of the canonical form of the file,
1405
and most methods must return that.
1408
def _file_content_summary(self, path, stat_result):
1409
# This is to support the somewhat obsolete path_content_summary method
1410
# with content filtering: see
1411
# <https://bugs.launchpad.net/bzr/+bug/415508>.
1413
# If the dirstate cache is up to date and knows the hash and size,
1415
# Otherwise if there are no content filters, return the on-disk size
1416
# and leave the hash blank.
1417
# Otherwise, read and filter the on-disk file and use its size and
1420
# The dirstate doesn't store the size of the canonical form so we
1421
# can't trust it for content-filtered trees. We just return None.
1422
dirstate_sha1 = self._dirstate.sha1_from_stat(path, stat_result)
1423
executable = self._is_executable_from_path_and_stat(path, stat_result)
1424
return ('file', None, executable, dirstate_sha1)
1427
class WorkingTree4(DirStateWorkingTree):
1428
"""This is the Format 4 working tree.
1430
This differs from WorkingTree by:
1431
- Having a consolidated internal dirstate, stored in a
1432
randomly-accessible sorted file on disk.
1433
- Not having a regular inventory attribute. One can be synthesized
1434
on demand but this is expensive and should be avoided.
1436
This is new in bzr 0.15.
1440
class WorkingTree5(ContentFilteringDirStateWorkingTree):
1441
"""This is the Format 5 working tree.
1443
This differs from WorkingTree4 by:
1444
- Supporting content filtering.
1446
This is new in bzr 1.11.
1450
class WorkingTree6(ContentFilteringDirStateWorkingTree):
1451
"""This is the Format 6 working tree.
1453
This differs from WorkingTree5 by:
1454
- Supporting a current view that may mask the set of files in a tree
1455
impacted by most user operations.
1457
This is new in bzr 1.14.
1460
def _make_views(self):
1461
return views.PathBasedViews(self)
1464
class DirStateWorkingTreeFormat(WorkingTreeFormatMetaDir):
1466
missing_parent_conflicts = True
1468
supports_versioned_directories = True
1470
_lock_class = LockDir
1471
_lock_file_name = 'lock'
1473
def _open_control_files(self, a_bzrdir):
1474
transport = a_bzrdir.get_workingtree_transport(None)
1475
return LockableFiles(transport, self._lock_file_name,
1478
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1479
accelerator_tree=None, hardlink=False):
1047
1480
"""See WorkingTreeFormat.initialize().
1049
revision_id allows creating a working tree at a different
1050
revision than the branch is at.
1482
:param revision_id: allows creating a working tree at a different
1483
revision than the branch is at.
1484
:param accelerator_tree: A tree which can be used for retrieving file
1485
contents more quickly than the revision tree, i.e. a workingtree.
1486
The revision tree will be used for cases where accelerator_tree's
1487
content is different.
1488
:param hardlink: If true, hard-link files from accelerator_tree,
1491
These trees get an initial random root id, if their repository supports
1492
rich root data, TREE_ROOT otherwise.
1052
revision_id = osutils.safe_revision_id(revision_id)
1053
1494
if not isinstance(a_bzrdir.transport, LocalTransport):
1054
1495
raise errors.NotLocalUrl(a_bzrdir.transport.base)
1055
1496
transport = a_bzrdir.get_workingtree_transport(self)
1056
1497
control_files = self._open_control_files(a_bzrdir)
1057
1498
control_files.create_lock()
1058
1499
control_files.lock_write()
1059
control_files.put_utf8('format', self.get_format_string())
1060
branch = a_bzrdir.open_branch()
1500
transport.put_bytes('format', self.as_string(),
1501
mode=a_bzrdir._get_file_mode())
1502
if from_branch is not None:
1503
branch = from_branch
1505
branch = a_bzrdir.open_branch()
1061
1506
if revision_id is None:
1062
1507
revision_id = branch.last_revision()
1063
1508
local_path = transport.local_abspath('dirstate')
1509
# write out new dirstate (must exist when we create the tree)
1064
1510
state = dirstate.DirState.initialize(local_path)
1066
wt = WorkingTree4(a_bzrdir.root_transport.local_abspath('.'),
1513
wt = self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
1069
1516
_bzrdir=a_bzrdir,
1090
1601
:param a_bzrdir: the dir for the tree.
1091
1602
:param control_files: the control files for the tree.
1093
return WorkingTree4(a_bzrdir.root_transport.local_abspath('.'),
1604
return self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
1094
1605
branch=a_bzrdir.open_branch(),
1096
1607
_bzrdir=a_bzrdir,
1097
1608
_control_files=control_files)
1100
class DirStateRevisionTree(Tree):
1101
"""A revision tree pulling the inventory from a dirstate."""
1610
def __get_matchingbzrdir(self):
1611
return self._get_matchingbzrdir()
1613
def _get_matchingbzrdir(self):
1614
"""Overrideable method to get a bzrdir for testing."""
1615
# please test against something that will let us do tree references
1616
return controldir.format_registry.make_bzrdir(
1617
'development-subtree')
1619
_matchingbzrdir = property(__get_matchingbzrdir)
1622
class WorkingTreeFormat4(DirStateWorkingTreeFormat):
1623
"""The first consolidated dirstate working tree format.
1626
- exists within a metadir controlling .bzr
1627
- includes an explicit version marker for the workingtree control
1628
files, separate from the ControlDir format
1629
- modifies the hash cache format
1630
- is new in bzr 0.15
1631
- uses a LockDir to guard access to it.
1634
upgrade_recommended = False
1636
_tree_class = WorkingTree4
1639
def get_format_string(cls):
1640
"""See WorkingTreeFormat.get_format_string()."""
1641
return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
1643
def get_format_description(self):
1644
"""See WorkingTreeFormat.get_format_description()."""
1645
return "Working tree format 4"
1648
class WorkingTreeFormat5(DirStateWorkingTreeFormat):
1649
"""WorkingTree format supporting content filtering.
1652
upgrade_recommended = False
1654
_tree_class = WorkingTree5
1657
def get_format_string(cls):
1658
"""See WorkingTreeFormat.get_format_string()."""
1659
return "Bazaar Working Tree Format 5 (bzr 1.11)\n"
1661
def get_format_description(self):
1662
"""See WorkingTreeFormat.get_format_description()."""
1663
return "Working tree format 5"
1665
def supports_content_filtering(self):
1669
class WorkingTreeFormat6(DirStateWorkingTreeFormat):
1670
"""WorkingTree format supporting views.
1673
upgrade_recommended = False
1675
_tree_class = WorkingTree6
1678
def get_format_string(cls):
1679
"""See WorkingTreeFormat.get_format_string()."""
1680
return "Bazaar Working Tree Format 6 (bzr 1.14)\n"
1682
def get_format_description(self):
1683
"""See WorkingTreeFormat.get_format_description()."""
1684
return "Working tree format 6"
1686
def _init_custom_control_files(self, wt):
1687
"""Subclasses with custom control files should override this method."""
1688
wt._transport.put_bytes('views', '', mode=wt.bzrdir._get_file_mode())
1690
def supports_content_filtering(self):
1693
def supports_views(self):
1696
def _get_matchingbzrdir(self):
1697
"""Overrideable method to get a bzrdir for testing."""
1698
# We use 'development-subtree' instead of '2a', because we have a
1699
# few tests that want to test tree references
1700
return bzrdir.format_registry.make_bzrdir('development-subtree')
1703
class DirStateRevisionTree(InventoryTree):
1704
"""A revision tree pulling the inventory from a dirstate.
1706
Note that this is one of the historical (ie revision) trees cached in the
1707
dirstate for easy access, not the workingtree.
1103
1710
def __init__(self, dirstate, revision_id, repository):
1104
1711
self._dirstate = dirstate
1105
self._revision_id = osutils.safe_revision_id(revision_id)
1712
self._revision_id = revision_id
1106
1713
self._repository = repository
1107
1714
self._inventory = None
1108
1715
self._locked = 0
1109
1716
self._dirstate_locked = False
1111
def annotate_iter(self, file_id):
1717
self._repo_supports_tree_reference = getattr(
1718
repository._format, "supports_tree_reference",
1722
return "<%s of %s in %s>" % \
1723
(self.__class__.__name__, self._revision_id, self._dirstate)
1725
def annotate_iter(self, file_id,
1726
default_revision=_mod_revision.CURRENT_REVISION):
1112
1727
"""See Tree.annotate_iter"""
1113
w = self._repository.weave_store.get_weave(file_id,
1114
self._repository.get_transaction())
1115
return w.annotate_iter(self.inventory[file_id].revision)
1728
text_key = (file_id, self.get_file_revision(file_id))
1729
annotations = self._repository.texts.annotate(text_key)
1730
return [(key[-1], line) for (key, line) in annotations]
1117
1732
def _comparison_data(self, entry, path):
1118
1733
"""See Tree._comparison_data."""
1230
1876
# Make sure the file exists
1231
1877
entry = self._get_entry(file_id, path=path)
1232
1878
if entry == (None, None): # do we raise?
1879
raise errors.NoSuchId(self, file_id)
1234
1880
parent_index = self._get_parent_index()
1235
1881
last_changed_revision = entry[1][parent_index][4]
1236
return self._repository.get_revision(last_changed_revision).timestamp
1883
rev = self._repository.get_revision(last_changed_revision)
1884
except errors.NoSuchRevision:
1885
raise errors.FileTimestampUnavailable(self.id2path(file_id))
1886
return rev.timestamp
1238
1888
def get_file_sha1(self, file_id, path=None, stat_value=None):
1239
# TODO: if path is present, fast-path on that, as inventory
1240
# might not be present
1241
ie = self.inventory[file_id]
1242
if ie.kind == "file":
1889
entry = self._get_entry(file_id=file_id, path=path)
1890
parent_index = self._get_parent_index()
1891
parent_details = entry[1][parent_index]
1892
if parent_details[0] == 'f':
1893
return parent_details[1]
1246
def get_file(self, file_id):
1897
def get_file_revision(self, file_id):
1898
inv, inv_file_id = self._unpack_file_id(file_id)
1899
return inv[inv_file_id].revision
1901
def get_file(self, file_id, path=None):
1247
1902
return StringIO(self.get_file_text(file_id))
1249
def get_file_lines(self, file_id):
1250
ie = self.inventory[file_id]
1251
return self._repository.weave_store.get_weave(file_id,
1252
self._repository.get_transaction()).get_lines(ie.revision)
1254
1904
def get_file_size(self, file_id):
1255
return self.inventory[file_id].text_size
1257
def get_file_text(self, file_id):
1258
return ''.join(self.get_file_lines(file_id))
1260
def get_symlink_target(self, file_id):
1905
"""See Tree.get_file_size"""
1906
inv, inv_file_id = self._unpack_file_id(file_id)
1907
return inv[inv_file_id].text_size
1909
def get_file_text(self, file_id, path=None):
1911
for _, content_iter in self.iter_files_bytes([(file_id, None)]):
1912
if content is not None:
1913
raise AssertionError('iter_files_bytes returned'
1914
' too many entries')
1915
# For each entry returned by iter_files_bytes, we must consume the
1916
# content_iter before we step the files iterator.
1917
content = ''.join(content_iter)
1919
raise AssertionError('iter_files_bytes did not return'
1920
' the requested data')
1923
def get_reference_revision(self, file_id, path=None):
1924
inv, inv_file_id = self._unpack_file_id(file_id)
1925
return inv[inv_file_id].reference_revision
1927
def iter_files_bytes(self, desired_files):
1928
"""See Tree.iter_files_bytes.
1930
This version is implemented on top of Repository.iter_files_bytes"""
1931
parent_index = self._get_parent_index()
1932
repo_desired_files = []
1933
for file_id, identifier in desired_files:
1934
entry = self._get_entry(file_id)
1935
if entry == (None, None):
1936
raise errors.NoSuchId(self, file_id)
1937
repo_desired_files.append((file_id, entry[1][parent_index][4],
1939
return self._repository.iter_files_bytes(repo_desired_files)
1941
def get_symlink_target(self, file_id, path=None):
1261
1942
entry = self._get_entry(file_id=file_id)
1262
1943
parent_index = self._get_parent_index()
1263
1944
if entry[1][parent_index][0] != 'l':
1266
# At present, none of the tree implementations supports non-ascii
1267
# symlink targets. So we will just assume that the dirstate path is
1269
return entry[1][parent_index][1]
1947
target = entry[1][parent_index][1]
1948
target = target.decode('utf8')
1271
1951
def get_revision_id(self):
1272
1952
"""Return the revision id for this tree."""
1273
1953
return self._revision_id
1275
def _get_inventory(self):
1955
def _get_root_inventory(self):
1276
1956
if self._inventory is not None:
1277
1957
return self._inventory
1958
self._must_be_locked()
1278
1959
self._generate_inventory()
1279
1960
return self._inventory
1962
root_inventory = property(_get_root_inventory,
1963
doc="Inventory of this Tree")
1965
@deprecated_method(deprecated_in((2, 5, 0)))
1966
def _get_inventory(self):
1967
return self.root_inventory
1281
1969
inventory = property(_get_inventory,
1282
1970
doc="Inventory of this Tree")
1486
2241
if not found_versioned:
1487
2242
# none of the indexes was not 'absent' at all ids for this
1489
all_versioned = False
1491
if not all_versioned:
1492
raise errors.PathsNotVersionedError(paths)
2244
not_versioned.append(path.decode('utf-8'))
2245
if len(not_versioned) > 0:
2246
raise errors.PathsNotVersionedError(not_versioned)
1493
2247
# -- remove redundancy in supplied specific_files to prevent over-scanning --
1494
search_specific_files = set()
1495
for path in specific_files:
1496
other_specific_files = specific_files.difference(set([path]))
1497
if not osutils.is_inside_any(other_specific_files, path):
1498
# this is a top level path, we must check it.
1499
search_specific_files.add(path)
1501
# compare source_index and target_index at or under each element of search_specific_files.
1502
# follow the following comparison table. Note that we only want to do diff operations when
1503
# the target is fdl because thats when the walkdirs logic will have exposed the pathinfo
1507
# Source | Target | disk | action
1508
# r | fdl | | add source to search, add id path move and perform
1509
# | | | diff check on source-target
1510
# r | fdl | a | dangling file that was present in the basis.
1512
# r | a | | add source to search
1514
# r | r | | this path is present in a non-examined tree, skip.
1515
# r | r | a | this path is present in a non-examined tree, skip.
1516
# a | fdl | | add new id
1517
# a | fdl | a | dangling locally added file, skip
1518
# a | a | | not present in either tree, skip
1519
# a | a | a | not present in any tree, skip
1520
# a | r | | not present in either tree at this path, skip as it
1521
# | | | may not be selected by the users list of paths.
1522
# a | r | a | not present in either tree at this path, skip as it
1523
# | | | may not be selected by the users list of paths.
1524
# fdl | fdl | | content in both: diff them
1525
# fdl | fdl | a | deleted locally, but not unversioned - show as deleted ?
1526
# fdl | a | | unversioned: output deleted id for now
1527
# fdl | a | a | unversioned and deleted: output deleted id
1528
# fdl | r | | relocated in this tree, so add target to search.
1529
# | | | Dont diff, we will see an r,fd; pair when we reach
1530
# | | | this id at the other path.
1531
# fdl | r | a | relocated in this tree, so add target to search.
1532
# | | | Dont diff, we will see an r,fd; pair when we reach
1533
# | | | this id at the other path.
1535
# for all search_indexs in each path at or under each element of
1536
# search_specific_files, if the detail is relocated: add the id, and add the
1537
# relocated path as one to search if its not searched already. If the
1538
# detail is not relocated, add the id.
1539
searched_specific_files = set()
1540
NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS
1541
# Using a list so that we can access the values and change them in
1542
# nested scope. Each one is [path, file_id, entry]
1543
last_source_parent = [None, None, None]
1544
last_target_parent = [None, None, None]
1546
def _process_entry(entry, path_info):
1547
"""Compare an entry and real disk to generate delta information.
1549
:param path_info: top_relpath, basename, kind, lstat, abspath for
1550
the path of entry. If None, then the path is considered absent.
1551
(Perhaps we should pass in a concrete entry for this ?)
1553
# TODO: when a parent has been renamed, dont emit path renames for children,
1554
if source_index is None:
1555
source_details = NULL_PARENT_DETAILS
1557
source_details = entry[1][source_index]
1558
target_details = entry[1][target_index]
1559
source_minikind = source_details[0]
1560
target_minikind = target_details[0]
1561
if source_minikind in 'fdlr' and target_minikind in 'fdl':
1562
# claimed content in both: diff
1563
# r | fdl | | add source to search, add id path move and perform
1564
# | | | diff check on source-target
1565
# r | fdl | a | dangling file that was present in the basis.
1567
if source_minikind in 'r':
1568
# add the source to the search path to find any children it
1569
# has. TODO ? : only add if it is a container ?
1570
if not osutils.is_inside_any(searched_specific_files,
1572
search_specific_files.add(source_details[1])
1573
# generate the old path; this is needed for stating later
1575
old_path = source_details[1]
1576
old_dirname, old_basename = os.path.split(old_path)
1577
path = pathjoin(entry[0][0], entry[0][1])
1578
old_entry = state._get_entry(source_index,
1580
# update the source details variable to be the real
1582
source_details = old_entry[1][source_index]
1583
source_minikind = source_details[0]
1585
old_dirname = entry[0][0]
1586
old_basename = entry[0][1]
1587
old_path = path = pathjoin(old_dirname, old_basename)
1588
if path_info is None:
1589
# the file is missing on disk, show as removed.
1590
old_path = pathjoin(entry[0][0], entry[0][1])
1591
content_change = True
1595
# source and target are both versioned and disk file is present.
1596
target_kind = path_info[2]
1597
if target_kind == 'directory':
1598
if source_minikind != 'd':
1599
content_change = True
1601
# directories have no fingerprint
1602
content_change = False
1604
elif target_kind == 'file':
1605
if source_minikind != 'f':
1606
content_change = True
1608
# has it changed? fast path: size, slow path: sha1.
1609
if source_details[2] != path_info[3].st_size:
1610
content_change = True
1612
# maybe the same. Get the hash
1613
new_hash = self.target._hashcache.get_sha1(
1615
content_change = (new_hash != source_details[1])
1617
stat.S_ISREG(path_info[3].st_mode)
1618
and stat.S_IEXEC & path_info[3].st_mode)
1619
elif target_kind == 'symlink':
1620
if source_minikind != 'l':
1621
content_change = True
1623
# TODO: check symlink supported for windows users
1624
# and grab from target state here.
1625
link_target = os.readlink(path_info[4])
1626
content_change = (link_target != source_details[1])
1629
raise Exception, "unknown kind %s" % path_info[2]
1630
# parent id is the entry for the path in the target tree
1631
if old_dirname == last_source_parent[0]:
1632
source_parent_id = last_source_parent[1]
1634
source_parent_entry = state._get_entry(source_index,
1635
path_utf8=old_dirname)
1636
source_parent_id = source_parent_entry[0][2]
1637
if source_parent_id == entry[0][2]:
1638
# This is the root, so the parent is None
1639
source_parent_id = None
1641
last_source_parent[0] = old_dirname
1642
last_source_parent[1] = source_parent_id
1643
last_source_parent[2] = source_parent_entry
1645
new_dirname = entry[0][0]
1646
if new_dirname == last_target_parent[0]:
1647
target_parent_id = last_target_parent[1]
1649
# TODO: We don't always need to do the lookup, because the
1650
# parent entry will be the same as the source entry.
1651
target_parent_entry = state._get_entry(target_index,
1652
path_utf8=new_dirname)
1653
target_parent_id = target_parent_entry[0][2]
1654
if target_parent_id == entry[0][2]:
1655
# This is the root, so the parent is None
1656
target_parent_id = None
1658
last_target_parent[0] = new_dirname
1659
last_target_parent[1] = target_parent_id
1660
last_target_parent[2] = target_parent_entry
1662
source_exec = source_details[3]
1663
path_unicode = utf8_decode(path)[0]
1664
return ((entry[0][2], path_unicode, content_change,
1666
(source_parent_id, target_parent_id),
1667
(old_basename, entry[0][1]),
1668
(_minikind_to_kind[source_minikind], target_kind),
1669
(source_exec, target_exec)),)
1670
elif source_minikind in 'a' and target_minikind in 'fdl':
1671
# looks like a new file
1672
if path_info is not None:
1673
path = pathjoin(entry[0][0], entry[0][1])
1674
# parent id is the entry for the path in the target tree
1675
# TODO: these are the same for an entire directory: cache em.
1676
parent_id = state._get_entry(target_index, path_utf8=entry[0][0])[0][2]
1677
if parent_id == entry[0][2]:
1680
new_executable = bool(
1681
stat.S_ISREG(path_info[3].st_mode)
1682
and stat.S_IEXEC & path_info[3].st_mode)
1683
path_unicode = utf8_decode(path)[0]
1684
return ((entry[0][2], path_unicode, True,
1687
(None, entry[0][1]),
1688
(None, path_info[2]),
1689
(None, new_executable)),)
1691
# but its not on disk: we deliberately treat this as just
1692
# never-present. (Why ?! - RBC 20070224)
1694
elif source_minikind in 'fdl' and target_minikind in 'a':
1695
# unversioned, possibly, or possibly not deleted: we dont care.
1696
# if its still on disk, *and* theres no other entry at this
1697
# path [we dont know this in this routine at the moment -
1698
# perhaps we should change this - then it would be an unknown.
1699
old_path = pathjoin(entry[0][0], entry[0][1])
1700
# parent id is the entry for the path in the target tree
1701
parent_id = state._get_entry(source_index, path_utf8=entry[0][0])[0][2]
1702
if parent_id == entry[0][2]:
1704
old_path_unicode = utf8_decode(old_path)[0]
1705
return ((entry[0][2], old_path_unicode, True,
1708
(entry[0][1], None),
1709
(_minikind_to_kind[source_minikind], None),
1710
(source_details[3], None)),)
1711
elif source_minikind in 'fdl' and target_minikind in 'r':
1712
# a rename; could be a true rename, or a rename inherited from
1713
# a renamed parent. TODO: handle this efficiently. Its not
1714
# common case to rename dirs though, so a correct but slow
1715
# implementation will do.
1716
if not osutils.is_inside_any(searched_specific_files, target_details[1]):
1717
search_specific_files.add(target_details[1])
1718
elif source_minikind in 'r' and target_minikind in 'r':
1719
# neither of the selected trees contain this file,
1720
# so skip over it. This is not currently directly tested, but
1721
# is indirectly via test_too_much.TestCommands.test_conflicts.
1724
print "*******", source_minikind, target_minikind
1725
import pdb;pdb.set_trace()
1727
while search_specific_files:
1728
# TODO: the pending list should be lexically sorted?
1729
current_root = search_specific_files.pop()
1730
searched_specific_files.add(current_root)
1731
# process the entries for this containing directory: the rest will be
1732
# found by their parents recursively.
1733
root_entries = _entries_for_path(current_root)
1734
root_abspath = self.target.abspath(current_root)
1736
root_stat = os.lstat(root_abspath)
1738
if e.errno == errno.ENOENT:
1739
# the path does not exist: let _process_entry know that.
1740
root_dir_info = None
1742
# some other random error: hand it up.
1745
root_dir_info = ('', current_root,
1746
osutils.file_kind_from_stat_mode(root_stat.st_mode), root_stat,
1748
if not root_entries and not root_dir_info:
1749
# this specified path is not present at all, skip it.
1751
for entry in root_entries:
1752
for result in _process_entry(entry, root_dir_info):
1753
# this check should probably be outside the loop: one
1754
# 'iterate two trees' api, and then _iter_changes filters
1755
# unchanged pairs. - RBC 20070226
1756
if (include_unchanged
1757
or result[2] # content change
1758
or result[3][0] != result[3][1] # versioned status
1759
or result[4][0] != result[4][1] # parent id
1760
or result[5][0] != result[5][1] # name
1761
or result[6][0] != result[6][1] # kind
1762
or result[7][0] != result[7][1] # executable
1765
dir_iterator = osutils._walkdirs_utf8(root_abspath, prefix=current_root)
1766
initial_key = (current_root, '', '')
1767
block_index, _ = state._find_block_index_from_key(initial_key)
1768
if block_index == 0:
1769
# we have processed the total root already, but because the
1770
# initial key matched it we should skip it here.
1773
current_dir_info = dir_iterator.next()
1775
if e.errno in (errno.ENOENT, errno.ENOTDIR):
1776
# there may be directories in the inventory even though
1777
# this path is not a file on disk: so mark it as end of
1779
current_dir_info = None
1783
if current_dir_info[0][0] == '':
1784
# remove .bzr from iteration
1785
bzr_index = bisect_left(current_dir_info[1], ('.bzr',))
1786
assert current_dir_info[1][bzr_index][0] == '.bzr'
1787
del current_dir_info[1][bzr_index]
1788
# walk until both the directory listing and the versioned metadata
1789
# are exhausted. TODO: reevaluate this, perhaps we should stop when
1790
# the versioned data runs out.
1791
if (block_index < len(state._dirblocks) and
1792
osutils.is_inside(current_root, state._dirblocks[block_index][0])):
1793
current_block = state._dirblocks[block_index]
1795
current_block = None
1796
while (current_dir_info is not None or
1797
current_block is not None):
1798
if (current_dir_info and current_block
1799
and current_dir_info[0][0] != current_block[0]):
1800
if current_dir_info[0][0] < current_block[0] :
1801
# import pdb; pdb.set_trace()
1802
# print 'unversioned dir'
1803
# filesystem data refers to paths not covered by the dirblock.
1804
# this has two possibilities:
1805
# A) it is versioned but empty, so there is no block for it
1806
# B) it is not versioned.
1807
# in either case it was processed by the containing directories walk:
1808
# if it is root/foo, when we walked root we emitted it,
1809
# or if we ere given root/foo to walk specifically, we
1810
# emitted it when checking the walk-root entries
1811
# advance the iterator and loop - we dont need to emit it.
1813
current_dir_info = dir_iterator.next()
1814
except StopIteration:
1815
current_dir_info = None
1817
# We have a dirblock entry for this location, but there
1818
# is no filesystem path for this. This is most likely
1819
# because a directory was removed from the disk.
1820
# We don't have to report the missing directory,
1821
# because that should have already been handled, but we
1822
# need to handle all of the files that are contained
1824
for current_entry in current_block[1]:
1825
# entry referring to file not present on disk.
1826
# advance the entry only, after processing.
1827
for result in _process_entry(current_entry, None):
1828
# this check should probably be outside the loop: one
1829
# 'iterate two trees' api, and then _iter_changes filters
1830
# unchanged pairs. - RBC 20070226
1831
if (include_unchanged
1832
or result[2] # content change
1833
or result[3][0] != result[3][1] # versioned status
1834
or result[4][0] != result[4][1] # parent id
1835
or result[5][0] != result[5][1] # name
1836
or result[6][0] != result[6][1] # kind
1837
or result[7][0] != result[7][1] # executable
1841
if (block_index < len(state._dirblocks) and
1842
osutils.is_inside(current_root,
1843
state._dirblocks[block_index][0])):
1844
current_block = state._dirblocks[block_index]
1846
current_block = None
1849
if current_block and entry_index < len(current_block[1]):
1850
current_entry = current_block[1][entry_index]
1852
current_entry = None
1853
advance_entry = True
1855
if current_dir_info and path_index < len(current_dir_info[1]):
1856
current_path_info = current_dir_info[1][path_index]
1858
current_path_info = None
1860
while (current_entry is not None or
1861
current_path_info is not None):
1862
if current_entry is None:
1863
# no more entries: yield current_pathinfo as an
1864
# unversioned file: its not the same as a path in any
1865
# tree in the dirstate.
1866
new_executable = bool(
1867
stat.S_ISREG(current_path_info[3].st_mode)
1868
and stat.S_IEXEC & current_path_info[3].st_mode)
1869
yield (None, current_path_info[0], True,
1872
(None, current_path_info[1]),
1873
(None, current_path_info[2]),
1874
(None, new_executable))
1875
elif current_path_info is None:
1876
# no path is fine: the per entry code will handle it.
1877
for result in _process_entry(current_entry, current_path_info):
1878
# this check should probably be outside the loop: one
1879
# 'iterate two trees' api, and then _iter_changes filters
1880
# unchanged pairs. - RBC 20070226
1881
if (include_unchanged
1882
or result[2] # content change
1883
or result[3][0] != result[3][1] # versioned status
1884
or result[4][0] != result[4][1] # parent id
1885
or result[5][0] != result[5][1] # name
1886
or result[6][0] != result[6][1] # kind
1887
or result[7][0] != result[7][1] # executable
1890
elif current_entry[0][1] != current_path_info[1]:
1891
if current_path_info[1] < current_entry[0][1]:
1892
# extra file on disk: pass for now, but only
1893
# increment the path, not the entry
1894
# import pdb; pdb.set_trace()
1895
# print 'unversioned file'
1896
advance_entry = False
1898
# entry referring to file not present on disk.
1899
# advance the entry only, after processing.
1900
for result in _process_entry(current_entry, None):
1901
# this check should probably be outside the loop: one
1902
# 'iterate two trees' api, and then _iter_changes filters
1903
# unchanged pairs. - RBC 20070226
1904
if (include_unchanged
1905
or result[2] # content change
1906
or result[3][0] != result[3][1] # versioned status
1907
or result[4][0] != result[4][1] # parent id
1908
or result[5][0] != result[5][1] # name
1909
or result[6][0] != result[6][1] # kind
1910
or result[7][0] != result[7][1] # executable
1913
advance_path = False
1915
for result in _process_entry(current_entry, current_path_info):
1916
# this check should probably be outside the loop: one
1917
# 'iterate two trees' api, and then _iter_changes filters
1918
# unchanged pairs. - RBC 20070226
1919
if (include_unchanged
1920
or result[2] # content change
1921
or result[3][0] != result[3][1] # versioned status
1922
or result[4][0] != result[4][1] # parent id
1923
or result[5][0] != result[5][1] # name
1924
or result[6][0] != result[6][1] # kind
1925
or result[7][0] != result[7][1] # executable
1928
if advance_entry and current_entry is not None:
1930
if entry_index < len(current_block[1]):
1931
current_entry = current_block[1][entry_index]
1933
current_entry = None
1935
advance_entry = True # reset the advance flaga
1936
if advance_path and current_path_info is not None:
1938
if path_index < len(current_dir_info[1]):
1939
current_path_info = current_dir_info[1][path_index]
1941
current_path_info = None
1943
advance_path = True # reset the advance flagg.
1944
if current_block is not None:
1946
if (block_index < len(state._dirblocks) and
1947
osutils.is_inside(current_root, state._dirblocks[block_index][0])):
1948
current_block = state._dirblocks[block_index]
1950
current_block = None
1951
if current_dir_info is not None:
1953
current_dir_info = dir_iterator.next()
1954
except StopIteration:
1955
current_dir_info = None
2248
search_specific_files = osutils.minimum_path_selection(specific_files)
2250
use_filesystem_for_exec = (sys.platform != 'win32')
2251
iter_changes = self.target._iter_changes(include_unchanged,
2252
use_filesystem_for_exec, search_specific_files, state,
2253
source_index, target_index, want_unversioned, self.target)
2254
return iter_changes.iter_changes()
1959
2257
def is_compatible(source, target):
1960
2258
# the target must be a dirstate working tree
1961
if not isinstance(target, WorkingTree4):
2259
if not isinstance(target, DirStateWorkingTree):
1963
# the source must be a revtreee or dirstate rev tree.
2261
# the source must be a revtree or dirstate rev tree.
1964
2262
if not isinstance(source,
1965
2263
(revisiontree.RevisionTree, DirStateRevisionTree)):
1967
2265
# the source revid must be in the target dirstate
1968
if not (source._revision_id == NULL_REVISION or
2266
if not (source._revision_id == _mod_revision.NULL_REVISION or
1969
2267
source._revision_id in target.get_parent_ids()):
1970
# TODO: what about ghosts? it may well need to
2268
# TODO: what about ghosts? it may well need to
1971
2269
# check for them explicitly.
1975
2273
InterTree.register_optimiser(InterDirStateTree)
2276
class Converter3to4(object):
2277
"""Perform an in-place upgrade of format 3 to format 4 trees."""
2280
self.target_format = WorkingTreeFormat4()
2282
def convert(self, tree):
2283
# lock the control files not the tree, so that we dont get tree
2284
# on-unlock behaviours, and so that noone else diddles with the
2285
# tree during upgrade.
2286
tree._control_files.lock_write()
2288
tree.read_working_inventory()
2289
self.create_dirstate_data(tree)
2290
self.update_format(tree)
2291
self.remove_xml_files(tree)
2293
tree._control_files.unlock()
2295
def create_dirstate_data(self, tree):
2296
"""Create the dirstate based data for tree."""
2297
local_path = tree.bzrdir.get_workingtree_transport(None
2298
).local_abspath('dirstate')
2299
state = dirstate.DirState.from_tree(tree, local_path)
2303
def remove_xml_files(self, tree):
2304
"""Remove the oldformat 3 data."""
2305
transport = tree.bzrdir.get_workingtree_transport(None)
2306
for path in ['basis-inventory-cache', 'inventory', 'last-revision',
2307
'pending-merges', 'stat-cache']:
2309
transport.delete(path)
2310
except errors.NoSuchFile:
2311
# some files are optional - just deal.
2314
def update_format(self, tree):
2315
"""Change the format marker."""
2316
tree._transport.put_bytes('format',
2317
self.target_format.as_string(),
2318
mode=tree.bzrdir._get_file_mode())
2321
class Converter4to5(object):
2322
"""Perform an in-place upgrade of format 4 to format 5 trees."""
2325
self.target_format = WorkingTreeFormat5()
2327
def convert(self, tree):
2328
# lock the control files not the tree, so that we don't get tree
2329
# on-unlock behaviours, and so that no-one else diddles with the
2330
# tree during upgrade.
2331
tree._control_files.lock_write()
2333
self.update_format(tree)
2335
tree._control_files.unlock()
2337
def update_format(self, tree):
2338
"""Change the format marker."""
2339
tree._transport.put_bytes('format',
2340
self.target_format.as_string(),
2341
mode=tree.bzrdir._get_file_mode())
2344
class Converter4or5to6(object):
2345
"""Perform an in-place upgrade of format 4 or 5 to format 6 trees."""
2348
self.target_format = WorkingTreeFormat6()
2350
def convert(self, tree):
2351
# lock the control files not the tree, so that we don't get tree
2352
# on-unlock behaviours, and so that no-one else diddles with the
2353
# tree during upgrade.
2354
tree._control_files.lock_write()
2356
self.init_custom_control_files(tree)
2357
self.update_format(tree)
2359
tree._control_files.unlock()
2361
def init_custom_control_files(self, tree):
2362
"""Initialize custom control files."""
2363
tree._transport.put_bytes('views', '',
2364
mode=tree.bzrdir._get_file_mode())
2366
def update_format(self, tree):
2367
"""Change the format marker."""
2368
tree._transport.put_bytes('format',
2369
self.target_format.as_string(),
2370
mode=tree.bzrdir._get_file_mode())