comparison mercurial/commands.py @ 38357:31ed65f9c5ad

annotate: reverse mapping between option name and field name This makes the next patch slightly simpler.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 03 May 2018 12:10:47 +0900
parents b8f45fc27370
children 57dc72b56b6c
comparison
equal deleted inserted replaced
38356:8221df643176 38357:31ed65f9c5ad
333 else: 333 else:
334 hexfn = rootfm.hexfunc 334 hexfn = rootfm.hexfunc
335 formatrev = formathex = pycompat.bytestr 335 formatrev = formathex = pycompat.bytestr
336 336
337 opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser), 337 opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser),
338 ('number', ' ', lambda x: x.fctx.rev(), formatrev), 338 ('rev', ' ', lambda x: x.fctx.rev(), formatrev),
339 ('changeset', ' ', lambda x: hexfn(x.fctx.node()), formathex), 339 ('node', ' ', lambda x: hexfn(x.fctx.node()), formathex),
340 ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)), 340 ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)),
341 ('file', ' ', lambda x: x.fctx.path(), pycompat.bytestr), 341 ('file', ' ', lambda x: x.fctx.path(), pycompat.bytestr),
342 ('line_number', ':', lambda x: x.lineno, pycompat.bytestr), 342 ('line_number', ':', lambda x: x.lineno, pycompat.bytestr),
343 ] 343 ]
344 fieldnamemap = {'number': 'rev', 'changeset': 'node'} 344 opnamemap = {'rev': 'number', 'node': 'changeset'}
345 345
346 if (not opts.get('user') and not opts.get('changeset') 346 if (not opts.get('user') and not opts.get('changeset')
347 and not opts.get('date') and not opts.get('file')): 347 and not opts.get('date') and not opts.get('file')):
348 opts['number'] = True 348 opts['number'] = True
349 349
357 def makefunc(get, fmt): 357 def makefunc(get, fmt):
358 return lambda x: fmt(get(x)) 358 return lambda x: fmt(get(x))
359 else: 359 else:
360 def makefunc(get, fmt): 360 def makefunc(get, fmt):
361 return get 361 return get
362 funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap 362 funcmap = [(makefunc(get, fmt), sep) for fn, sep, get, fmt in opmap
363 if opts.get(op)] 363 if opts.get(opnamemap.get(fn, fn))]
364 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column 364 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
365 fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap 365 fields = ' '.join(fn for fn, sep, get, fmt in opmap
366 if opts.get(op)) 366 if opts.get(opnamemap.get(fn, fn)))
367 367
368 def bad(x, y): 368 def bad(x, y):
369 raise error.Abort("%s: %s" % (x, y)) 369 raise error.Abort("%s: %s" % (x, y))
370 370
371 m = scmutil.match(ctx, pats, opts, badfn=bad) 371 m = scmutil.match(ctx, pats, opts, badfn=bad)