1252
1057
self._inventory.remove_recursive_id(file_id)
1254
1059
@needs_tree_write_lock
1255
def rename_one(self, from_rel, to_rel, after=False):
1256
"""See WorkingTree.rename_one"""
1258
WorkingTree.rename_one(self, from_rel, to_rel, after)
1260
@needs_tree_write_lock
1261
def apply_inventory_delta(self, changes):
1262
"""See MutableTree.apply_inventory_delta"""
1263
state = self.current_dirstate()
1264
state.update_by_delta(changes)
1265
self._make_dirty(reset_inventory=True)
1267
def update_basis_by_delta(self, new_revid, delta):
1268
"""See MutableTree.update_basis_by_delta."""
1269
if self.last_revision() == new_revid:
1270
raise AssertionError()
1271
self.current_dirstate().update_basis_by_delta(delta, new_revid)
1274
def _validate(self):
1275
self._dirstate._validate()
1277
@needs_tree_write_lock
1278
1060
def _write_inventory(self, inv):
1279
1061
"""Write inventory as the current inventory."""
1281
raise AssertionError("attempting to write an inventory when the "
1282
"dirstate is dirty will lose pending changes")
1283
had_inventory = self._inventory is not None
1284
# Setting self._inventory = None forces the dirstate to regenerate the
1285
# working inventory. We do this because self.inventory may be inv, or
1286
# may have been modified, and either case would prevent a clean delta
1288
self._inventory = None
1290
delta = inv._make_delta(self.inventory)
1292
self.apply_inventory_delta(delta)
1062
assert not self._dirty, "attempting to write an inventory when the dirstate is dirty will cause data loss"
1063
self.current_dirstate().set_state_from_inventory(inv)
1064
self._make_dirty(reset_inventory=False)
1065
if self._inventory is not None:
1294
1066
self._inventory = inv
1298
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1300
def __init__(self, tree):
1303
def sha1(self, abspath):
1304
"""See dirstate.SHA1Provider.sha1()."""
1305
filters = self.tree._content_filter_stack(
1306
self.tree.relpath(osutils.safe_unicode(abspath)))
1307
return internal_size_sha_file_byname(abspath, filters)[1]
1309
def stat_and_sha1(self, abspath):
1310
"""See dirstate.SHA1Provider.stat_and_sha1()."""
1311
filters = self.tree._content_filter_stack(
1312
self.tree.relpath(osutils.safe_unicode(abspath)))
1313
file_obj = file(abspath, 'rb', 65000)
1315
statvalue = os.fstat(file_obj.fileno())
1317
file_obj = filtered_input_file(file_obj, filters)
1318
sha1 = osutils.size_sha_file(file_obj)[1]
1321
return statvalue, sha1
1324
class ContentFilteringDirStateWorkingTree(DirStateWorkingTree):
1325
"""Dirstate working tree that supports content filtering.
1327
The dirstate holds the hash and size of the canonical form of the file,
1328
and most methods must return that.
1331
def _file_content_summary(self, path, stat_result):
1332
# This is to support the somewhat obsolete path_content_summary method
1333
# with content filtering: see
1334
# <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
1336
# If the dirstate cache is up to date and knows the hash and size,
1338
# Otherwise if there are no content filters, return the on-disk size
1339
# and leave the hash blank.
1340
# Otherwise, read and filter the on-disk file and use its size and
1343
# The dirstate doesn't store the size of the canonical form so we
1344
# can't trust it for content-filtered trees. We just return None.
1345
dirstate_sha1 = self._dirstate.sha1_from_stat(path, stat_result)
1346
executable = self._is_executable_from_path_and_stat(path, stat_result)
1347
return ('file', None, executable, dirstate_sha1)
1350
class WorkingTree4(DirStateWorkingTree):
1351
"""This is the Format 4 working tree.
1353
This differs from WorkingTree3 by:
1354
- Having a consolidated internal dirstate, stored in a
1355
randomly-accessible sorted file on disk.
1356
- Not having a regular inventory attribute. One can be synthesized
1357
on demand but this is expensive and should be avoided.
1359
This is new in bzr 0.15.
1363
class WorkingTree5(ContentFilteringDirStateWorkingTree):
1364
"""This is the Format 5 working tree.
1366
This differs from WorkingTree4 by:
1367
- Supporting content filtering.
1369
This is new in bzr 1.11.
1373
class WorkingTree6(ContentFilteringDirStateWorkingTree):
1374
"""This is the Format 6 working tree.
1376
This differs from WorkingTree5 by:
1377
- Supporting a current view that may mask the set of files in a tree
1378
impacted by most user operations.
1380
This is new in bzr 1.14.
1383
def _make_views(self):
1384
return views.PathBasedViews(self)
1387
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1389
def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1390
accelerator_tree=None, hardlink=False):
1070
class WorkingTreeFormat4(WorkingTreeFormat3):
1071
"""The first consolidated dirstate working tree format.
1074
- exists within a metadir controlling .bzr
1075
- includes an explicit version marker for the workingtree control
1076
files, separate from the BzrDir format
1077
- modifies the hash cache format
1078
- is new in bzr TODO FIXME SETBEFOREMERGE
1079
- uses a LockDir to guard access to it.
1082
def get_format_string(self):
1083
"""See WorkingTreeFormat.get_format_string()."""
1084
return "Bazaar Working Tree format 4\n"
1086
def get_format_description(self):
1087
"""See WorkingTreeFormat.get_format_description()."""
1088
return "Working tree format 4"
1090
def initialize(self, a_bzrdir, revision_id=None):
1391
1091
"""See WorkingTreeFormat.initialize().
1393
:param revision_id: allows creating a working tree at a different
1093
revision_id allows creating a working tree at a different
1394
1094
revision than the branch is at.
1395
:param accelerator_tree: A tree which can be used for retrieving file
1396
contents more quickly than the revision tree, i.e. a workingtree.
1397
The revision tree will be used for cases where accelerator_tree's
1398
content is different.
1399
:param hardlink: If true, hard-link files from accelerator_tree,
1402
These trees get an initial random root id, if their repository supports
1403
rich root data, TREE_ROOT otherwise.
1096
revision_id = osutils.safe_revision_id(revision_id)
1405
1097
if not isinstance(a_bzrdir.transport, LocalTransport):
1406
1098
raise errors.NotLocalUrl(a_bzrdir.transport.base)
1407
1099
transport = a_bzrdir.get_workingtree_transport(self)
1408
1100
control_files = self._open_control_files(a_bzrdir)
1409
1101
control_files.create_lock()
1410
1102
control_files.lock_write()
1411
transport.put_bytes('format', self.get_format_string(),
1412
mode=a_bzrdir._get_file_mode())
1413
if from_branch is not None:
1414
branch = from_branch
1416
branch = a_bzrdir.open_branch()
1103
control_files.put_utf8('format', self.get_format_string())
1104
branch = a_bzrdir.open_branch()
1417
1105
if revision_id is None:
1418
1106
revision_id = branch.last_revision()
1419
1107
local_path = transport.local_abspath('dirstate')
1420
# write out new dirstate (must exist when we create the tree)
1421
1108
state = dirstate.DirState.initialize(local_path)
1424
wt = self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
1110
wt = WorkingTree4(a_bzrdir.root_transport.local_abspath('.'),
1427
1113
_bzrdir=a_bzrdir,
2102
1532
if not found_versioned:
2103
1533
# none of the indexes was not 'absent' at all ids for this
2105
not_versioned.append(path)
2106
if len(not_versioned) > 0:
2107
raise errors.PathsNotVersionedError(not_versioned)
1535
all_versioned = False
1537
if not all_versioned:
1538
raise errors.PathsNotVersionedError(specific_files)
2108
1539
# -- remove redundancy in supplied specific_files to prevent over-scanning --
2109
search_specific_files = osutils.minimum_path_selection(specific_files)
2111
use_filesystem_for_exec = (sys.platform != 'win32')
2112
iter_changes = self.target._iter_changes(include_unchanged,
2113
use_filesystem_for_exec, search_specific_files, state,
2114
source_index, target_index, want_unversioned, self.target)
2115
return iter_changes.iter_changes()
1540
search_specific_files = set()
1541
for path in specific_files:
1542
other_specific_files = specific_files.difference(set([path]))
1543
if not osutils.is_inside_any(other_specific_files, path):
1544
# this is a top level path, we must check it.
1545
search_specific_files.add(path)
1547
# compare source_index and target_index at or under each element of search_specific_files.
1548
# follow the following comparison table. Note that we only want to do diff operations when
1549
# the target is fdl because thats when the walkdirs logic will have exposed the pathinfo
1553
# Source | Target | disk | action
1554
# r | fdl | | add source to search, add id path move and perform
1555
# | | | diff check on source-target
1556
# r | fdl | a | dangling file that was present in the basis.
1558
# r | a | | add source to search
1560
# r | r | | this path is present in a non-examined tree, skip.
1561
# r | r | a | this path is present in a non-examined tree, skip.
1562
# a | fdl | | add new id
1563
# a | fdl | a | dangling locally added file, skip
1564
# a | a | | not present in either tree, skip
1565
# a | a | a | not present in any tree, skip
1566
# a | r | | not present in either tree at this path, skip as it
1567
# | | | may not be selected by the users list of paths.
1568
# a | r | a | not present in either tree at this path, skip as it
1569
# | | | may not be selected by the users list of paths.
1570
# fdl | fdl | | content in both: diff them
1571
# fdl | fdl | a | deleted locally, but not unversioned - show as deleted ?
1572
# fdl | a | | unversioned: output deleted id for now
1573
# fdl | a | a | unversioned and deleted: output deleted id
1574
# fdl | r | | relocated in this tree, so add target to search.
1575
# | | | Dont diff, we will see an r,fd; pair when we reach
1576
# | | | this id at the other path.
1577
# fdl | r | a | relocated in this tree, so add target to search.
1578
# | | | Dont diff, we will see an r,fd; pair when we reach
1579
# | | | this id at the other path.
1581
# for all search_indexs in each path at or under each element of
1582
# search_specific_files, if the detail is relocated: add the id, and add the
1583
# relocated path as one to search if its not searched already. If the
1584
# detail is not relocated, add the id.
1585
searched_specific_files = set()
1586
NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS
1587
# Using a list so that we can access the values and change them in
1588
# nested scope. Each one is [path, file_id, entry]
1589
last_source_parent = [None, None, None]
1590
last_target_parent = [None, None, None]
1592
def _process_entry(entry, path_info):
1593
"""Compare an entry and real disk to generate delta information.
1595
:param path_info: top_relpath, basename, kind, lstat, abspath for
1596
the path of entry. If None, then the path is considered absent.
1597
(Perhaps we should pass in a concrete entry for this ?)
1598
Basename is returned as a utf8 string because we expect this
1599
tuple will be ignored, and don't want to take the time to
1602
# TODO: when a parent has been renamed, dont emit path renames for children,
1603
if source_index is None:
1604
source_details = NULL_PARENT_DETAILS
1606
source_details = entry[1][source_index]
1607
target_details = entry[1][target_index]
1608
target_minikind = target_details[0]
1609
if path_info is not None and target_minikind in 'fdl':
1610
assert target_index == 0
1611
link_or_sha1 = state.update_entry(entry, abspath=path_info[4],
1612
stat_value=path_info[3])
1613
# The entry may have been modified by update_entry
1614
target_details = entry[1][target_index]
1615
target_minikind = target_details[0]
1618
source_minikind = source_details[0]
1619
if source_minikind in 'fdlr' and target_minikind in 'fdl':
1620
# claimed content in both: diff
1621
# r | fdl | | add source to search, add id path move and perform
1622
# | | | diff check on source-target
1623
# r | fdl | a | dangling file that was present in the basis.
1625
if source_minikind in 'r':
1626
# add the source to the search path to find any children it
1627
# has. TODO ? : only add if it is a container ?
1628
if not osutils.is_inside_any(searched_specific_files,
1630
search_specific_files.add(source_details[1])
1631
# generate the old path; this is needed for stating later
1633
old_path = source_details[1]
1634
old_dirname, old_basename = os.path.split(old_path)
1635
path = pathjoin(entry[0][0], entry[0][1])
1636
old_entry = state._get_entry(source_index,
1638
# update the source details variable to be the real
1640
source_details = old_entry[1][source_index]
1641
source_minikind = source_details[0]
1643
old_dirname = entry[0][0]
1644
old_basename = entry[0][1]
1645
old_path = path = pathjoin(old_dirname, old_basename)
1646
if path_info is None:
1647
# the file is missing on disk, show as removed.
1648
content_change = True
1652
# source and target are both versioned and disk file is present.
1653
target_kind = path_info[2]
1654
if target_kind == 'directory':
1655
if source_minikind != 'd':
1656
content_change = True
1658
# directories have no fingerprint
1659
content_change = False
1661
elif target_kind == 'file':
1662
if source_minikind != 'f':
1663
content_change = True
1665
# We could check the size, but we already have the
1667
content_change = (link_or_sha1 != source_details[1])
1668
# Target details is updated at update_entry time
1670
stat.S_ISREG(path_info[3].st_mode)
1671
and stat.S_IEXEC & path_info[3].st_mode)
1672
elif target_kind == 'symlink':
1673
if source_minikind != 'l':
1674
content_change = True
1676
content_change = (link_or_sha1 != source_details[1])
1679
raise Exception, "unknown kind %s" % path_info[2]
1680
# parent id is the entry for the path in the target tree
1681
if old_dirname == last_source_parent[0]:
1682
source_parent_id = last_source_parent[1]
1684
source_parent_entry = state._get_entry(source_index,
1685
path_utf8=old_dirname)
1686
source_parent_id = source_parent_entry[0][2]
1687
if source_parent_id == entry[0][2]:
1688
# This is the root, so the parent is None
1689
source_parent_id = None
1691
last_source_parent[0] = old_dirname
1692
last_source_parent[1] = source_parent_id
1693
last_source_parent[2] = source_parent_entry
1695
new_dirname = entry[0][0]
1696
if new_dirname == last_target_parent[0]:
1697
target_parent_id = last_target_parent[1]
1699
# TODO: We don't always need to do the lookup, because the
1700
# parent entry will be the same as the source entry.
1701
target_parent_entry = state._get_entry(target_index,
1702
path_utf8=new_dirname)
1703
target_parent_id = target_parent_entry[0][2]
1704
if target_parent_id == entry[0][2]:
1705
# This is the root, so the parent is None
1706
target_parent_id = None
1708
last_target_parent[0] = new_dirname
1709
last_target_parent[1] = target_parent_id
1710
last_target_parent[2] = target_parent_entry
1712
source_exec = source_details[3]
1713
return ((entry[0][2], (old_path, path), content_change,
1715
(source_parent_id, target_parent_id),
1716
(old_basename, entry[0][1]),
1717
(_minikind_to_kind[source_minikind], target_kind),
1718
(source_exec, target_exec)),)
1719
elif source_minikind in 'a' and target_minikind in 'fdl':
1720
# looks like a new file
1721
if path_info is not None:
1722
path = pathjoin(entry[0][0], entry[0][1])
1723
# parent id is the entry for the path in the target tree
1724
# TODO: these are the same for an entire directory: cache em.
1725
parent_id = state._get_entry(target_index,
1726
path_utf8=entry[0][0])[0][2]
1727
if parent_id == entry[0][2]:
1730
stat.S_ISREG(path_info[3].st_mode)
1731
and stat.S_IEXEC & path_info[3].st_mode)
1732
return ((entry[0][2], (None, path), True,
1735
(None, entry[0][1]),
1736
(None, path_info[2]),
1737
(None, target_exec)),)
1739
# but its not on disk: we deliberately treat this as just
1740
# never-present. (Why ?! - RBC 20070224)
1742
elif source_minikind in 'fdl' and target_minikind in 'a':
1743
# unversioned, possibly, or possibly not deleted: we dont care.
1744
# if its still on disk, *and* theres no other entry at this
1745
# path [we dont know this in this routine at the moment -
1746
# perhaps we should change this - then it would be an unknown.
1747
old_path = pathjoin(entry[0][0], entry[0][1])
1748
# parent id is the entry for the path in the target tree
1749
parent_id = state._get_entry(source_index, path_utf8=entry[0][0])[0][2]
1750
if parent_id == entry[0][2]:
1752
return ((entry[0][2], (old_path, None), True,
1755
(entry[0][1], None),
1756
(_minikind_to_kind[source_minikind], None),
1757
(source_details[3], None)),)
1758
elif source_minikind in 'fdl' and target_minikind in 'r':
1759
# a rename; could be a true rename, or a rename inherited from
1760
# a renamed parent. TODO: handle this efficiently. Its not
1761
# common case to rename dirs though, so a correct but slow
1762
# implementation will do.
1763
if not osutils.is_inside_any(searched_specific_files, target_details[1]):
1764
search_specific_files.add(target_details[1])
1765
elif source_minikind in 'r' and target_minikind in 'r':
1766
# neither of the selected trees contain this file,
1767
# so skip over it. This is not currently directly tested, but
1768
# is indirectly via test_too_much.TestCommands.test_conflicts.
1771
print "*******", source_minikind, target_minikind
1772
import pdb;pdb.set_trace()
1774
while search_specific_files:
1775
# TODO: the pending list should be lexically sorted?
1776
current_root = search_specific_files.pop()
1777
searched_specific_files.add(current_root)
1778
# process the entries for this containing directory: the rest will be
1779
# found by their parents recursively.
1780
root_entries = _entries_for_path(current_root)
1781
root_abspath = self.target.abspath(current_root)
1783
root_stat = os.lstat(root_abspath)
1785
if e.errno == errno.ENOENT:
1786
# the path does not exist: let _process_entry know that.
1787
root_dir_info = None
1789
# some other random error: hand it up.
1792
root_dir_info = ('', current_root,
1793
osutils.file_kind_from_stat_mode(root_stat.st_mode), root_stat,
1795
if not root_entries and not root_dir_info:
1796
# this specified path is not present at all, skip it.
1798
path_handled = False
1799
for entry in root_entries:
1800
for result in _process_entry(entry, root_dir_info):
1801
# this check should probably be outside the loop: one
1802
# 'iterate two trees' api, and then _iter_changes filters
1803
# unchanged pairs. - RBC 20070226
1805
if (include_unchanged
1806
or result[2] # content change
1807
or result[3][0] != result[3][1] # versioned status
1808
or result[4][0] != result[4][1] # parent id
1809
or result[5][0] != result[5][1] # name
1810
or result[6][0] != result[6][1] # kind
1811
or result[7][0] != result[7][1] # executable
1813
result = (result[0],
1814
((utf8_decode(result[1][0])[0]),
1815
utf8_decode(result[1][1])[0]),) + result[2:]
1817
if want_unversioned and not path_handled:
1818
new_executable = bool(
1819
stat.S_ISREG(root_dir_info[3].st_mode)
1820
and stat.S_IEXEC & root_dir_info[3].st_mode)
1821
yield (None, (None, current_root), True, (False, False),
1823
(None, splitpath(current_root)[-1]),
1824
(None, root_dir_info[2]), (None, new_executable))
1825
dir_iterator = osutils._walkdirs_utf8(root_abspath, prefix=current_root)
1826
initial_key = (current_root, '', '')
1827
block_index, _ = state._find_block_index_from_key(initial_key)
1828
if block_index == 0:
1829
# we have processed the total root already, but because the
1830
# initial key matched it we should skip it here.
1833
current_dir_info = dir_iterator.next()
1835
if e.errno in (errno.ENOENT, errno.ENOTDIR):
1836
# there may be directories in the inventory even though
1837
# this path is not a file on disk: so mark it as end of
1839
current_dir_info = None
1843
if current_dir_info[0][0] == '':
1844
# remove .bzr from iteration
1845
bzr_index = bisect_left(current_dir_info[1], ('.bzr',))
1846
assert current_dir_info[1][bzr_index][0] == '.bzr'
1847
del current_dir_info[1][bzr_index]
1848
# walk until both the directory listing and the versioned metadata
1849
# are exhausted. TODO: reevaluate this, perhaps we should stop when
1850
# the versioned data runs out.
1851
if (block_index < len(state._dirblocks) and
1852
osutils.is_inside(current_root, state._dirblocks[block_index][0])):
1853
current_block = state._dirblocks[block_index]
1855
current_block = None
1856
while (current_dir_info is not None or
1857
current_block is not None):
1858
if (current_dir_info and current_block
1859
and current_dir_info[0][0] != current_block[0]):
1860
if current_dir_info[0][0] < current_block[0] :
1861
# import pdb; pdb.set_trace()
1862
# print 'unversioned dir'
1863
# filesystem data refers to paths not covered by the dirblock.
1864
# this has two possibilities:
1865
# A) it is versioned but empty, so there is no block for it
1866
# B) it is not versioned.
1867
# in either case it was processed by the containing directories walk:
1868
# if it is root/foo, when we walked root we emitted it,
1869
# or if we ere given root/foo to walk specifically, we
1870
# emitted it when checking the walk-root entries
1871
# advance the iterator and loop - we dont need to emit it.
1873
current_dir_info = dir_iterator.next()
1874
except StopIteration:
1875
current_dir_info = None
1877
# We have a dirblock entry for this location, but there
1878
# is no filesystem path for this. This is most likely
1879
# because a directory was removed from the disk.
1880
# We don't have to report the missing directory,
1881
# because that should have already been handled, but we
1882
# need to handle all of the files that are contained
1884
for current_entry in current_block[1]:
1885
# entry referring to file not present on disk.
1886
# advance the entry only, after processing.
1887
for result in _process_entry(current_entry, None):
1888
# this check should probably be outside the loop: one
1889
# 'iterate two trees' api, and then _iter_changes filters
1890
# unchanged pairs. - RBC 20070226
1891
if (include_unchanged
1892
or result[2] # content change
1893
or result[3][0] != result[3][1] # versioned status
1894
or result[4][0] != result[4][1] # parent id
1895
or result[5][0] != result[5][1] # name
1896
or result[6][0] != result[6][1] # kind
1897
or result[7][0] != result[7][1] # executable
1899
result = (result[0],
1900
((utf8_decode(result[1][0])[0]),
1901
utf8_decode(result[1][1])[0]),) + result[2:]
1904
if (block_index < len(state._dirblocks) and
1905
osutils.is_inside(current_root,
1906
state._dirblocks[block_index][0])):
1907
current_block = state._dirblocks[block_index]
1909
current_block = None
1912
if current_block and entry_index < len(current_block[1]):
1913
current_entry = current_block[1][entry_index]
1915
current_entry = None
1916
advance_entry = True
1918
if current_dir_info and path_index < len(current_dir_info[1]):
1919
current_path_info = current_dir_info[1][path_index]
1921
current_path_info = None
1923
path_handled = False
1924
while (current_entry is not None or
1925
current_path_info is not None):
1926
if current_entry is None:
1927
# the check for path_handled when the path is adnvaced
1928
# will yield this path if needed.
1930
elif current_path_info is None:
1931
# no path is fine: the per entry code will handle it.
1932
for result in _process_entry(current_entry, current_path_info):
1933
# this check should probably be outside the loop: one
1934
# 'iterate two trees' api, and then _iter_changes filters
1935
# unchanged pairs. - RBC 20070226
1936
if (include_unchanged
1937
or result[2] # content change
1938
or result[3][0] != result[3][1] # versioned status
1939
or result[4][0] != result[4][1] # parent id
1940
or result[5][0] != result[5][1] # name
1941
or result[6][0] != result[6][1] # kind
1942
or result[7][0] != result[7][1] # executable
1944
result = (result[0],
1945
((utf8_decode(result[1][0])[0]),
1946
utf8_decode(result[1][1])[0]),) + result[2:]
1948
elif current_entry[0][1] != current_path_info[1]:
1949
if current_path_info[1] < current_entry[0][1]:
1950
# extra file on disk: pass for now, but only
1951
# increment the path, not the entry
1952
# import pdb; pdb.set_trace()
1953
# print 'unversioned file'
1954
advance_entry = False
1956
# entry referring to file not present on disk.
1957
# advance the entry only, after processing.
1958
for result in _process_entry(current_entry, None):
1959
# this check should probably be outside the loop: one
1960
# 'iterate two trees' api, and then _iter_changes filters
1961
# unchanged pairs. - RBC 20070226
1963
if (include_unchanged
1964
or result[2] # content change
1965
or result[3][0] != result[3][1] # versioned status
1966
or result[4][0] != result[4][1] # parent id
1967
or result[5][0] != result[5][1] # name
1968
or result[6][0] != result[6][1] # kind
1969
or result[7][0] != result[7][1] # executable
1971
result = (result[0],
1972
((utf8_decode(result[1][0])[0]),
1973
utf8_decode(result[1][1])[0]),) + result[2:]
1975
advance_path = False
1977
for result in _process_entry(current_entry, current_path_info):
1978
# this check should probably be outside the loop: one
1979
# 'iterate two trees' api, and then _iter_changes filters
1980
# unchanged pairs. - RBC 20070226
1982
if (include_unchanged
1983
or result[2] # content change
1984
or result[3][0] != result[3][1] # versioned status
1985
or result[4][0] != result[4][1] # parent id
1986
or result[5][0] != result[5][1] # name
1987
or result[6][0] != result[6][1] # kind
1988
or result[7][0] != result[7][1] # executable
1990
result = (result[0],
1991
((utf8_decode(result[1][0])[0]),
1992
utf8_decode(result[1][1])[0]),) + result[2:]
1994
if advance_entry and current_entry is not None:
1996
if entry_index < len(current_block[1]):
1997
current_entry = current_block[1][entry_index]
1999
current_entry = None
2001
advance_entry = True # reset the advance flaga
2002
if advance_path and current_path_info is not None:
2003
if not path_handled:
2004
# unversioned in all regards
2005
if want_unversioned:
2006
new_executable = bool(
2007
stat.S_ISREG(current_path_info[3].st_mode)
2008
and stat.S_IEXEC & current_path_info[3].st_mode)
2009
if want_unversioned:
2010
yield (None, (None, current_path_info[0]),
2014
(None, current_path_info[1]),
2015
(None, current_path_info[2]),
2016
(None, new_executable))
2017
# dont descend into this unversioned path if it is
2019
if current_path_info[2] == 'directory':
2020
del current_dir_info[1][path_index]
2023
if path_index < len(current_dir_info[1]):
2024
current_path_info = current_dir_info[1][path_index]
2026
current_path_info = None
2027
path_handled = False
2029
advance_path = True # reset the advance flagg.
2030
if current_block is not None:
2032
if (block_index < len(state._dirblocks) and
2033
osutils.is_inside(current_root, state._dirblocks[block_index][0])):
2034
current_block = state._dirblocks[block_index]
2036
current_block = None
2037
if current_dir_info is not None:
2039
current_dir_info = dir_iterator.next()
2040
except StopIteration:
2041
current_dir_info = None
2118
2045
def is_compatible(source, target):
2119
2046
# the target must be a dirstate working tree
2120
if not isinstance(target, DirStateWorkingTree):
2047
if not isinstance(target, WorkingTree4):
2122
# the source must be a revtree or dirstate rev tree.
2049
# the source must be a revtreee or dirstate rev tree.
2123
2050
if not isinstance(source,
2124
2051
(revisiontree.RevisionTree, DirStateRevisionTree)):
2126
2053
# the source revid must be in the target dirstate
2127
if not (source._revision_id == _mod_revision.NULL_REVISION or
2054
if not (source._revision_id == NULL_REVISION or
2128
2055
source._revision_id in target.get_parent_ids()):
2129
# TODO: what about ghosts? it may well need to
2056
# TODO: what about ghosts? it may well need to
2130
2057
# check for them explicitly.
2134
2061
InterTree.register_optimiser(InterDirStateTree)
2137
class Converter3to4(object):
2138
"""Perform an in-place upgrade of format 3 to format 4 trees."""
2141
self.target_format = WorkingTreeFormat4()
2143
def convert(self, tree):
2144
# lock the control files not the tree, so that we dont get tree
2145
# on-unlock behaviours, and so that noone else diddles with the
2146
# tree during upgrade.
2147
tree._control_files.lock_write()
2149
tree.read_working_inventory()
2150
self.create_dirstate_data(tree)
2151
self.update_format(tree)
2152
self.remove_xml_files(tree)
2154
tree._control_files.unlock()
2156
def create_dirstate_data(self, tree):
2157
"""Create the dirstate based data for tree."""
2158
local_path = tree.bzrdir.get_workingtree_transport(None
2159
).local_abspath('dirstate')
2160
state = dirstate.DirState.from_tree(tree, local_path)
2164
def remove_xml_files(self, tree):
2165
"""Remove the oldformat 3 data."""
2166
transport = tree.bzrdir.get_workingtree_transport(None)
2167
for path in ['basis-inventory-cache', 'inventory', 'last-revision',
2168
'pending-merges', 'stat-cache']:
2170
transport.delete(path)
2171
except errors.NoSuchFile:
2172
# some files are optional - just deal.
2175
def update_format(self, tree):
2176
"""Change the format marker."""
2177
tree._transport.put_bytes('format',
2178
self.target_format.get_format_string(),
2179
mode=tree.bzrdir._get_file_mode())
2182
class Converter4to5(object):
2183
"""Perform an in-place upgrade of format 4 to format 5 trees."""
2186
self.target_format = WorkingTreeFormat5()
2188
def convert(self, tree):
2189
# lock the control files not the tree, so that we don't get tree
2190
# on-unlock behaviours, and so that no-one else diddles with the
2191
# tree during upgrade.
2192
tree._control_files.lock_write()
2194
self.update_format(tree)
2196
tree._control_files.unlock()
2198
def update_format(self, tree):
2199
"""Change the format marker."""
2200
tree._transport.put_bytes('format',
2201
self.target_format.get_format_string(),
2202
mode=tree.bzrdir._get_file_mode())
2205
class Converter4or5to6(object):
2206
"""Perform an in-place upgrade of format 4 or 5 to format 6 trees."""
2209
self.target_format = WorkingTreeFormat6()
2211
def convert(self, tree):
2212
# lock the control files not the tree, so that we don't get tree
2213
# on-unlock behaviours, and so that no-one else diddles with the
2214
# tree during upgrade.
2215
tree._control_files.lock_write()
2217
self.init_custom_control_files(tree)
2218
self.update_format(tree)
2220
tree._control_files.unlock()
2222
def init_custom_control_files(self, tree):
2223
"""Initialize custom control files."""
2224
tree._transport.put_bytes('views', '',
2225
mode=tree.bzrdir._get_file_mode())
2227
def update_format(self, tree):
2228
"""Change the format marker."""
2229
tree._transport.put_bytes('format',
2230
self.target_format.get_format_string(),
2231
mode=tree.bzrdir._get_file_mode())