1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
442
442
conflicts.extend(self._overwrite_conflicts())
445
def _check_malformed(self):
446
conflicts = self.find_conflicts()
447
if len(conflicts) != 0:
448
raise MalformedTransform(conflicts=conflicts)
445
450
def _add_tree_children(self):
446
451
"""Add all the children of all active parents to the known paths.
860
865
return _PreviewTree(self)
867
def commit(self, branch, message, merge_parents=None, strict=False):
868
"""Commit the result of this TreeTransform to a branch.
870
:param branch: The branch to commit to.
871
:param message: The message to attach to the commit.
872
:param merge_parents: Additional parents specified by pending merges.
873
:return: The revision_id of the revision committed.
875
self._check_malformed()
877
unversioned = set(self._new_contents).difference(set(self._new_id))
878
for trans_id in unversioned:
879
if self.final_file_id(trans_id) is None:
880
raise errors.StrictCommitFailed()
882
revno, last_rev_id = branch.last_revision_info()
883
if last_rev_id == _mod_revision.NULL_REVISION:
884
if merge_parents is not None:
885
raise ValueError('Cannot supply merge parents for first'
889
parent_ids = [last_rev_id]
890
if merge_parents is not None:
891
parent_ids.extend(merge_parents)
892
if self._tree.get_revision_id() != last_rev_id:
893
raise ValueError('TreeTransform not based on branch basis: %s' %
894
self._tree.get_revision_id())
895
builder = branch.get_commit_builder(parent_ids)
896
preview = self.get_preview_tree()
897
list(builder.record_iter_changes(preview, last_rev_id,
898
self.iter_changes()))
899
builder.finish_inventory()
900
revision_id = builder.commit(message)
901
branch.set_last_revision_info(revno + 1, revision_id)
862
904
def _text_parent(self, trans_id):
863
905
file_id = self.tree_file_id(trans_id)
1355
1397
yield self.trans_id_tree_path(childpath)
1358
1399
def apply(self, no_conflicts=False, precomputed_delta=None, _mover=None):
1359
1400
"""Apply all changes to the inventory and filesystem.
1370
1411
:param _mover: Supply an alternate FileMover, for testing
1372
1413
if not no_conflicts:
1373
conflicts = self.find_conflicts()
1374
if len(conflicts) != 0:
1375
raise MalformedTransform(conflicts=conflicts)
1414
self._check_malformed()
1376
1415
child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
1378
1417
if precomputed_delta is None:
1679
1718
def __iter__(self):
1680
1719
return iter(self.all_file_ids())
1682
def has_id(self, file_id):
1721
def _has_id(self, file_id, fallback_check):
1683
1722
if file_id in self._transform._r_new_id:
1685
1724
elif file_id in set([self._transform.tree_file_id(trans_id) for
1686
1725
trans_id in self._transform._removed_id]):
1689
return self._transform._tree.has_id(file_id)
1728
return fallback_check(file_id)
1730
def has_id(self, file_id):
1731
return self._has_id(file_id, self._transform._tree.has_id)
1733
def has_or_had_id(self, file_id):
1734
return self._has_id(file_id, self._transform._tree.has_or_had_id)
1691
1736
def _path2trans_id(self, path):
1692
1737
# We must not use None here, because that is a valid value to store.
1962
2007
return old_annotation
1963
2008
if not changed_content:
1964
2009
return old_annotation
2010
# TODO: This is doing something similar to what WT.annotate_iter is
2011
# doing, however it fails slightly because it doesn't know what
2012
# the *other* revision_id is, so it doesn't know how to give the
2013
# other as the origin for some lines, they all get
2014
# 'default_revision'
2015
# It would be nice to be able to use the new Annotator based
2016
# approach, as well.
1965
2017
return annotate.reannotate([old_annotation],
1966
2018
self.get_file(file_id).readlines(),
1967
2019
default_revision)
2033
2085
self.transform = transform
2035
2087
def _determine_path(self, trans_id):
2036
if trans_id == self.transform.root:
2088
if (trans_id == self.transform.root or trans_id == ROOT_PARENT):
2038
2090
name = self.transform.final_name(trans_id)
2039
2091
parent_id = self.transform.final_parent(trans_id)