comparison 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
comparison
equal deleted inserted replaced
29952:e40343ce9c4c 29953:e7cacb45c4be
439 439
440 linenumber = opts.get('line_number') is not None 440 linenumber = opts.get('line_number') is not None
441 if linenumber and (not opts.get('changeset')) and (not opts.get('number')): 441 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
442 raise error.Abort(_('at least one of -n/-c is required for -l')) 442 raise error.Abort(_('at least one of -n/-c is required for -l'))
443 443
444 if fm: 444 if fm.isplain():
445 def makefunc(get, fmt):
446 return lambda x: fmt(get(x))
447 else:
445 def makefunc(get, fmt): 448 def makefunc(get, fmt):
446 return get 449 return get
447 else:
448 def makefunc(get, fmt):
449 return lambda x: fmt(get(x))
450 funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap 450 funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap
451 if opts.get(op)] 451 if opts.get(op)]
452 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column 452 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
453 fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap 453 fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap
454 if opts.get(op)) 454 if opts.get(op))
474 formats = [] 474 formats = []
475 pieces = [] 475 pieces = []
476 476
477 for f, sep in funcmap: 477 for f, sep in funcmap:
478 l = [f(n) for n, dummy in lines] 478 l = [f(n) for n, dummy in lines]
479 if fm: 479 if fm.isplain():
480 formats.append(['%s' for x in l])
481 else:
482 sizes = [encoding.colwidth(x) for x in l] 480 sizes = [encoding.colwidth(x) for x in l]
483 ml = max(sizes) 481 ml = max(sizes)
484 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) 482 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes])
483 else:
484 formats.append(['%s' for x in l])
485 pieces.append(l) 485 pieces.append(l)
486 486
487 for f, p, l in zip(zip(*formats), zip(*pieces), lines): 487 for f, p, l in zip(zip(*formats), zip(*pieces), lines):
488 fm.startitem() 488 fm.startitem()
489 fm.write(fields, "".join(f), *p) 489 fm.write(fields, "".join(f), *p)
1183 lockmod.release(tr, lock, wlock) 1183 lockmod.release(tr, lock, wlock)
1184 else: # show bookmarks 1184 else: # show bookmarks
1185 fm = ui.formatter('bookmarks', opts) 1185 fm = ui.formatter('bookmarks', opts)
1186 hexfn = fm.hexfunc 1186 hexfn = fm.hexfunc
1187 marks = repo._bookmarks 1187 marks = repo._bookmarks
1188 if len(marks) == 0 and not fm: 1188 if len(marks) == 0 and fm.isplain():
1189 ui.status(_("no bookmarks set\n")) 1189 ui.status(_("no bookmarks set\n"))
1190 for bmark, n in sorted(marks.iteritems()): 1190 for bmark, n in sorted(marks.iteritems()):
1191 active = repo._activebookmark 1191 active = repo._activebookmark
1192 if bmark == active: 1192 if bmark == active:
1193 prefix, label = '*', activebookmarklabel 1193 prefix, label = '*', activebookmarklabel
4440 for i in xrange(blo, bhi): 4440 for i in xrange(blo, bhi):
4441 yield ('+', b[i]) 4441 yield ('+', b[i])
4442 4442
4443 def display(fm, fn, ctx, pstates, states): 4443 def display(fm, fn, ctx, pstates, states):
4444 rev = ctx.rev() 4444 rev = ctx.rev()
4445 if fm: 4445 if fm.isplain():
4446 formatuser = ui.shortuser
4447 else:
4446 formatuser = str 4448 formatuser = str
4447 else:
4448 formatuser = ui.shortuser
4449 if ui.quiet: 4449 if ui.quiet:
4450 datefmt = '%Y-%m-%d' 4450 datefmt = '%Y-%m-%d'
4451 else: 4451 else:
4452 datefmt = '%a %b %d %H:%M:%S %Y %1%2' 4452 datefmt = '%a %b %d %H:%M:%S %Y %1%2'
4453 found = False 4453 found = False
5693 if name == search] 5693 if name == search]
5694 else: 5694 else:
5695 pathitems = sorted(ui.paths.iteritems()) 5695 pathitems = sorted(ui.paths.iteritems())
5696 5696
5697 fm = ui.formatter('paths', opts) 5697 fm = ui.formatter('paths', opts)
5698 if fm: 5698 if fm.isplain():
5699 hidepassword = util.hidepassword
5700 else:
5699 hidepassword = str 5701 hidepassword = str
5700 else:
5701 hidepassword = util.hidepassword
5702 if ui.quiet: 5702 if ui.quiet:
5703 namefmt = '%s\n' 5703 namefmt = '%s\n'
5704 else: 5704 else:
5705 namefmt = '%s = ' 5705 namefmt = '%s = '
5706 showsubopts = not search and not ui.quiet 5706 showsubopts = not search and not ui.quiet