##// END OF EJS Templates
perf: define formatter locally for Mercurial earlier than 2.2...
FUJIWARA Katsunori -
r30147:423bf74d default
parent child Browse files
Show More
@@ -138,8 +138,42 b' def gettimer(ui, opts=None):'
138 # redirect all to stderr
138 # redirect all to stderr
139 ui = ui.copy()
139 ui = ui.copy()
140 ui.fout = ui.ferr
140 ui.fout = ui.ferr
141
141 # get a formatter
142 # get a formatter
142 fm = ui.formatter('perf', opts)
143 uiformatter = getattr(ui, 'formatter', None)
144 if uiformatter:
145 fm = uiformatter('perf', opts)
146 else:
147 # for "historical portability":
148 # define formatter locally, because ui.formatter has been
149 # available since 2.2 (or ae5f92e154d3)
150 from mercurial import node
151 class defaultformatter(object):
152 """Minimized composition of baseformatter and plainformatter
153 """
154 def __init__(self, ui, topic, opts):
155 self._ui = ui
156 if ui.debugflag:
157 self.hexfunc = node.hex
158 else:
159 self.hexfunc = node.short
160 def __nonzero__(self):
161 return False
162 def startitem(self):
163 pass
164 def data(self, **data):
165 pass
166 def write(self, fields, deftext, *fielddata, **opts):
167 self._ui.write(deftext % fielddata, **opts)
168 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
169 if cond:
170 self._ui.write(deftext % fielddata, **opts)
171 def plain(self, text, **opts):
172 self._ui.write(text, **opts)
173 def end(self):
174 pass
175 fm = defaultformatter(ui, 'perf', opts)
176
143 # stub function, runs code only once instead of in a loop
177 # stub function, runs code only once instead of in a loop
144 # experimental config: perf.stub
178 # experimental config: perf.stub
145 if ui.configbool("perf", "stub"):
179 if ui.configbool("perf", "stub"):
General Comments 0
You need to be logged in to leave comments. Login now