diff hgext/evolve.py @ 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 154510dc4318
children 32915143d448
line wrap: on
line diff
--- 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'),