compat: merge with stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 22 May 2017 16:01:59 +0200
changeset 2470 5d015dfd7753
parent 2463 08c552a5eb37 (current diff)
parent 2465 479646a3873a (diff)
child 2474 50113c1ea068
compat: merge with stable Stable has multiple changeset that solve deprecation warning for the future Mercurial 4.3.
--- a/hgext3rd/evolve/__init__.py	Sun May 21 23:58:55 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Mon May 22 16:01:59 2017 +0200
@@ -145,6 +145,7 @@
     commands,
     context,
     copies,
+    dirstate,
     error,
     extensions,
     help,
@@ -221,6 +222,29 @@
 reposetup = eh.final_reposetup
 cmdtable = eh.cmdtable
 
+# pre hg 4.0 compat
+
+if not util.safehasattr(dirstate.dirstate, 'parentchange'):
+    import contextlib
+
+    @contextlib.contextmanager
+    def parentchange(self):
+        '''Context manager for handling dirstate parents.
+
+        If an exception occurs in the scope of the context manager,
+        the incoherent dirstate won't be written when wlock is
+        released.
+        '''
+        self._parentwriters += 1
+        yield
+        # Typically we want the "undo" step of a context manager in a
+        # finally block so it happens even when an exception
+        # occurs. In this case, however, we only want to decrement
+        # parentwriters if the code in the with statement exits
+        # normally, so we don't have a try/finally here on purpose.
+        self._parentwriters -= 1
+    dirstate.dirstate.parentchange = parentchange
+
 #####################################################################
 ### Option configuration                                          ###
 #####################################################################
@@ -866,12 +890,11 @@
                                 '(see hg help resolve)'))
         nodenew = _relocatecommit(repo, orig, commitmsg)
     except error.Abort as exc:
-        repo.dirstate.beginparentchange()
-        repo.setparents(repo['.'].node(), nullid)
-        repo.dirstate.write(tr)
-        # fix up dirstate for copies and renames
-        copies.duplicatecopies(repo, dest.rev(), orig.p1().rev())
-        repo.dirstate.endparentchange()
+        with repo.dirstate.parentchange():
+            repo.setparents(repo['.'].node(), nullid)
+            repo.dirstate.write(tr)
+            # fix up dirstate for copies and renames
+            copies.duplicatecopies(repo, dest.rev(), orig.p1().rev())
 
         class LocalMergeFailure(MergeFailure, exc.__class__):
             pass
@@ -1780,9 +1803,8 @@
     bmupdate(newid)
     repo.ui.status(_('committed as %s\n') % node.short(newid))
     # reroute the working copy parent to the new changeset
-    repo.dirstate.beginparentchange()
-    repo.dirstate.setparents(newid, node.nullid)
-    repo.dirstate.endparentchange()
+    with repo.dirstate.parentchange():
+        repo.dirstate.setparents(newid, node.nullid)
 
 def _solvedivergent(ui, repo, divergent, dryrun=False, confirm=False,
                     progresscb=None):
@@ -1882,9 +1904,8 @@
     assert tr is not None
     try:
         repo.ui.setconfig('ui', 'allowemptycommit', True, 'evolve')
-        repo.dirstate.beginparentchange()
-        repo.dirstate.setparents(divergent.node(), node.nullid)
-        repo.dirstate.endparentchange()
+        with repo.dirstate.parentchange():
+            repo.dirstate.setparents(divergent.node(), node.nullid)
         oldlen = len(repo)
         amend(ui, repo, message='', logfile='')
         if oldlen == len(repo):
@@ -2537,10 +2558,9 @@
         # Move local changes on filtered changeset
         obsolete.createmarkers(repo, [(old, (repo[newid],))])
         phases.retractboundary(repo, tr, oldphase, [newid])
-        repo.dirstate.beginparentchange()
-        repo.dirstate.setparents(newid, node.nullid)
-        _uncommitdirstate(repo, old, match)
-        repo.dirstate.endparentchange()
+        with repo.dirstate.parentchange():
+            repo.dirstate.setparents(newid, node.nullid)
+            _uncommitdirstate(repo, old, match)
         updatebookmarks(newid)
         if not repo[newid].files():
             ui.warn(_("new changeset is empty\n"))
@@ -2773,9 +2793,8 @@
                 obsolete.createmarkers(repo, [(ctx, (repo[new],))])
             phases.retractboundary(repo, tr, ctx.phase(), [new])
             if ctx in repo[None].parents():
-                repo.dirstate.beginparentchange()
-                repo.dirstate.setparents(new, node.nullid)
-                repo.dirstate.endparentchange()
+                with repo.dirstate.parentchange():
+                    repo.dirstate.setparents(new, node.nullid)
         tr.close()
     finally:
         lockmod.release(tr, lock, wlock)
--- a/hgext3rd/evolve/exthelper.py	Sun May 21 23:58:55 2017 +0200
+++ b/hgext3rd/evolve/exthelper.py	Mon May 22 16:01:59 2017 +0200
@@ -3,13 +3,20 @@
 #####################################################################
 
 from mercurial import (
-    cmdutil,
     commands,
     extensions,
+    registrar,
     revset,
     templatekw,
+    util,
 )
 
