[PATCH 2 of 2] rebase: store/restore arguments correctly

Stefano Tortarolo stefano.tortarolo at gmail.com
Sun Mar 29 14:49:28 CDT 2009


# HG changeset patch
# User Stefano Tortarolo <stefano.tortarolo at gmail.com>
# Date 1238330629 -7200
# Node ID 6a9fa7c1ca63c2c2f62bfe31e149cea630c6b9a1
# Parent  9f2bf6432e4cb49825158995a36125e7c4efb47a
rebase: store/restore arguments correctly

Keep and keepbranches were lost after an interruption

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -64,12 +64,8 @@
         abortf = opts.get('abort')
         collapsef = opts.get('collapse', False)
         extrafn = opts.get('extrafn')
-        if opts.get('keepbranches', None):
-            if extrafn:
-                raise error.ParseError(
-                    'rebase', _('cannot use both keepbranches and extrafn'))
-            def extrafn(ctx, extra):
-                extra['branch'] = ctx.branch()
+        keepf = opts.get('keep', False)
+        keepbranchesf = opts.get('keepbranches', False)
 
         if contf or abortf:
             if contf and abortf:
@@ -83,7 +79,8 @@
                 raise error.ParseError('rebase',
                     _('abort and continue do not allow specifying revisions'))
 
-            originalwd, target, state, collapsef, external = restorestatus(repo)
+            (originalwd, target, state, collapsef, keepf,
+                                keepbranchesf, external) = restorestatus(repo)
             if abortf:
                 abort(repo, originalwd, target, state)
                 return
@@ -99,14 +96,21 @@
                 repo.ui.status(_('nothing to rebase\n'))
                 return
 
+        if keepbranchesf:
+            if extrafn:
+                raise error.ParseError(
+                    'rebase', _('cannot use both keepbranches and extrafn'))
+            def extrafn(ctx, extra):
+                extra['branch'] = ctx.branch()
+
         # Rebase
         targetancestors = list(repo.changelog.ancestors(target))
         targetancestors.append(target)
 
         for rev in util.sort(state):
             if state[rev] == -1:
-                storestatus(repo, originalwd, target, state, collapsef,
-                                                                external)
+                storestatus(repo, originalwd, target, state, collapsef, keepf,
+                                                    keepbranchesf, external)
                 rebasenode(repo, rev, target, state, skipped, targetancestors,
                                                        collapsef, extrafn)
         ui.note(_('rebase merging completed\n'))
@@ -120,7 +124,7 @@
         if 'qtip' in repo.tags():
             updatemq(repo, state, skipped, **opts)
 
-        if not opts.get('keep'):
+        if not keepf:
             # Remove no more useful revisions
             if (util.set(repo.changelog.descendants(min(state)))
                                                     - util.set(state.keys())):
@@ -273,13 +277,16 @@
                             git=opts.get('git', False),rev=[str(state[rev])])
         repo.mq.save_dirty()
 
-def storestatus(repo, originalwd, target, state, collapse, external):
+def storestatus(repo, originalwd, target, state, collapse, keep, keepbranches,
+                                                                external):
     'Store the current status to allow recovery'
     f = repo.opener("rebasestate", "w")
     f.write(repo[originalwd].hex() + '\n')
     f.write(repo[target].hex() + '\n')
     f.write(repo[external].hex() + '\n')
     f.write('%d\n' % int(collapse))
+    f.write('%d\n' % int(keep))
+    f.write('%d\n' % int(keepbranches))
     for d, v in state.iteritems():
         oldrev = repo[d].hex()
         newrev = repo[v].hex()
@@ -309,11 +316,15 @@
                 external = repo[l].rev()
             elif i == 3:
                 collapse = bool(int(l))
+            elif i == 4:
+                keep = bool(int(l))
+            elif i == 5:
+                keepbranches = bool(int(l))
             else:
                 oldrev, newrev = l.split(':')
                 state[repo[oldrev].rev()] = repo[newrev].rev()
         repo.ui.debug(_('rebase status resumed\n'))
