compat: use updateresult API if available
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 30 Mar 2018 20:26:54 +0200
changeset 3616 f6d629514607
parent 3615 1ff7ff53d81f
child 3617 a0e322641810
compat: use updateresult API if available The status return is no longer a tuple, we access attribute instead.
hgext3rd/evolve/cmdrewrite.py
hgext3rd/evolve/compat.py
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/cmdrewrite.py	Fri Mar 30 20:13:06 2018 +0200
+++ b/hgext3rd/evolve/cmdrewrite.py	Fri Mar 30 20:26:54 2018 +0200
@@ -1200,7 +1200,7 @@
                        origctx.description().split("\n", 1)[0]))
             stats = merge.graft(repo, origctx, origctx.p1(), ['local',
                                                               'destination'])
-            if stats[3]:
+            if compat.hasconflict(stats):
                 grabstate.addopts({'orignode': origctx.node(),
                                    'oldpctx': pctx.node()})
                 grabstate.save()
--- a/hgext3rd/evolve/compat.py	Fri Mar 30 20:13:06 2018 +0200
+++ b/hgext3rd/evolve/compat.py	Fri Mar 30 20:26:54 2018 +0200
@@ -293,3 +293,14 @@
                 hgweb_mod.perms[name] = permission
                 wireproto.commands[name] = (func, args)
         return decorator
+
+# mercurial <= 4.5 do not have the updateresult object
+try:
+    from mercurial.merge import updateresult
+except (ImportError, AttributeError):
+    updateresult = None
+
+def hasconflict(upres):
+    if updateresult is None:
+        return bool(upres[-1])
+    return bool(upres.unresolvedcount)
--- a/hgext3rd/evolve/evolvecmd.py	Fri Mar 30 20:13:06 2018 +0200
+++ b/hgext3rd/evolve/evolvecmd.py	Fri Mar 30 20:26:54 2018 +0200
@@ -382,10 +382,9 @@
                          ancestor=base.node(),
                          mergeancestor=True)
     hg._showstats(repo, stats)
-    if stats[3]:
+    if compat.hasconflict(stats):
         repo.ui.status(_("use 'hg resolve' to retry unresolved file merges "
                          "or 'hg update -C .' to abort\n"))
-    if stats[3] > 0:
         raise error.Abort('merge conflict between several amendments '
                           '(this is not automated yet)',
                           hint="""/!\ You can try:
@@ -504,7 +503,7 @@
     assert tr is not None
     try:
         r = _evolvemerge(repo, orig, dest, pctx, keepbranch)
-        if r[-1]: # some conflict
+        if compat.hasconflict(r): # some conflict
             raise error.Abort(_('unresolved merge conflicts '
                                 '(see hg help resolve)'))
         nodenew = _relocatecommit(repo, orig, commitmsg)