Mercurial > hg
changeset 7952:b214066b7e1d
rebase: store/restore arguments correctly
Keep and keepbranches were lost after an interruption
author | Stefano Tortarolo <stefano.tortarolo@gmail.com> |
---|---|
date | Sun, 29 Mar 2009 14:43:49 +0200 |
parents | 4d9e8efb7326 |
children | 8c6f823efcc9 |
files | hgext/rebase.py tests/test-rebase-check-restore tests/test-rebase-check-restore.out |
diffstat | 3 files changed, 167 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/rebase.py Sun Mar 29 14:47:59 2009 +0200 +++ b/hgext/rebase.py Sun Mar 29 14:43:49 2009 +0200 @@ -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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-rebase-check-restore Sun Mar 29 14:43:49 2009 +0200 @@ -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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-rebase-check-restore.out Sun Mar 29 14:43:49 2009 +0200 @@ -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: +