Patchwork [4,of,5] cmdutil: rewrite makefilename() to use ctx methods

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

Comments

Yuya Nishihara - Feb. 14, 2018, 2:25 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1427985427 -32400
#      Thu Apr 02 23:37:07 2015 +0900
# Node ID cd93d1cd0887842c12c3b8f7a3741be3ef338105
# Parent  f45bd2b2fa1ec9b4cd41c00ab5d2d2f1872461ef
cmdutil: rewrite makefilename() to use ctx methods

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -893,16 +893,14 @@  def getcommiteditor(edit=False, finishde
 
 def makefilename(ctx, pat, desc=None,
                   total=None, seqno=None, revwidth=None, pathname=None):
-    repo = ctx.repo()
-    node = ctx.node()
     expander = {
-        'H': lambda: hex(node),
-        'R': lambda: '%d' % repo.changelog.rev(node),
-        'h': lambda: short(node),
+        'H': lambda: ctx.hex(),
+        'R': lambda: '%d' % ctx.rev(),
+        'h': lambda: short(ctx.node()),
         'm': lambda: re.sub('[^\w]', '_', desc or ''),
-        'r': lambda: ('%d' % repo.changelog.rev(node)).zfill(revwidth or 0),
+        'r': lambda: ('%d' % ctx.rev()).zfill(revwidth or 0),
         '%': lambda: '%',
-        'b': lambda: os.path.basename(repo.root),
+        'b': lambda: os.path.basename(ctx.repo().root),
         }
 
     try: