# HG changeset patch # User Pierre-Yves David # Date 1316448231 -7200 # Node ID 64fe5a4f877e1776f1e397728dab6fa5b296c62a # Parent 246b8fefd0a522c096455577bbe25fb74a836d30 [evolution] first workign draft of a relocate function The relocate function is a lighter rebase. diff -r 246b8fefd0a5 -r 64fe5a4f877e hgext/evolution.py --- a/hgext/evolution.py Mon Sep 19 03:18:08 2011 +0200 +++ b/hgext/evolution.py Mon Sep 19 18:03:51 2011 +0200 @@ -17,6 +17,7 @@ from mercurial import commands from mercurial import bookmarks from mercurial import context +from mercurial import util from mercurial.i18n import _ from mercurial.commands import walkopts, commitopts, commitopts2, logopts @@ -107,6 +108,29 @@ return newid +def relocate(repo, rev, dest): + """rewrite on dest""" + try: + rebase = extensions.find('rebase') + # dummy state to trick rebase node + assert repo[rev].p2().rev() == node.nullrev, 'no support yet' + rebase.updatedirstate(repo, rev, repo[dest].node(), + repo[rev].p2().node()) + rebase.rebasenode(repo, rev, dest, {node.nullrev: node.nullrev}) + nodenew = rebase.concludenode(repo, rev, dest, node.nullid) + nodesrc = repo.changelog.node(rev) + repo.addobsolete(nodenew, nodesrc) + oldbookmarks = repo.nodebookmarks(nodesrc) + for book in oldbookmarks: + repo._bookmarks[book] = nodenew + if oldbookmarks: + bookmarks.write(repo) + except util.Abort: + # Invalidate the previous setparents + repo.dirstate.invalidate() + raise + + ### new command ############################# @@ -126,7 +150,26 @@ assert obs.obsolete() newer = obsolete.newerversion(repo, obs.node()) target = newer[-1] - repo.ui.status('hg rebase --dest %s --source %s --detach \n' % (repo[target].rev(), next)) + repo.ui.status('hg relocate --rev %s %s\n' % (next, repo[target].rev())) + +@command('^relocate', + [ + ('r', 'rev', '.', + _('revision to relocate')), + ], + '') +def cmdrelocate(ui, repo, dest, rev='.'): + """relocate a changeset""" + wlock = repo.wlock() + try: + src = repo[rev] + dest = repo[dest] + if src == src.ancestor(dest): + raise util.Abort(_('source is ancestor of destination')) + relocate(repo, src.rev(), dest.rev()) + return 0 + finally: + wlock.release() diff -r 246b8fefd0a5 -r 64fe5a4f877e tests/test-evolution.t --- a/tests/test-evolution.t Mon Sep 19 03:18:08 2011 +0200 +++ b/tests/test-evolution.t Mon Sep 19 18:03:51 2011 +0200 @@ -113,7 +113,7 @@ To begin with, we just do the changes that will be the initial version of the changeset:: $ echo One >file-from-A - $ sed -i '' -e s/One/Eins/ main-file-1 + $ sed -i'' -e s/One/Eins/ main-file-1 $ hg add file-from-A So this is what we would like our changeset to be:: @@ -147,7 +147,7 @@ Let's do this again for the second changeset:: $ echo Two >file-from-B - $ sed -i '' -e s/Two/Zwie/ main-file-1 + $ sed -i'' -e s/Two/Zwie/ main-file-1 $ hg add file-from-B Before committing, however, we need to switch to a new bookmark for the second @@ -174,7 +174,7 @@ Fixing this is very easy. Just change:: - $ sed -i '' -e s/Zwie/Zwei/ main-file-1 + $ sed -i'' -e s/Zwie/Zwei/ main-file-1 and **amend**:: @@ -193,7 +193,7 @@ 0 : base - test $ hg up feature-A -q - $ sed -i '' -e s/Eins/Un/ main-file-1 + $ sed -i'' -e s/Eins/Un/ main-file-1 $ hg amend --note 'french looks better' $ hg log @@ -202,11 +202,10 @@ 1 : a nifty feature - test 0 : base - test $ hg evolve - hg rebase --dest 6 --source 4 --detach + hg relocate --rev 4 6 $ hg up feature-B -q #prevent feature-A bookmark to move grml - $ hg rebase --dest 6 --source 4 --detach + $ hg relocate -r 4 6 --traceback merging main-file-1 - $ hg bookmark -fr 7 feature-B # XXX there is a bug out-there because we force --keep imp $ hg log 7 feature-B: another feature - test 6 feature-A: a nifty feature - test