diff mercurial/formatter.py @ 22701:cb28d2b3db0b

formatter: add general way to switch hex/short functions This seems a bit awkward, but it can avoid duplicates in annotate, tags, branches and bookmarks. I guess fm.hexfunc can eventually be removed (or redesigned) when it gets template backend.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 03 Oct 2014 22:20:02 +0900
parents 06c8b58647b9
children 0a714a1f7d5c
line wrap: on
line diff
--- a/mercurial/formatter.py	Fri Oct 03 11:37:56 2014 -0500
+++ b/mercurial/formatter.py	Fri Oct 03 22:20:02 2014 +0900
@@ -6,6 +6,7 @@
 # GNU General Public License version 2 or any later version.
 
 import cPickle
+from node import hex, short
 from i18n import _
 import encoding, util
 
@@ -16,6 +17,8 @@
         self._style = opts.get("style")
         self._template = opts.get("template")
         self._item = None
+        # function to convert node to string suitable for this output
+        self.hexfunc = hex
     def __nonzero__(self):
         '''return False if we're not doing real templating so we can
         skip extra work'''
@@ -51,6 +54,10 @@
     '''the default text output scheme'''
     def __init__(self, ui, topic, opts):
         baseformatter.__init__(self, ui, topic, opts)
+        if ui.debugflag:
+            self.hexfunc = hex
+        else:
+            self.hexfunc = short
     def __nonzero__(self):
         return False
     def startitem(self):