diff extensions/kwarchive.py @ 349:0d889720613d

FIX: Mercurial 5 does not accept "root" and "cwd" for match.exact and friends: make a compatibility shim
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 06 Jan 2020 19:26:50 +0100
parents 41a8e3db181c
children 84f20a80f247
line wrap: on
line diff
--- a/extensions/kwarchive.py	Mon Jan 06 18:55:06 2020 +0100
+++ b/extensions/kwarchive.py	Mon Jan 06 19:26:50 2020 +0100
@@ -607,14 +607,14 @@
             matcher = match.match(ctx.repo().root, b'', patterns=patterns,
                                   include=include, exclude=exclude)
         else:
-            matcher = match.never(ctx.repo().root, b'')
+            matcher = _matchmod_never(ctx.repo().root, b'')
 
         #
         # An empty patterns_rcs does not mean that match_rcs is always
         # true.
         #
         if not patterns_rcs:
-            matcher_rcs = match.never(ctx.repo().root, b'')
+            matcher_rcs = _matchmod_never(ctx.repo().root, b'')
         else:
             matcher_rcs = match.match(ctx.repo().root, b'',
                                       patterns=patterns_rcs,
@@ -624,7 +624,7 @@
         # true.
         #
         if not patterns_rst:
-            matcher_rst = match.never(ctx.repo().root, b'')
+            matcher_rst = _matchmod_never(ctx.repo().root, b'')
         else:
             matcher_rst = match.match(ctx.repo().root, b'',
                                       patterns=patterns_rst,
@@ -835,8 +835,10 @@
 if hasattr(inspect, "getfullargspec"):
     # PY3
     _has_makefilename_ctx = "ctx" in inspect.getfullargspec(cmdutil.makefilename).args
+    _has_matchmod_with_root = "root" in inspect.getfullargspec(match.exact).args
 else:
     _has_makefilename_ctx = "ctx" in inspect.getargspec(cmdutil.makefilename).args
+    _has_matchmod_with_root = "root" in inspect.getargspec(match.exact).args
 
 if _has_makefilename_ctx:
 
@@ -855,6 +857,17 @@
     def makefileobj_compat(ctx, pat, **props):
         return cmdutil.makefileobj(ctx.repo(), pat, ctx.node(), **props)
 
+if _has_matchmod_with_root:
+
+    # Mercurial < 5
+
+    _matchmod_never = match.never
+
+else:
+
+    def _matchmod_never(root, cwd, badfn=None):
+        return match.never(badfn=badfn)
+
 
 if context_mapping_api: