[PATCH 1 of 1] rebase: make sure the newancestor is used during the whole update

Christian Boos cboos at neuf.fr
Mon Nov 9 16:52:33 CST 2009


# HG changeset patch
# User Christian Boos <cboos at bct-technology.com>
# Date 1257794149 -3600
# Node ID ba79a2096c6e34128a70a717c87141e55e4311d9
# Parent  4ce13d7c6b8855e028dd284e03d416400fcb5225
rebase: make sure the newancestor is used during the whole update
(issue1561)

Before this change, newancestor was used only once as a replacement
for ancestor.ancestor, but merge.update calls ancestor.ancestor
several times, so it ends up with the "wrong" ancestor (the real
ancestor, but we want the parent of the rebased changeset for all but
the first rebased changeset).

Added a new test case for this: test-rebase-newancestor.

Also, in one scenario in test-rebase-collapse, there was a spurious
conflict caused by the same issue, so that test case was fixed by
removing the now unneeded conflict resolution and the output was
adapted accordingly.

diff -r 4ce13d7c6b88 -r ba79a2096c6e hgext/rebase.py
--- a/hgext/rebase.py	Sun Nov 08 18:50:39 2009 +0100
+++ b/hgext/rebase.py	Mon Nov 09 20:15:49 2009 +0100
@@ -27,17 +27,19 @@
     oldancestor = ancestor.ancestor
 
     def newancestor(a, b, pfunc):
-        ancestor.ancestor = oldancestor
         if b == rev:
             return repo[rev].parents()[0].rev()
-        return ancestor.ancestor(a, b, pfunc)
+        return oldancestor(a, b, pfunc)
 
     if not first:
         ancestor.ancestor = newancestor
     else:
         repo.ui.debug("first revision, do not change ancestor\n")
-    stats = merge.update(repo, rev, True, True, False)
-    return stats
+    try:
+        stats = merge.update(repo, rev, True, True, False)
+        return stats
+    finally:
+        ancestor.ancestor = oldancestor
 
 def rebase(ui, repo, **opts):
     """move changeset (and descendants) to a different branch
diff -r 4ce13d7c6b88 -r ba79a2096c6e tests/test-rebase-collapse
--- a/tests/test-rebase-collapse	Sun Nov 08 18:50:39 2009 +0100
+++ b/tests/test-rebase-collapse	Mon Nov 09 20:15:49 2009 +0100
@@ -130,12 +130,7 @@
 
 echo
 echo '% Rebase and collapse - E onto I'
-hg rebase -s 4 --collapse 
-
-echo '% Fix conflict and continue'
-echo 'Resolved merge' > E
-hg resolve -m E
-hg rebase -c 2>&1 | sed 's/\(saving bundle to \).*/\1/'
+hg rebase -s 4 --collapse 2>&1 | sed 's/\(saving bundle to \).*/\1/'
 
 hg glog  --template '{rev}: {desc}\n'
 
diff -r 4ce13d7c6b88 -r ba79a2096c6e tests/test-rebase-collapse.out
--- a/tests/test-rebase-collapse.out	Sun Nov 08 18:50:39 2009 +0100
+++ b/tests/test-rebase-collapse.out	Mon Nov 09 20:15:49 2009 +0100
@@ -145,10 +145,6 @@
 
 % Rebase and collapse - E onto I
 merging E
-warning: conflicts during merge.
-merging E failed!
-abort: fix unresolved conflicts with hg resolve then run hg rebase --continue
-% Fix conflict and continue
 saving bundle to 
 adding branch
 adding changesets
@@ -179,7 +175,7 @@
 G
 I
 Cat E:
-Resolved merge
+F
 
 @  5: F
 |
diff -r 4ce13d7c6b88 -r ba79a2096c6e tests/test-rebase-newancestor
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-rebase-newancestor	Mon Nov 09 20:15:49 2009 +0100
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "graphlog=" >> $HGRCPATH
+echo "rebase=" >> $HGRCPATH
+
+rm -rf repo
+hg init repo
+cd repo
+
+echo A > a
+echo >> a
+hg commit -AmA -u test -d '0 0'
+
+echo B > a
+echo >> a
+hg commit -mB -u test -d '1 0'
+
+echo C > a
+echo >> a
+hg commit -mC -u test -d '2 0'
+
+hg up -C 0
+echo D >> a
+hg commit -AmAD -u test -d '3 0'
+
+hg glog --template '{rev}:{desc} {node|short}\n'
+hg rebase -q -s 1 -d 3 2>&1 | grep -v 'saving bundle'
+hg glog --template '{rev}:{desc} {node|short}\n'
+
+exit 0
diff -r 4ce13d7c6b88 -r ba79a2096c6e tests/test-rebase-newancestor.out
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-rebase-newancestor.out	Mon Nov 09 20:15:49 2009 +0100
@@ -0,0 +1,19 @@
+adding a
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+created new head
+@  3:AD 1d4e82ed3c2a
+|
+| o  2:C 7e1afe9214b2
+| |
+| o  1:B 0a6620c3c26a
+|/
+o  0:A 1e635d440a73
+
+@  3:C 0c5887756284
+|
+o  2:B 4f208f4a1507
+|
+o  1:AD 1d4e82ed3c2a
+|
+o  0:A 1e635d440a73
+


More information about the Mercurial-devel mailing list