Commit 65c4ad3f authored by Mathias De Maré's avatar Mathias De Maré
Browse files

formatter: introduce isplain() to replace (the inverse of) __nonzero__() (API)

V2: also remove and replace __nonzero__
parent e40343ce9c4c
......@@ -441,12 +441,12 @@ def annotate(ui, repo, *pats, **opts):
if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
raise error.Abort(_('at least one of -n/-c is required for -l'))
if fm:
if fm.isplain():
def makefunc(get, fmt):
return get
return lambda x: fmt(get(x))
else:
def makefunc(get, fmt):
return lambda x: fmt(get(x))
return get
funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap
if opts.get(op)]
funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
......@@ -476,12 +476,12 @@ def annotate(ui, repo, *pats, **opts):
for f, sep in funcmap:
l = [f(n) for n, dummy in lines]
if fm:
formats.append(['%s' for x in l])
else:
if fm.isplain():
sizes = [encoding.colwidth(x) for x in l]
ml = max(sizes)
formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes])
else:
formats.append(['%s' for x in l])
pieces.append(l)
for f, p, l in zip(zip(*formats), zip(*pieces), lines):
......@@ -1185,7 +1185,7 @@ def bookmark(ui, repo, *names, **opts):
fm = ui.formatter('bookmarks', opts)
hexfn = fm.hexfunc
marks = repo._bookmarks
if len(marks) == 0 and not fm:
if len(marks) == 0 and fm.isplain():
ui.status(_("no bookmarks set\n"))
for bmark, n in sorted(marks.iteritems()):
active = repo._activebookmark
......@@ -4442,10 +4442,10 @@ def grep(ui, repo, pattern, *pats, **opts):
def display(fm, fn, ctx, pstates, states):
rev = ctx.rev()
if fm:
formatuser = str
else:
if fm.isplain():
formatuser = ui.shortuser
else:
formatuser = str
if ui.quiet:
datefmt = '%Y-%m-%d'
else:
......@@ -5695,10 +5695,10 @@ def paths(ui, repo, search=None, **opts):
pathitems = sorted(ui.paths.iteritems())
fm = ui.formatter('paths', opts)
if fm:
hidepassword = str
else:
if fm.isplain():
hidepassword = util.hidepassword
else:
hidepassword = str
if ui.quiet:
namefmt = '%s\n'
else:
......
......@@ -57,10 +57,6 @@ class baseformatter(object):
def __exit__(self, exctype, excvalue, traceback):
if exctype is None:
self.end()
def __nonzero__(self):
'''return False if we're not doing real templating so we can
skip extra work'''
return True
def _showitem(self):
'''show a formatted item once all data is collected'''
pass
......@@ -96,6 +92,9 @@ class baseformatter(object):
def plain(self, text, **opts):
'''show raw text for non-templated mode'''
pass
def isplain(self):
'''check for plain formatter usage'''
return False
def nested(self, field):
'''sub formatter to store nested data in the specified field'''
self._item[field] = data = []
......@@ -142,8 +141,6 @@ class plainformatter(baseformatter):
self.hexfunc = hex
else:
self.hexfunc = short
def __nonzero__(self):
return False
def startitem(self):
pass
def data(self, **data):
......@@ -156,6 +153,8 @@ class plainformatter(baseformatter):
self._ui.write(deftext % fielddata, **opts)
def plain(self, text, **opts):
self._ui.write(text, **opts)
def isplain(self):
return True
def nested(self, field):
# nested data will be directly written to ui
return self
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment