494
497
old.append(list(tree.annotate_iter(file_id)))
495
498
return annotate.reannotate(old, self.get_file(file_id).readlines(),
503
def _get_ancestors(self, default_revision):
504
ancestors = set([default_revision])
505
for parent_id in self.get_parent_ids():
506
ancestors.update(self.branch.repository.get_ancestry(
507
parent_id, topo_sorted=False))
500
510
def get_parent_ids(self):
501
511
"""See Tree.get_parent_ids.
503
513
This implementation reads the pending merges list and last_revision
504
514
value and uses that to decide what the parents list should be.
506
last_rev = self._last_revision()
516
last_rev = _mod_revision.ensure_null(self._last_revision())
517
if _mod_revision.NULL_REVISION == last_rev:
510
520
parents = [last_rev]
735
745
revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
736
746
self._check_parents_for_ghosts(revision_ids,
737
747
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
748
for revision_id in revision_ids:
749
_mod_revision.check_not_reserved_id(revision_id)
739
751
if len(revision_ids) > 0:
740
752
self.set_last_revision(revision_ids[0])
742
self.set_last_revision(None)
754
self.set_last_revision(_mod_revision.NULL_REVISION)
744
756
self._set_merges_from_parent_ids(revision_ids)
747
759
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
748
760
"""See MutableTree.set_parent_trees."""
749
761
parent_ids = [osutils.safe_revision_id(rev) for (rev, tree) in parents_list]
762
for revision_id in parent_ids:
763
_mod_revision.check_not_reserved_id(revision_id)
751
765
self._check_parents_for_ghosts(parent_ids,
752
766
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
754
768
if len(parent_ids) == 0:
755
leftmost_parent_id = None
769
leftmost_parent_id = _mod_revision.NULL_REVISION
756
770
leftmost_parent_tree = None
758
772
leftmost_parent_id, leftmost_parent_tree = parents_list[0]
789
803
self._control_files.put(filename, my_file)
791
805
@needs_write_lock # because merge pulls data into the branch.
792
def merge_from_branch(self, branch, to_revision=None):
806
def merge_from_branch(self, branch, to_revision=None, from_revision=None,
793
808
"""Merge from a branch into this working tree.
795
810
:param branch: The branch to merge from.
808
823
# local alterations
809
824
merger.check_basis(check_clean=True, require_commits=False)
810
825
if to_revision is None:
811
to_revision = branch.last_revision()
826
to_revision = _mod_revision.ensure_null(branch.last_revision())
813
828
to_revision = osutils.safe_revision_id(to_revision)
814
829
merger.other_rev_id = to_revision
815
if merger.other_rev_id is None:
816
raise error.NoCommits(branch)
830
if _mod_revision.is_null(merger.other_rev_id):
831
raise errors.NoCommits(branch)
817
832
self.branch.fetch(branch, last_revision=merger.other_rev_id)
818
833
merger.other_basis = merger.other_rev_id
819
834
merger.other_tree = self.branch.repository.revision_tree(
820
835
merger.other_rev_id)
821
836
merger.other_branch = branch
822
837
merger.pp.next_phase()
838
if from_revision is None:
841
merger.set_base_revision(from_revision, branch)
824
842
if merger.base_rev_id == merger.other_rev_id:
825
843
raise errors.PointlessMerge
826
844
merger.backup_files = False
827
merger.merge_type = Merge3Merger
845
if merge_type is None:
846
merger.merge_type = Merge3Merger
848
merger.merge_type = merge_type
828
849
merger.set_interesting_files(None)
829
850
merger.show_base = False
830
851
merger.reprocess = False
932
953
transport = self.branch.bzrdir.root_transport
933
954
for name in segments:
934
955
transport = transport.clone(name)
937
except errors.FileExists:
956
transport.ensure_base()
941
959
sub_path = self.id2path(file_id)
942
960
branch_transport = mkdirs(sub_path)
943
961
if format is None:
944
962
format = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
946
branch_transport.mkdir('.')
947
except errors.FileExists:
963
branch_transport.ensure_base()
949
964
branch_bzrdir = format.initialize_on_transport(branch_transport)
951
966
repo = branch_bzrdir.find_repository()
1789
1804
def recurse_directory_to_add_files(directory):
1790
1805
# recurse directory and add all files
1791
1806
# so we can check if they have changed.
1792
for contained_dir_info in self.walkdirs(directory):
1793
for file_info in contained_dir_info[1]:
1794
if file_info[2] == 'file':
1795
relpath = self.relpath(file_info[0])
1796
if file_info[4]: #is it versioned?
1807
for parent_info, file_infos in\
1808
osutils.walkdirs(self.abspath(directory),
1810
for relpath, basename, kind, lstat, abspath in file_infos:
1812
if self.path2id(relpath): #is it versioned?
1797
1813
new_files.add(relpath)
1799
1815
unknown_files_in_directory.add(
1800
(relpath, None, file_info[2]))
1816
(relpath, None, kind))
1802
1818
for filename in files:
1803
1819
# Get file name into canonical form.
1804
filename = self.relpath(self.abspath(filename))
1820
abspath = self.abspath(filename)
1821
filename = self.relpath(abspath)
1805
1822
if len(filename) > 0:
1806
1823
new_files.add(filename)
1807
if osutils.isdir(filename) and len(os.listdir(filename)) > 0:
1824
if osutils.isdir(abspath):
1808
1825
recurse_directory_to_add_files(filename)
1809
1826
files = [f for f in new_files]
1829
return # nothing to do
1811
1831
# Sort needed to first handle directory content before the directory
1812
1832
files.sort(reverse=True)
1813
1833
if not keep_files and not force:
1814
tree_delta = self.changes_from(self.basis_tree(),
1815
specific_files=files)
1816
for unknown_file in unknown_files_in_directory:
1817
tree_delta.unversioned.extend((unknown_file,))
1818
if bool(tree_delta.modified
1820
or tree_delta.renamed
1821
or tree_delta.kind_changed
1822
or tree_delta.unversioned):
1834
has_changed_files = len(unknown_files_in_directory) > 0
1835
if not has_changed_files:
1836
for (file_id, path, content_change, versioned, parent_id, name,
1837
kind, executable) in self._iter_changes(self.basis_tree(),
1838
include_unchanged=True, require_versioned=False,
1839
want_unversioned=True, specific_files=files):
1840
# check if it's unknown OR changed but not deleted:
1841
if (versioned == (False, False)
1842
or (content_change and kind[1] != None)):
1843
has_changed_files = True
1846
if has_changed_files:
1847
# make delta to show ALL applicable changes in error message.
1848
tree_delta = self.changes_from(self.basis_tree(),
1849
specific_files=files)
1850
for unknown_file in unknown_files_in_directory:
1851
tree_delta.unversioned.extend((unknown_file,))
1823
1852
raise errors.BzrRemoveChangedFilesError(tree_delta)
1825
1854
# do this before any modifications
1826
1855
for f in files:
1827
fid = inv.path2id(f)
1856
fid = self.path2id(f)
1830
1859
message="%s is not versioned." % (f,)
1835
1864
new_status = 'I'
1837
1866
new_status = '?'
1838
textui.show_status(new_status, inv[fid].kind, f,
1867
textui.show_status(new_status, self.kind(fid), f,
1839
1868
to_file=to_file)
1840
1869
# unversion file
1870
inv_delta.append((f, None, fid, None))
1842
1871
message="removed %s" % (f,)
1844
1873
if not keep_files:
2011
2040
old_tip = self.branch.update()
2014
return self._update_tree(old_tip)
2043
return self._update_tree(old_tip, change_reporter)
2018
2047
@needs_tree_write_lock
2019
def _update_tree(self, old_tip=None):
2048
def _update_tree(self, old_tip=None, change_reporter=None):
2020
2049
"""Update a tree to the master branch.
2022
2051
:param old_tip: if supplied, the previous tip revision the branch,
2074
2104
# the working tree had the same last-revision as the master
2075
2105
# branch did. We may still have pivot local work from the local
2076
2106
# branch into old_tip:
2077
if old_tip is not None:
2107
if (old_tip is not None and not _mod_revision.is_null(old_tip)):
2078
2108
self.add_parent_tree_id(old_tip)
2079
if old_tip and old_tip != last_rev:
2109
if (old_tip is not None and not _mod_revision.is_null(old_tip)
2110
and old_tip != last_rev):
2080
2111
# our last revision was not the prior branch last revision
2081
2112
# and we have converted that last revision to a pending merge.
2082
2113
# base is somewhere between the branch tip now
2089
2120
# inventory and calls tree._write_inventory(). Ultimately we
2090
2121
# should be able to remove this extra flush.
2092
from bzrlib.revision import common_ancestor
2094
base_rev_id = common_ancestor(self.branch.last_revision(),
2096
self.branch.repository)
2097
except errors.NoCommonAncestor:
2123
graph = self.branch.repository.get_graph()
2124
base_rev_id = graph.find_unique_lca(self.branch.last_revision(),
2099
2126
base_tree = self.branch.repository.revision_tree(base_rev_id)
2100
2127
other_tree = self.branch.repository.revision_tree(old_tip)
2101
2128
result += merge.merge_inner(
2133
change_reporter=change_reporter)
2108
2136
def _write_hashcache_if_dirty(self):
2602
2635
if not isinstance(a_bzrdir.transport, LocalTransport):
2603
2636
raise errors.NotLocalUrl(a_bzrdir.transport.base)
2604
2637
branch = a_bzrdir.open_branch()
2605
if revision_id is not None:
2638
if revision_id is None:
2639
revision_id = _mod_revision.ensure_null(branch.last_revision())
2606
2641
revision_id = osutils.safe_revision_id(revision_id)
2609
revision_history = branch.revision_history()
2611
position = revision_history.index(revision_id)
2613
raise errors.NoSuchRevision(branch, revision_id)
2614
branch.set_revision_history(revision_history[:position + 1])
2617
revision = branch.last_revision()
2644
branch.generate_revision_history(revision_id)
2618
2647
inv = Inventory()
2619
2648
wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2622
2651
_internal=True,
2624
2653
_bzrdir=a_bzrdir)
2625
basis_tree = branch.repository.revision_tree(revision)
2654
basis_tree = branch.repository.revision_tree(revision_id)
2626
2655
if basis_tree.inventory.root is not None:
2627
2656
wt.set_root_id(basis_tree.inventory.root.file_id)
2628
2657
# set the parent list and cache the basis tree.
2629
wt.set_parent_trees([(revision, basis_tree)])
2658
if _mod_revision.is_null(revision_id):
2661
parent_trees = [(revision_id, basis_tree)]
2662
wt.set_parent_trees(parent_trees)
2630
2663
transform.build_tree(basis_tree, wt)
2781
2814
# and not independently creatable, so are not registered.
2782
2815
_legacy_formats = [WorkingTreeFormat2(),
2786
class WorkingTreeTestProviderAdapter(object):
2787
"""A tool to generate a suite testing multiple workingtree formats at once.
2789
This is done by copying the test once for each transport and injecting
2790
the transport_server, transport_readonly_server, and workingtree_format
2791
classes into each copy. Each copy is also given a new id() to make it
2795
def __init__(self, transport_server, transport_readonly_server, formats):
2796
self._transport_server = transport_server
2797
self._transport_readonly_server = transport_readonly_server
2798
self._formats = formats
2800
def _clone_test(self, test, bzrdir_format, workingtree_format, variation):
2801
"""Clone test for adaption."""
2802
new_test = deepcopy(test)
2803
new_test.transport_server = self._transport_server
2804
new_test.transport_readonly_server = self._transport_readonly_server
2805
new_test.bzrdir_format = bzrdir_format
2806
new_test.workingtree_format = workingtree_format
2807
def make_new_test_id():
2808
new_id = "%s(%s)" % (test.id(), variation)
2809
return lambda: new_id
2810
new_test.id = make_new_test_id()
2813
def adapt(self, test):
2814
from bzrlib.tests import TestSuite
2815
result = TestSuite()
2816
for workingtree_format, bzrdir_format in self._formats:
2817
new_test = self._clone_test(
2820
workingtree_format, workingtree_format.__class__.__name__)
2821
result.addTest(new_test)