changeset 34327:4647e0a8d3d7

scmutil: extract helper functions that returns human-readable change id We do "'%d:%s' % (ctx...)" at several places, so let's formalize it. A low- level function, formatrevnode(ui, rev, node), is extracted so we can pass a manifest rev/node pair. Note that hex() for manifest output can be replaced with hexfunc() because it is printed only when debugflag is set. i18n/de.po is updated so test-log.t passes with no error.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 24 Sep 2017 12:43:57 +0900
parents e60c601953d7
children dd28b1f55eb8
files i18n/de.po mercurial/cmdutil.py mercurial/scmutil.py mercurial/templatekw.py
diffstat 4 files changed, 30 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/i18n/de.po	Sat Sep 02 23:13:54 2017 +0900
+++ b/i18n/de.po	Sun Sep 24 12:43:57 2017 +0900
@@ -9746,8 +9746,8 @@
 
 #. i18n: column positioning for "hg log"
 #, python-format
-msgid "changeset:   %d:%s\n"
-msgstr "Änderung:        %d:%s\n"
+msgid "changeset:   %s\n"
+msgstr "Änderung:        %s\n"
 
 #. i18n: column positioning for "hg log"
 #, python-format
@@ -9771,8 +9771,8 @@
 
 #. i18n: column positioning for "hg log"
 #, python-format
-msgid "parent:      %d:%s\n"
-msgstr "Vorgänger:       %d:%s\n"
+msgid "parent:      %s\n"
+msgstr "Vorgänger:       %s\n"
 
 #. i18n: column positioning for "hg log"
 #, python-format
--- a/mercurial/cmdutil.py	Sat Sep 02 23:13:54 2017 +0900
+++ b/mercurial/cmdutil.py	Sun Sep 24 12:43:57 2017 +0900
@@ -1623,22 +1623,16 @@
         '''show a single changeset or file revision'''
         changenode = ctx.node()
         rev = ctx.rev()
-        if self.ui.debugflag:
-            hexfunc = hex
-        else:
-            hexfunc = short
-        # as of now, wctx.node() and wctx.rev() return None, but we want to
-        # show the same values as {node} and {rev} templatekw
-        revnode = (scmutil.intrev(ctx), hexfunc(scmutil.binnode(ctx)))
 
         if self.ui.quiet:
-            self.ui.write("%d:%s\n" % revnode, label='log.node')
+            self.ui.write("%s\n" % scmutil.formatchangeid(ctx),
+                          label='log.node')
             return
 
         date = util.datestr(ctx.date())
 
         # i18n: column positioning for "hg log"
-        self.ui.write(_("changeset:   %d:%s\n") % revnode,
+        self.ui.write(_("changeset:   %s\n") % scmutil.formatchangeid(ctx),
                       label=_changesetlabels(ctx))
 
         # branches are shown first before any other names due to backwards
@@ -1667,16 +1661,15 @@
         for pctx in scmutil.meaningfulparents(self.repo, ctx):
             label = 'log.parent changeset.%s' % pctx.phasestr()
             # i18n: column positioning for "hg log"
-            self.ui.write(_("parent:      %d:%s\n")
-                          % (pctx.rev(), hexfunc(pctx.node())),
+            self.ui.write(_("parent:      %s\n") % scmutil.formatchangeid(pctx),
                           label=label)
 
         if self.ui.debugflag and rev is not None:
             mnode = ctx.manifestnode()
+            mrev = self.repo.manifestlog._revlog.rev(mnode)
             # i18n: column positioning for "hg log"
-            self.ui.write(_("manifest:    %d:%s\n") %
-                          (self.repo.manifestlog._revlog.rev(mnode),
-                           hex(mnode)),
+            self.ui.write(_("manifest:    %s\n")
+                          % scmutil.formatrevnode(self.ui, mrev, mnode),
                           label='ui.debug log.manifest')
         # i18n: column positioning for "hg log"
         self.ui.write(_("user:        %s\n") % ctx.user(),
--- a/mercurial/scmutil.py	Sat Sep 02 23:13:54 2017 +0900
+++ b/mercurial/scmutil.py	Sun Sep 24 12:43:57 2017 +0900
@@ -19,6 +19,7 @@
 from .node import (
     hex,
     nullid,
+    short,
     wdirid,
     wdirrev,
 )
@@ -405,6 +406,20 @@
         return wdirrev
     return rev
 
+def formatchangeid(ctx):
+    """Format changectx as '{rev}:{node|formatnode}', which is the default
+    template provided by cmdutil.changeset_templater"""
+    repo = ctx.repo()
+    return formatrevnode(repo.ui, intrev(ctx), binnode(ctx))
+
+def formatrevnode(ui, rev, node):
+    """Format given revision and node depending on the current verbosity"""
+    if ui.debugflag:
+        hexfunc = hex
+    else:
+        hexfunc = short
+    return '%d:%s' % (rev, hexfunc(node))
+
 def revsingle(repo, revspec, default='.', localalias=None):
     if not revspec and revspec != 0:
         return repo[default]
--- a/mercurial/templatekw.py	Sat Sep 02 23:13:54 2017 +0900
+++ b/mercurial/templatekw.py	Sun Sep 24 12:43:57 2017 +0900
@@ -11,7 +11,6 @@
 from .node import (
     hex,
     nullid,
-    short,
 )
 
 from . import (
@@ -163,16 +162,6 @@
     if endname in templ:
         yield templ(endname, **strmapping)
 
-def _formatrevnode(ctx):
-    """Format changeset as '{rev}:{node|formatnode}', which is the default
-    template provided by cmdutil.changeset_templater"""
-    repo = ctx.repo()
-    if repo.ui.debugflag:
-        hexfunc = hex
-    else:
-        hexfunc = short
-    return '%d:%s' % (scmutil.intrev(ctx), hexfunc(scmutil.binnode(ctx)))
-
 def getfiles(repo, ctx, revcache):
     if 'files' not in revcache:
         revcache['files'] = repo.status(ctx.p1(), ctx)[:3]
@@ -640,7 +629,7 @@
 
     return _hybrid(None, predecessors,
                    lambda x: {'ctx': repo[x], 'revcache': {}},
-                   lambda d: _formatrevnode(d['ctx']))
+                   lambda d: scmutil.formatchangeid(d['ctx']))
 
 @templatekeyword("successorssets")
 def showsuccessorssets(repo, ctx, **args):
@@ -658,7 +647,7 @@
     data = []
     for ss in ssets:
         h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}},
-                    lambda d: _formatrevnode(d['ctx']))
+                    lambda d: scmutil.formatchangeid(d['ctx']))
         data.append(h)
 
     # Format the successorssets
@@ -698,7 +687,7 @@
         successors = [hex(n) for n in successors]
         successors = _hybrid(None, successors,
                              lambda x: {'ctx': repo[x], 'revcache': {}},
-                             lambda d: _formatrevnode(d['ctx']))
+                             lambda d: scmutil.formatchangeid(d['ctx']))
 
         # Format markers
         finalmarkers = []
@@ -759,7 +748,7 @@
                for p in pctxs]
     f = _showlist('parent', parents, args)
     return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}},
-                   lambda d: _formatrevnode(d['ctx']))
+                   lambda d: scmutil.formatchangeid(d['ctx']))
 
 @templatekeyword('phase')
 def showphase(repo, ctx, templ, **args):