Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
22700:41421bd9c42e | 22701:cb28d2b3db0b |
---|---|
4 # | 4 # |
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 import cPickle | 8 import cPickle |
9 from node import hex, short | |
9 from i18n import _ | 10 from i18n import _ |
10 import encoding, util | 11 import encoding, util |
11 | 12 |
12 class baseformatter(object): | 13 class baseformatter(object): |
13 def __init__(self, ui, topic, opts): | 14 def __init__(self, ui, topic, opts): |
14 self._ui = ui | 15 self._ui = ui |
15 self._topic = topic | 16 self._topic = topic |
16 self._style = opts.get("style") | 17 self._style = opts.get("style") |
17 self._template = opts.get("template") | 18 self._template = opts.get("template") |
18 self._item = None | 19 self._item = None |
20 # function to convert node to string suitable for this output | |
21 self.hexfunc = hex | |
19 def __nonzero__(self): | 22 def __nonzero__(self): |
20 '''return False if we're not doing real templating so we can | 23 '''return False if we're not doing real templating so we can |
21 skip extra work''' | 24 skip extra work''' |
22 return True | 25 return True |
23 def _showitem(self): | 26 def _showitem(self): |
49 | 52 |
50 class plainformatter(baseformatter): | 53 class plainformatter(baseformatter): |
51 '''the default text output scheme''' | 54 '''the default text output scheme''' |
52 def __init__(self, ui, topic, opts): | 55 def __init__(self, ui, topic, opts): |
53 baseformatter.__init__(self, ui, topic, opts) | 56 baseformatter.__init__(self, ui, topic, opts) |
57 if ui.debugflag: | |
58 self.hexfunc = hex | |
59 else: | |
60 self.hexfunc = short | |
54 def __nonzero__(self): | 61 def __nonzero__(self): |
55 return False | 62 return False |
56 def startitem(self): | 63 def startitem(self): |
57 pass | 64 pass |
58 def data(self, **data): | 65 def data(self, **data): |