-        return originalwd, target, state, collapse, external
+        return originalwd, target, state, collapse, keep, keepbranches, external
     except IOError, err:
         if err.errno != errno.ENOENT:
             raise
diff --git a/tests/test-rebase-check-restore b/tests/test-rebase-check-restore
new file mode 100755
--- /dev/null
+++ b/tests/test-rebase-check-restore
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "graphlog=" >> $HGRCPATH
+echo "rebase=" >> $HGRCPATH
+
+BASE=`pwd`
+
+addcommit () {
+    echo $1 > $1
+    hg add $1
+    hg commit -d "${2} 0" -u test -m $1
+}
+
+commit () {
+    hg commit -d "${2} 0" -u test -m $1
+}
+
+createrepo () {
+    cd $BASE
+    rm -rf a
+    hg init a
+    cd a
+    addcommit "A" 0
+    addcommit "B" 1
+    echo "C" >> A
+    commit "C" 2
+
+    hg update -C 0
+    echo "D" >> A
+    commit "D" 3
+    addcommit "E" 4
+
+    hg update -C 0
+    hg branch 'notdefault'
+    echo "F" >> A
+    commit "F" 5
+}
+
+echo
+echo "% - Rebasing B onto E - check keep"
+createrepo > /dev/null 2>&1
+hg glog  --template '{rev}:{desc}:{branches}\n'
+hg rebase -s 1 -d 4 --keep 2>&1 | sed 's/\(saving bundle to \).*/\1/'
+
+echo
+echo "% - Solve the conflict and go on"
+echo 'conflict solved' > A
+rm A.orig
+hg resolve -m A
+hg rebase --continue 2>&1 | sed 's/\(saving bundle to \).*/\1/'
+hg glog  --template '{rev}:{desc}:{branches}\n'
+
+echo
+echo "% - Rebase F onto E - check keepbranches"
+createrepo > /dev/null 2>&1
+hg glog  --template '{rev}:{desc}:{branches}\n'
+hg rebase -s 5 -d 4 --keepbranches 2>&1 | sed 's/\(saving bundle to \).*/\1/'
+
+echo
+echo "% - Solve the conflict and go on"
+echo 'conflict solved' > A
+rm A.orig
+hg resolve -m A
+hg rebase --continue 2>&1 | sed 's/\(saving bundle to \).*/\1/'
+hg glog  --template '{rev}:{desc}:{branches}\n'
+
+exit 0
diff --git a/tests/test-rebase-check-restore.out b/tests/test-rebase-check-restore.out
new file mode 100644
--- /dev/null
+++ b/tests/test-rebase-check-restore.out
@@ -0,0 +1,76 @@
+
+% - Rebasing B onto E - check keep
+@  5:F:notdefault
+|
+| o  4:E:
+| |
+| o  3:D:
+|/
+| o  2:C:
+| |
+| o  1:B:
+|/
+o  0:A:
+
+merging A
+warning: conflicts during merge.
+merging A failed!
+abort: fix unresolved conflicts with hg resolve then run hg rebase --continue
+
+% - Solve the conflict and go on
+rebase completed
+@  7:C:
+|
+o  6:B:
+|
+| o  5:F:notdefault
+| |
+o |  4:E:
+| |
+o |  3:D:
+|/
+| o  2:C:
+| |
+| o  1:B:
+|/
+o  0:A:
+
+
+% - Rebase F onto E - check keepbranches
+@  5:F:notdefault
+|
+| o  4:E:
+| |
+| o  3:D:
+|/
+| o  2:C:
+| |
+| o  1:B:
+|/
+o  0:A:
+
+merging A
+warning: conflicts during merge.
+merging A failed!
+abort: fix unresolved conflicts with hg resolve then run hg rebase --continue
+
+% - Solve the conflict and go on
+saving bundle to 
+adding branch
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 1 changes to 1 files
+rebase completed
+@  5:F:notdefault
+|
+o  4:E:
+|
+o  3:D:
+|
+| o  2:C:
+| |
+| o  1:B:
+|/
+o  0:A:
+


More information about the Mercurial-devel mailing list