changeset 5707:581203686284 stable

compat: make topics compatible across change to cmdutil.commitstatus() `cmdutil.commitstatus()` was changed in https://phab.mercurial-scm.org/D9257 so it has a new `tip` argument. This patch adds compatibility with that. It was harder than I expected because the callers all pass the arguments as positional, so we can't look for `opts` or `tip` in the `kwargs`. I instead extracted much of the override to a helper. I think the result is okay.
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 16 Nov 2020 13:08:08 -0800
parents 59b2be90e9fd
children fdc540a9b94b
files hgext3rd/topic/compat.py hgext3rd/topic/topicmap.py
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/compat.py	Thu Oct 29 09:19:37 2020 -0700
+++ b/hgext3rd/topic/compat.py	Mon Nov 16 13:08:08 2020 -0800
@@ -8,6 +8,8 @@
 from __future__ import absolute_import
 
 from mercurial import (
+    cmdutil,
+    extensions,
     pycompat,
     registrar,
     util,
@@ -46,3 +48,14 @@
     return set().union(
         *[roots for roots in repo._phasecache.phaseroots[1:] if roots]
     )
+
+def overridecommitstatus(overridefn):
+    if r'tip' in cmdutil.commitstatus.__code__.co_varnames:
+        extensions.wrapfunction(cmdutil, 'commitstatus', overridefn)
+    else:
+        # hg <= 5.6 (976b26bdd0d8)
+        def _override(orig, repo, node, branch, bheads=None, opts=None):
+            def _orig(repo, node, branch, bheads=None, tip=None, opts=None):
+                return orig(repo, node, branch, bheads=bheads, opts=opts)
+            return overridefn(_orig, repo, node, branch, bheads=bheads, tip=None, opts=opts)
+        extensions.wrapfunction(cmdutil, 'commitstatus', _override)
--- a/hgext3rd/topic/topicmap.py	Thu Oct 29 09:19:37 2020 -0700
+++ b/hgext3rd/topic/topicmap.py	Mon Nov 16 13:08:08 2020 -0800
@@ -6,7 +6,6 @@
 from mercurial import (
     branchmap,
     changegroup,
-    cmdutil,
     extensions,
     repoview,
     util,
@@ -89,20 +88,20 @@
     _setuptopicfilter(ui)
     _wrapbmcache(ui)
     extensions.wrapfunction(changegroup.cg1unpacker, 'apply', cgapply)
-    extensions.wrapfunction(cmdutil, 'commitstatus', commitstatus)
+    compat.overridecommitstatus(commitstatus)
 
 def cgapply(orig, self, repo, *args, **kwargs):
     """make sure a topicmap is used when applying a changegroup"""
     other = repo.filtered(topicfilter(repo.filtername))
     return orig(self, other, *args, **kwargs)
 
-def commitstatus(orig, repo, node, branch, bheads=None, opts=None):
+def commitstatus(orig, repo, node, branch, bheads=None, tip=None, opts=None):
     # wrap commit status use the topic branch heads
     ctx = repo[node]
     if ctx.topic() and ctx.branch() == branch:
         bheads = repo.branchheads(b"%s:%s" % (branch, ctx.topic()))
 
-    ret = orig(repo, node, branch, bheads=bheads, opts=opts)
+    ret = orig(repo, node, branch, bheads=bheads, tip=tip, opts=opts)
 
     # logic copy-pasted from cmdutil.commitstatus()
     if opts is None: