35
35
DivergedBranches, LockError, UnlistableStore,
36
36
UnlistableBranch, NoSuchFile)
37
37
from bzrlib.textui import show_status
38
from bzrlib.revision import Revision
38
from bzrlib.revision import Revision, is_ancestor, get_intervening_revisions
39
40
from bzrlib.delta import compare_trees
40
41
from bzrlib.tree import EmptyTree, RevisionTree
41
42
from bzrlib.inventory import Inventory
858
def common_ancestor(self, other, self_revno=None, other_revno=None):
860
>>> from bzrlib.commit import commit
861
>>> sb = ScratchBranch(files=['foo', 'foo~'])
862
>>> sb.common_ancestor(sb) == (None, None)
864
>>> commit(sb, "Committing first revision", verbose=False)
865
>>> sb.common_ancestor(sb)[0]
867
>>> clone = sb.clone()
868
>>> commit(sb, "Committing second revision", verbose=False)
869
>>> sb.common_ancestor(sb)[0]
871
>>> sb.common_ancestor(clone)[0]
873
>>> commit(clone, "Committing divergent second revision",
875
>>> sb.common_ancestor(clone)[0]
877
>>> sb.common_ancestor(clone) == clone.common_ancestor(sb)
879
>>> sb.common_ancestor(sb) != clone.common_ancestor(clone)
881
>>> clone2 = sb.clone()
882
>>> sb.common_ancestor(clone2)[0]
884
>>> sb.common_ancestor(clone2, self_revno=1)[0]
886
>>> sb.common_ancestor(clone2, other_revno=1)[0]
889
my_history = self.revision_history()
890
other_history = other.revision_history()
891
if self_revno is None:
892
self_revno = len(my_history)
893
if other_revno is None:
894
other_revno = len(other_history)
895
indices = range(min((self_revno, other_revno)))
898
if my_history[r] == other_history[r]:
899
return r+1, my_history[r]
904
860
"""Return current revision number for this branch.
947
903
Traceback (most recent call last):
948
904
DivergedBranches: These branches have diverged.
950
# FIXME: If the branches have diverged, but the latest
951
# revision in this branch is completely merged into the other,
952
# then we should still be able to pull.
953
906
self_history = self.revision_history()
954
907
self_len = len(self_history)
955
908
other_history = other.revision_history()
970
923
def update_revisions(self, other, stop_revision=None):
971
924
"""Pull in new perfect-fit revisions."""
925
# FIXME: If the branches have diverged, but the latest
926
# revision in this branch is completely merged into the other,
927
# then we should still be able to pull.
972
928
from bzrlib.fetch import greedy_fetch
973
from bzrlib.revision import get_intervening_revisions
974
929
if stop_revision is None:
975
930
stop_revision = other.last_revision()
931
### Should this be checking is_ancestor instead of revision_history?
976
932
if (stop_revision is not None and
977
933
stop_revision in self.revision_history()):
979
935
greedy_fetch(to_branch=self, from_branch=other,
980
936
revision=stop_revision)
981
pullable_revs = self.missing_revisions(
982
other, other.revision_id_to_revno(stop_revision))
984
greedy_fetch(to_branch=self,
986
revision=pullable_revs[-1])
937
pullable_revs = self.pullable_revisions(other, stop_revision)
938
if len(pullable_revs) > 0:
987
939
self.append_revision(*pullable_revs)
941
def pullable_revisions(self, other, stop_revision):
942
other_revno = other.revision_id_to_revno(stop_revision)
944
return self.missing_revisions(other, other_revno)
945
except DivergedBranches, e:
947
pullable_revs = get_intervening_revisions(self.last_revision(),
949
assert self.last_revision() not in pullable_revs
951
except bzrlib.errors.NotAncestor:
952
if is_ancestor(self.last_revision(), stop_revision, self):
989
957
def commit(self, *args, **kw):
990
958
from bzrlib.commit import Commit
991
959
Commit().commit(self, *args, **kw)