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,
1486
2225
if not found_versioned:
1487
2226
# 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)
2228
not_versioned.append(path.decode('utf-8'))
2229
if len(not_versioned) > 0:
2230
raise errors.PathsNotVersionedError(not_versioned)
1493
2231
# -- 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
2232
search_specific_files = osutils.minimum_path_selection(specific_files)
2234
use_filesystem_for_exec = (sys.platform != 'win32')
2235
iter_changes = self.target._iter_changes(include_unchanged,
2236
use_filesystem_for_exec, search_specific_files, state,
2237
source_index, target_index, want_unversioned, self.target)
2238
return iter_changes.iter_changes()
1959
2241
def is_compatible(source, target):
1960
2242
# the target must be a dirstate working tree
1961
if not isinstance(target, WorkingTree4):
2243
if not isinstance(target, DirStateWorkingTree):
1963
# the source must be a revtreee or dirstate rev tree.
2245
# the source must be a revtree or dirstate rev tree.
1964
2246
if not isinstance(source,
1965
2247
(revisiontree.RevisionTree, DirStateRevisionTree)):
1967
2249
# the source revid must be in the target dirstate
1968
if not (source._revision_id == NULL_REVISION or
2250
if not (source._revision_id == _mod_revision.NULL_REVISION or
1969
2251
source._revision_id in target.get_parent_ids()):
1970
# TODO: what about ghosts? it may well need to
2252
# TODO: what about ghosts? it may well need to
1971
2253
# check for them explicitly.
1975
2257
InterTree.register_optimiser(InterDirStateTree)
2260
class Converter3to4(object):
2261
"""Perform an in-place upgrade of format 3 to format 4 trees."""
2264
self.target_format = WorkingTreeFormat4()
2266
def convert(self, tree):
2267
# lock the control files not the tree, so that we dont get tree
2268
# on-unlock behaviours, and so that noone else diddles with the
2269
# tree during upgrade.
2270
tree._control_files.lock_write()
2272
tree.read_working_inventory()
2273
self.create_dirstate_data(tree)
2274
self.update_format(tree)
2275
self.remove_xml_files(tree)
2277
tree._control_files.unlock()
2279
def create_dirstate_data(self, tree):
2280
"""Create the dirstate based data for tree."""
2281
local_path = tree.bzrdir.get_workingtree_transport(None
2282
).local_abspath('dirstate')
2283
state = dirstate.DirState.from_tree(tree, local_path)
2287
def remove_xml_files(self, tree):
2288
"""Remove the oldformat 3 data."""
2289
transport = tree.bzrdir.get_workingtree_transport(None)
2290
for path in ['basis-inventory-cache', 'inventory', 'last-revision',
2291
'pending-merges', 'stat-cache']:
2293
transport.delete(path)
2294
except errors.NoSuchFile:
2295
# some files are optional - just deal.
2298
def update_format(self, tree):
2299
"""Change the format marker."""
2300
tree._transport.put_bytes('format',
2301
self.target_format.as_string(),
2302
mode=tree.bzrdir._get_file_mode())
2305
class Converter4to5(object):
2306
"""Perform an in-place upgrade of format 4 to format 5 trees."""
2309
self.target_format = WorkingTreeFormat5()
2311
def convert(self, tree):
2312
# lock the control files not the tree, so that we don't get tree
2313
# on-unlock behaviours, and so that no-one else diddles with the
2314
# tree during upgrade.
2315
tree._control_files.lock_write()
2317
self.update_format(tree)
2319
tree._control_files.unlock()
2321
def update_format(self, tree):
2322
"""Change the format marker."""
2323
tree._transport.put_bytes('format',
2324
self.target_format.as_string(),
2325
mode=tree.bzrdir._get_file_mode())
2328
class Converter4or5to6(object):
2329
"""Perform an in-place upgrade of format 4 or 5 to format 6 trees."""
2332
self.target_format = WorkingTreeFormat6()
2334
def convert(self, tree):
2335
# lock the control files not the tree, so that we don't get tree
2336
# on-unlock behaviours, and so that no-one else diddles with the
2337
# tree during upgrade.
2338
tree._control_files.lock_write()
2340
self.init_custom_control_files(tree)
2341
self.update_format(tree)
2343
tree._control_files.unlock()
2345
def init_custom_control_files(self, tree):
2346
"""Initialize custom control files."""
2347
tree._transport.put_bytes('views', '',
2348
mode=tree.bzrdir._get_file_mode())
2350
def update_format(self, tree):
2351
"""Change the format marker."""
2352
tree._transport.put_bytes('format',
2353
self.target_format.as_string(),
2354
mode=tree.bzrdir._get_file_mode())