changeset 3673:9c12b6520a20

import: adapt to fd1dd79cff20 With the latest state of the code, the patch is passed to "import try one" as parsed.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 17 Apr 2018 18:30:56 +0200
parents f4d5ef9ba074
children 51adc7e6a617
files hgext3rd/evolve/__init__.py
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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']):