Patchwork [1,of,5] cmdutil: make node parameter of makefileobj() mandatory (API)

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 14, 2018, 2:25 p.m.
Message ID <87127b53c63a948b2446.1518618305@mimosa>
Download mbox | patch
Permalink /patch/27926/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 14, 2018, 2:25 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1427984522 -32400
#      Thu Apr 02 23:22:02 2015 +0900
# Node ID 87127b53c63a948b24461862e6d7a02862ecdaa2
# Parent  39b3aab6231e8fa070eadd8e165b9960f8c46076
cmdutil: make node parameter of makefileobj() mandatory (API)

(repo, node) pair will be replaced with ctx, so makefilename() can be easily
ported to templater.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -893,23 +893,17 @@  def getcommiteditor(edit=False, finishde
 
 def makefilename(repo, pat, node, desc=None,
                   total=None, seqno=None, revwidth=None, pathname=None):
-    node_expander = {
+    expander = {
         'H': lambda: hex(node),
         'R': lambda: '%d' % repo.changelog.rev(node),
         'h': lambda: short(node),
-        'm': lambda: re.sub('[^\w]', '_', desc or '')
-        }
-    expander = {
+        'm': lambda: re.sub('[^\w]', '_', desc or ''),
+        'r': lambda: ('%d' % repo.changelog.rev(node)).zfill(revwidth or 0),
         '%': lambda: '%',
         'b': lambda: os.path.basename(repo.root),
         }
 
     try:
-        if node:
-            expander.update(node_expander)
-        if node:
-            expander['r'] = (lambda:
-                    ('%d' % repo.changelog.rev(node)).zfill(revwidth or 0))
         if total is not None:
             expander['N'] = lambda: '%d' % total
         if seqno is not None:
@@ -960,7 +954,7 @@  class _unclosablefile(object):
     def __exit__(self, exc_type, exc_value, exc_tb):
         pass
 
-def makefileobj(repo, pat, node=None, desc=None, total=None,
+def makefileobj(repo, pat, node, desc=None, total=None,
                 seqno=None, revwidth=None, mode='wb', modemap=None,
                 pathname=None):
 
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -486,7 +486,7 @@  def archive(ui, repo, dest, **opts):
     if dest == '-':
         if kind == 'files':
             raise error.Abort(_('cannot archive plain files to stdout'))
-        dest = cmdutil.makefileobj(repo, dest)
+        dest = cmdutil.makefileobj(repo, dest, node)
         if not prefix:
             prefix = os.path.basename(repo.root) + '-%h'