+if util.safehasattr(registrar, 'command'):
+    command = registrar.command
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    command = cmdutil.command
+
 class exthelper(object):
     """Helper for modular extension setup
 
@@ -30,7 +37,7 @@
         self._functionwrappers = []
         self._duckpunchers = []
         self.cmdtable = {}
-        self.command = cmdutil.command(self.cmdtable)
+        self.command = command(self.cmdtable)
 
     def merge(self, other):
         self._uicallables.extend(other._uicallables)
--- a/hgext3rd/evolve/hack/directaccess.py	Sun May 21 23:58:55 2017 +0200
+++ b/hgext3rd/evolve/hack/directaccess.py	Mon May 22 16:01:59 2017 +0200
@@ -6,9 +6,9 @@
 to xxx.
 """
 from mercurial import extensions
-from mercurial import cmdutil
 from mercurial import repoview
 from mercurial import branchmap
+from mercurial import registrar
 from mercurial import revset
 from mercurial import error
 from mercurial import commands
@@ -17,7 +17,12 @@
 from mercurial.i18n import _
 
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+
+if util.safehasattr(registrar, 'command'):
+    command = registrar.command(cmdtable)
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    command = cmdutil.command(cmdtable)
 
 # By default, all the commands have directaccess with warnings
 # List of commands that have no directaccess and directaccess with no warning
--- a/hgext3rd/evolve/hack/drophack.py	Sun May 21 23:58:55 2017 +0200
+++ b/hgext3rd/evolve/hack/drophack.py	Mon May 22 16:01:59 2017 +0200
@@ -12,7 +12,7 @@
 import contextlib
 
 from mercurial.i18n import _
-from mercurial import cmdutil
+from mercurial import registrar
 from mercurial import repair
 from mercurial import scmutil
 from mercurial import lock as lockmod
@@ -20,7 +20,12 @@
 from mercurial import commands
 
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+
+if util.safehasattr(registrar, 'command'):
+    command = registrar.command(cmdtable)
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    command = cmdutil.command(cmdtable)
 
 
 @contextlib.contextmanager
--- a/hgext3rd/evolve/hack/inhibit.py	Sun May 21 23:58:55 2017 +0200
+++ b/hgext3rd/evolve/hack/inhibit.py	Mon May 22 16:01:59 2017 +0200
@@ -14,20 +14,25 @@
 However as the inhibitor are not fitting in an append only model, this is
 incompatible with sharing mutable history.
 """
-from mercurial import localrepo
-from mercurial import obsolete
-from mercurial import extensions
-from mercurial import cmdutil
+from mercurial import bookmarks
+from mercurial import commands
 from mercurial import error
+from mercurial import extensions
+from mercurial import localrepo
+from mercurial import lock as lockmod
+from mercurial import obsolete
+from mercurial import registrar
 from mercurial import scmutil
-from mercurial import commands
-from mercurial import lock as lockmod
-from mercurial import bookmarks
 from mercurial import util
 from mercurial.i18n import _
 
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+
+if util.safehasattr(registrar, 'command'):
+    command = registrar.command(cmdtable)
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    command = cmdutil.command(cmdtable)
 
 def _inhibitenabled(repo):
     return util.safehasattr(repo, '_obsinhibit')
@@ -176,14 +181,14 @@
         finally:
             tr.release()
 
-def _createmarkers(orig, repo, relations, flag=0, date=None, metadata=None):
+def _createmarkers(orig, repo, relations, *args, **kwargs):
     """wrap markers create to make sure we de-inhibit target nodes"""
     # wrapping transactio to unify the one in each function
     lock = tr = None
     try:
         lock = repo.lock()
         tr = repo.transaction('add-obsolescence-marker')
-        orig(repo, relations, flag, date, metadata)
+        orig(repo, relations, *args, **kwargs)
         precs = (r[0].node() for r in relations)
         _deinhibitmarkers(repo, precs)
         tr.close()
--- a/hgext3rd/evolve/legacy.py	Sun May 21 23:58:55 2017 +0200
+++ b/hgext3rd/evolve/legacy.py	Mon May 22 16:01:59 2017 +0200
@@ -24,12 +24,17 @@
 import sys
 import json
 
-from mercurial import cmdutil
 from mercurial.i18n import _
 from mercurial import lock as lockmod
 from mercurial.node import bin, nullid
+from mercurial import registrar
 from mercurial import util
 
+if util.safehasattr(registrar, 'command'):
+    commandfunc = registrar.command
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    commandfunc = cmdutil.command
 
 #####################################################################
 ### Older format management                                       ###
@@ -75,7 +80,7 @@
     return rels
 
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+command = commandfunc(cmdtable)
 @command('debugconvertobsolete', [], '')
 def cmddebugconvertobsolete(ui, repo):
     """import markers from an .hg/obsolete-relations file"""
--- a/hgext3rd/topic/__init__.py	Sun May 21 23:58:55 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Mon May 22 16:01:59 2017 +0200
@@ -69,6 +69,7 @@
     obsolete,
     patch,
     phases,
+    registrar,
     util,
 )
 
@@ -81,8 +82,13 @@
     discovery,
 )
 
+if util.safehasattr(registrar, 'command'):
+    commandfunc = registrar.command
+else: # compat with hg < 4.3
+    commandfunc = cmdutil.command
+
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+command = commandfunc(cmdtable)
 colortable = {'topic.active': 'green',
               'topic.list.troubledcount': 'red',
               'topic.list.headcount.multiple': 'yellow',