diff mercurial/scmutil.py @ 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 9e4f82bc2b0b
children 255c761a52db
line wrap: on
line diff
--- 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]