Mercurial > public > mercurial-scm > hg-stable
diff mercurial/commands.py @ 29953:e7cacb45c4be
formatter: introduce isplain() to replace (the inverse of) __nonzero__() (API)
V2: also remove and replace __nonzero__
author | Mathias De Mar? <mathias.demare@gmail.com> |
---|---|
date | Mon, 29 Aug 2016 17:19:09 +0200 |
parents | 45bf56a89197 |
children | 80fef5251099 |
line wrap: on
line diff
--- a/mercurial/commands.py Tue Aug 30 15:55:07 2016 -0400 +++ b/mercurial/commands.py Mon Aug 29 17:19:09 2016 +0200 @@ -441,12 +441,12 @@ 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 lambda x: fmt(get(x)) + else: def makefunc(get, fmt): return get - else: - def makefunc(get, fmt): - return lambda x: fmt(get(x)) 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 @@ 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 @@ 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 display(fm, fn, ctx, pstates, states): rev = ctx.rev() - if fm: + if fm.isplain(): + formatuser = ui.shortuser + else: formatuser = str - else: - formatuser = ui.shortuser if ui.quiet: datefmt = '%Y-%m-%d' else: @@ -5695,10 +5695,10 @@ pathitems = sorted(ui.paths.iteritems()) fm = ui.formatter('paths', opts) - if fm: + if fm.isplain(): + hidepassword = util.hidepassword + else: hidepassword = str - else: - hidepassword = util.hidepassword if ui.quiet: namefmt = '%s\n' else: