Mercurial > evolve
changeset 930:cac35bef8aee stable
import: --obsolete flag for automatic obsolescence marker creation
A new `--obsolete` flag is added to import. When present, the new node will be
marked as a successors of the one specified in the `Node` field of the imported
patch. No marker are created when revision have the node expected in the patch.
This improves email based work flow where implicit rebase are likely to happen
and extra information are lost, changing the hash.
This new behavior requires a flags, otherwise the `hg export x | hg import -`
idiom would change, turning the source obsolete.
(Changing from `hg graft x` to `hg rebase --dest . --rev x`)
This change only takes effect when using Mercurial 3.0 and above
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Fri, 09 May 2014 03:06:36 -0700 |
parents | 306f67906a6c |
children | 32915143d448 |
files | README hgext/evolve.py tests/test-import.t |
diffstat | 3 files changed, 125 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/README Sun May 11 01:17:02 2014 -0700 +++ b/README Fri May 09 03:06:36 2014 -0700 @@ -51,6 +51,7 @@ - fix a bug where evolve were creating changeset with 2 parents on windows (fix issues #16, #35 and #42) +- adds a --obsolete flag to import (requieres Mercurial 3.0) 3.3.1 -- 2014-04-23
--- a/hgext/evolve.py Sun May 11 01:17:02 2014 -0700 +++ b/hgext/evolve.py Fri May 09 03:06:36 2014 -0700 @@ -52,6 +52,7 @@ from mercurial import merge from mercurial import node from mercurial import phases +from mercurial import patch from mercurial import revset from mercurial import scmutil from mercurial import templatekw @@ -823,6 +824,37 @@ _('record the specified user in metadata'), _('USER')), ] +if getattr(mercurial.cmdutil, 'tryimportone', None) is not None: + # hg 3.0 and greate + @eh.uisetup + def _installimportobsolete(ui): + entry = cmdutil.findcmd('import', commands.table)[1] + entry[1].append(('', 'obsolete', False, + _('mark the old node as obsoleted by' + 'the created commit'))) + + @eh.wrapfunction(mercurial.cmdutil, 'tryimportone') + def tryimportone(orig, ui, repo, hunk, parents, opts, *args, **kwargs): + extracted = patch.extract(ui, hunk) + expected = extracted[5] + oldextract = patch.extract + try: + patch.extract = lambda ui, hunk: extracted + ret = orig(ui, repo, hunk, parents, opts, *args, **kwargs) + finally: + patch.extract = oldextract + created = ret[1] + if opts['obsolete'] and created is not None and created != expected: + tr = repo.transaction('import-obs') + try: + metadata = {'user': ui.username()} + repo.obsstore.create(tr, node.bin(expected), (created,), + metadata=metadata) + tr.close() + finally: + tr.release() + return ret + @command('^evolve|stabilize|solve', [('n', 'dry-run', False, 'do not perform actions, just print what would be done'),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-import.t Fri May 09 03:06:36 2014 -0700 @@ -0,0 +1,92 @@ + +This feature requires mercurial 3.0 +(and the `only(` revset is 3.0 specific) + + $ (hg help revset | grep ' only(') || exit 80 + +Test creation of obsolescence marker by path import + + $ hg init auto-obsolete + $ cd auto-obsolete + $ echo '[extensions]' >> $HGRCPATH + $ echo 'rebase=' >> $HGRCPATH + $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext/evolve.py" >> $HGRCPATH + $ echo A > a + $ hg commit -Am A + adding a + $ echo B > b + $ hg commit -Am B + adding b + $ hg up '.^' + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ echo C > c + $ hg commit -Am C + adding c + created new head + $ hg log -G + @ changeset: 2:eb8dd0f31b51 + | tag: tip + | parent: 0:f2bbf19cf96d + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: C + | + | o changeset: 1:95b760afef3c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: B + | + o changeset: 0:f2bbf19cf96d + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: A + + +(actual test) + + $ hg export 'desc(B)' | hg import - --obsolete + applying patch from stdin + $ hg log -G + @ changeset: 3:00c49133f17e + | tag: tip + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: B + | + o changeset: 2:eb8dd0f31b51 + | parent: 0:f2bbf19cf96d + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: C + | + o changeset: 0:f2bbf19cf96d + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: A + + $ hg debugobsolete + 95b760afef3c234ffb3f9fd391edcb36e60921a4 00c49133f17e5e5a52b6ef1b6d516c0e90b56d8a 0 {'date': '* *', 'user': 'test'} (glob) + + $ hg rollback + repository tip rolled back to revision 2 (undo import) + working directory now based on revision 2 + $ hg log -G + @ changeset: 2:eb8dd0f31b51 + | tag: tip + | parent: 0:f2bbf19cf96d + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: C + | + | o changeset: 1:95b760afef3c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: B + | + o changeset: 0:f2bbf19cf96d + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: A + + $ hg debugobsolete +