import: adapt to fd1dd79cff20
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 17 Apr 2018 18:30:56 +0200
changeset 3673 9c12b6520a20
parent 3672 f4d5ef9ba074
child 3674 51adc7e6a617
import: adapt to fd1dd79cff20 With the latest state of the code, the patch is passed to "import try one" as parsed.
hgext3rd/evolve/__init__.py
--- a/hgext3rd/evolve/__init__.py	Tue Apr 17 18:10:53 2018 +0200
+++ b/hgext3rd/evolve/__init__.py	Tue Apr 17 18:30:56 2018 +0200
@@ -886,17 +886,21 @@
 @eh.wrapfunction(mercurial.cmdutil, 'tryimportone')
 def tryimportone(orig, ui, repo, hunk, parents, opts, *args, **kwargs):
     expected = {'node': None}
-    oldextract = patch.extract
+    if not util.safehasattr(hunk, 'get'): # hg < 4.6
+        oldextract = patch.extract
 
-    def extract(*args, **kwargs):
-        ret = oldextract(*args, **kwargs)
-        _getnodefrompatch(ret, expected)
-        return ret
-    try:
-        patch.extract = extract
+        def extract(*args, **kwargs):
+            ret = oldextract(*args, **kwargs)
+            _getnodefrompatch(ret, expected)
+            return ret
+        try:
+            patch.extract = extract
+            ret = orig(ui, repo, hunk, parents, opts, *args, **kwargs)
+        finally:
+            patch.extract = oldextract
+    else:
+        _getnodefrompatch(hunk, expected)
         ret = orig(ui, repo, hunk, parents, opts, *args, **kwargs)
-    finally:
-        patch.extract = oldextract
     created = ret[1]
     if (opts['obsolete'] and None not in (created, expected['node'])
         and created != expected['node']):