diff extensions/kwarchive.py @ 103:d6e594644778

Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
author Franz Glasner <hg@dom66.de>
date Thu, 02 Aug 2018 16:57:44 +0200
parents ec4392ae8c92
children 65789e3e8e3d
line wrap: on
line diff
--- a/extensions/kwarchive.py	Thu Aug 02 14:57:14 2018 +0200
+++ b/extensions/kwarchive.py	Thu Aug 02 16:57:44 2018 +0200
@@ -38,6 +38,7 @@
 
 import os
 import itertools
+import inspect
 
 from mercurial.i18n import _
 from mercurial import (archival, commands, config, cmdutil, error, match,
@@ -143,7 +144,7 @@
     if not ctx:
         raise error.Abort(_('no working directory: please specify a revision'))
     node = ctx.node()
-    dest = cmdutil.makefilename(repo, dest, node)
+    dest = makefilename_compat(ctx, dest)
     if os.path.realpath(dest) == repo.root:
         raise error.Abort(_('repository root cannot be destination'))
 
@@ -153,11 +154,11 @@
     if dest == '-':
         if kind == 'files':
             raise error.Abort(_('cannot archive plain files to stdout'))
-        dest = cmdutil.makefileobj(repo, dest)
+        dest = makefileobj_compat(ctx, dest)
         if not prefix:
             prefix = os.path.basename(repo.root) + '-%h'
 
-    prefix = cmdutil.makefilename(repo, prefix, node)
+    prefix = makefilename_compat(ctx, prefix)
     matchfn = scmutil.match(ctx, [], opts)
 
     #
@@ -242,7 +243,7 @@
         raise error.Abort(_('no working directory: please specify a revision'))
     node = ctx.node()
 
-    prefix = cmdutil.makefilename(repo, "", node)
+    prefix = makefilename_compat(ctx, "")
 
     keywords = make_node_keywords(
         ui, repo, ctx, prefix,
@@ -451,3 +452,21 @@
     if not pf in ("full", "nopwd", "short", "last"):
         raise error.Abort(_("path filter must be any of `full', `nopwd' or `short'"))
     return pf
+
+
+if "ctx" in inspect.getargspec(cmdutil.makefilename).args:
+
+    # Mercurial >= 4.6
+
+    makefilename_compat = cmdutil.makefilename
+    makefileobj_compat = cmdutil.makefileobj
+
+else:
+
+    # Mercurial < 4.6
+
+    def makefilename_compat(ctx, pat, **props):
+        return cmdutil.makefilename(ctx.repo(), pat, ctx.node(), **props)
+
+    def makefileobj_compat(ctx, pat, **props):
+        return cmdutil.makefileobj(ctx.repo(), pat, ctx.node(), **props)