import: grab the expected node value on the fly
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 17 Apr 2018 18:10:53 +0200
changeset 3672 f4d5ef9ba074
parent 3671 c82f0d5740b4
child 3673 9c12b6520a20
import: grab the expected node value on the fly We no longer parse the patch beforehand this will reduce inconsistency with newer API.
hgext3rd/evolve/__init__.py
--- a/hgext3rd/evolve/__init__.py	Tue Apr 17 17:58:12 2018 +0200
+++ b/hgext3rd/evolve/__init__.py	Tue Apr 17 18:10:53 2018 +0200
@@ -878,16 +878,22 @@
                     _('mark the old node as obsoleted by '
                       'the created commit')))
 
+def _getnodefrompatch(patch, dest):
+    patchnode = patch.get('nodeid')
+    if patchnode is not None:
+        dest['node'] = node.bin(patchnode)
+
 @eh.wrapfunction(mercurial.cmdutil, 'tryimportone')
 def tryimportone(orig, ui, repo, hunk, parents, opts, *args, **kwargs):
     expected = {'node': None}
-    extracted = patch.extract(ui, hunk)
-    expectednode = extracted.get('nodeid')
-    if expectednode is not None:
-        expected['node'] = node.bin(expectednode)
     oldextract = patch.extract
+
+    def extract(*args, **kwargs):
+        ret = oldextract(*args, **kwargs)
+        _getnodefrompatch(ret, expected)
+        return ret
     try:
-        patch.extract = lambda ui, hunk: extracted
+        patch.extract = extract
         ret = orig(ui, repo, hunk, parents, opts, *args, **kwargs)
     finally:
         patch.extract = oldextract