494
494
old.append(list(tree.annotate_iter(file_id)))
495
495
return annotate.reannotate(old, self.get_file(file_id).readlines(),
500
def _get_ancestors(self, default_revision):
501
ancestors = set([default_revision])
502
for parent_id in self.get_parent_ids():
503
ancestors.update(self.branch.repository.get_ancestry(
504
parent_id, topo_sorted=False))
500
507
def get_parent_ids(self):
501
508
"""See Tree.get_parent_ids.
503
510
This implementation reads the pending merges list and last_revision
504
511
value and uses that to decide what the parents list should be.
506
last_rev = self._last_revision()
513
last_rev = _mod_revision.ensure_null(self._last_revision())
514
if _mod_revision.NULL_REVISION == last_rev:
510
517
parents = [last_rev]
735
742
revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
736
743
self._check_parents_for_ghosts(revision_ids,
737
744
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
745
for revision_id in revision_ids:
746
_mod_revision.check_not_reserved_id(revision_id)
739
748
if len(revision_ids) > 0:
740
749
self.set_last_revision(revision_ids[0])
742
self.set_last_revision(None)
751
self.set_last_revision(_mod_revision.NULL_REVISION)
744
753
self._set_merges_from_parent_ids(revision_ids)
747
756
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
748
757
"""See MutableTree.set_parent_trees."""
749
758
parent_ids = [osutils.safe_revision_id(rev) for (rev, tree) in parents_list]
759
for revision_id in parent_ids:
760
_mod_revision.check_not_reserved_id(revision_id)
751
762
self._check_parents_for_ghosts(parent_ids,
752
763
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
754
765
if len(parent_ids) == 0:
755
leftmost_parent_id = None
766
leftmost_parent_id = _mod_revision.NULL_REVISION
756
767
leftmost_parent_tree = None
758
769
leftmost_parent_id, leftmost_parent_tree = parents_list[0]
808
819
# local alterations
809
820
merger.check_basis(check_clean=True, require_commits=False)
810
821
if to_revision is None:
811
to_revision = branch.last_revision()
822
to_revision = _mod_revision.ensure_null(branch.last_revision())
813
824
to_revision = osutils.safe_revision_id(to_revision)
814
825
merger.other_rev_id = to_revision
815
if merger.other_rev_id is None:
816
raise error.NoCommits(branch)
826
if _mod_revision.is_null(merger.other_rev_id):
827
raise errors.NoCommits(branch)
817
828
self.branch.fetch(branch, last_revision=merger.other_rev_id)
818
829
merger.other_basis = merger.other_rev_id
819
830
merger.other_tree = self.branch.repository.revision_tree(
1783
1794
def recurse_directory_to_add_files(directory):
1784
1795
# recurse directory and add all files
1785
1796
# so we can check if they have changed.
1786
for contained_dir_info in self.walkdirs(directory):
1787
for file_info in contained_dir_info[1]:
1788
if file_info[2] == 'file':
1789
relpath = self.relpath(file_info[0])
1790
if file_info[4]: #is it versioned?
1797
for parent_info, file_infos in\
1798
osutils.walkdirs(self.abspath(directory),
1800
for relpath, basename, kind, lstat, abspath in file_infos:
1802
if self.path2id(relpath): #is it versioned?
1791
1803
new_files.add(relpath)
1793
1805
unknown_files_in_directory.add(
1794
(relpath, None, file_info[2]))
1806
(relpath, None, kind))
1796
1808
for filename in files:
1797
1809
# Get file name into canonical form.
1798
filename = self.relpath(self.abspath(filename))
1810
abspath = self.abspath(filename)
1811
filename = self.relpath(abspath)
1799
1812
if len(filename) > 0:
1800
1813
new_files.add(filename)
1801
if osutils.isdir(filename) and len(os.listdir(filename)) > 0:
1814
if osutils.isdir(abspath):
1802
1815
recurse_directory_to_add_files(filename)
1803
1816
files = [f for f in new_files]
1819
return # nothing to do
1805
1821
# Sort needed to first handle directory content before the directory
1806
1822
files.sort(reverse=True)
1807
1823
if not keep_files and not force:
1808
tree_delta = self.changes_from(self.basis_tree(),
1809
specific_files=files)
1810
for unknown_file in unknown_files_in_directory:
1811
tree_delta.unversioned.extend((unknown_file,))
1812
if bool(tree_delta.modified
1814
or tree_delta.renamed
1815
or tree_delta.kind_changed
1816
or tree_delta.unversioned):
1824
has_changed_files = len(unknown_files_in_directory) > 0
1825
if not has_changed_files:
1826
for (file_id, path, content_change, versioned, parent_id, name,
1827
kind, executable) in self._iter_changes(self.basis_tree(),
1828
include_unchanged=True, require_versioned=False,
1829
want_unversioned=True, specific_files=files):
1830
# check if it's unknown OR changed but not deleted:
1831
if (versioned == (False, False)
1832
or (content_change and kind[1] != None)):
1833
has_changed_files = True
1836
if has_changed_files:
1837
# make delta to show ALL applicable changes in error message.
1838
tree_delta = self.changes_from(self.basis_tree(),
1839
specific_files=files)
1840
for unknown_file in unknown_files_in_directory:
1841
tree_delta.unversioned.extend((unknown_file,))
1817
1842
raise errors.BzrRemoveChangedFilesError(tree_delta)
1819
1844
# do this before any modifications
1820
1845
for f in files:
1821
fid = inv.path2id(f)
1846
fid = self.path2id(f)
1824
1849
message="%s is not versioned." % (f,)
1829
1854
new_status = 'I'
1831
1856
new_status = '?'
1832
textui.show_status(new_status, inv[fid].kind, f,
1857
textui.show_status(new_status, self.kind(fid), f,
1833
1858
to_file=to_file)
1834
1859
# unversion file
1860
inv_delta.append((f, None, fid, None))
1836
1861
message="removed %s" % (f,)
1838
1863
if not keep_files:
2005
2030
old_tip = self.branch.update()
2008
return self._update_tree(old_tip)
2033
return self._update_tree(old_tip, change_reporter)
2012
2037
@needs_tree_write_lock
2013
def _update_tree(self, old_tip=None):
2038
def _update_tree(self, old_tip=None, change_reporter=None):
2014
2039
"""Update a tree to the master branch.
2016
2041
:param old_tip: if supplied, the previous tip revision the branch,
2068
2094
# the working tree had the same last-revision as the master
2069
2095
# branch did. We may still have pivot local work from the local
2070
2096
# branch into old_tip:
2071
if old_tip is not None:
2097
if (old_tip is not None and not _mod_revision.is_null(old_tip)):
2072
2098
self.add_parent_tree_id(old_tip)
2073
if old_tip and old_tip != last_rev:
2099
if (old_tip is not None and not _mod_revision.is_null(old_tip)
2100
and old_tip != last_rev):
2074
2101
# our last revision was not the prior branch last revision
2075
2102
# and we have converted that last revision to a pending merge.
2076
2103
# base is somewhere between the branch tip now
2083
2110
# inventory and calls tree._write_inventory(). Ultimately we
2084
2111
# should be able to remove this extra flush.
2086
from bzrlib.revision import common_ancestor
2088
base_rev_id = common_ancestor(self.branch.last_revision(),
2090
self.branch.repository)
2091
except errors.NoCommonAncestor:
2113
graph = self.branch.repository.get_graph()
2114
base_rev_id = graph.find_unique_lca(self.branch.last_revision(),
2093
2116
base_tree = self.branch.repository.revision_tree(base_rev_id)
2094
2117
other_tree = self.branch.repository.revision_tree(old_tip)
2095
2118
result += merge.merge_inner(
2123
change_reporter=change_reporter)
2102
2126
def _write_hashcache_if_dirty(self):
2595
2619
if not isinstance(a_bzrdir.transport, LocalTransport):
2596
2620
raise errors.NotLocalUrl(a_bzrdir.transport.base)
2597
2621
branch = a_bzrdir.open_branch()
2598
if revision_id is not None:
2622
if revision_id is None:
2623
revision_id = _mod_revision.ensure_null(branch.last_revision())
2599
2625
revision_id = osutils.safe_revision_id(revision_id)
2602
revision_history = branch.revision_history()
2604
position = revision_history.index(revision_id)
2606
raise errors.NoSuchRevision(branch, revision_id)
2607
branch.set_revision_history(revision_history[:position + 1])
2610
revision = branch.last_revision()
2628
branch.generate_revision_history(revision_id)
2611
2631
inv = Inventory()
2612
2632
wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2615
2635
_internal=True,
2617
2637
_bzrdir=a_bzrdir)
2618
basis_tree = branch.repository.revision_tree(revision)
2638
basis_tree = branch.repository.revision_tree(revision_id)
2619
2639
if basis_tree.inventory.root is not None:
2620
2640
wt.set_root_id(basis_tree.inventory.root.file_id)
2621
2641
# set the parent list and cache the basis tree.
2622
wt.set_parent_trees([(revision, basis_tree)])
2642
if _mod_revision.is_null(revision_id):
2645
parent_trees = [(revision_id, basis_tree)]
2646
wt.set_parent_trees(parent_trees)
2623
2647
transform.build_tree(basis_tree, wt)
2774
2798
# and not independently creatable, so are not registered.
2775
2799
_legacy_formats = [WorkingTreeFormat2(),
2779
class WorkingTreeTestProviderAdapter(object):
2780
"""A tool to generate a suite testing multiple workingtree formats at once.
2782
This is done by copying the test once for each transport and injecting
2783
the transport_server, transport_readonly_server, and workingtree_format
2784
classes into each copy. Each copy is also given a new id() to make it
2788
def __init__(self, transport_server, transport_readonly_server, formats):
2789
self._transport_server = transport_server
2790
self._transport_readonly_server = transport_readonly_server
2791
self._formats = formats
2793
def _clone_test(self, test, bzrdir_format, workingtree_format, variation):
2794
"""Clone test for adaption."""
2795
new_test = deepcopy(test)
2796
new_test.transport_server = self._transport_server
2797
new_test.transport_readonly_server = self._transport_readonly_server
2798
new_test.bzrdir_format = bzrdir_format
2799
new_test.workingtree_format = workingtree_format
2800
def make_new_test_id():
2801
new_id = "%s(%s)" % (test.id(), variation)
2802
return lambda: new_id
2803
new_test.id = make_new_test_id()
2806
def adapt(self, test):
2807
from bzrlib.tests import TestSuite
2808
result = TestSuite()
2809
for workingtree_format, bzrdir_format in self._formats:
2810
new_test = self._clone_test(
2813
workingtree_format, workingtree_format.__class__.__name__)
2814
result.addTest(new_test)