# HG changeset patch # User Yuya Nishihara # Date 1525317047 -32400 # Node ID 31ed65f9c5adf1e00c7d794585eed0fed334c33d # Parent 8221df64317649aace611bd37ac0aed644aa6130 annotate: reverse mapping between option name and field name This makes the next patch slightly simpler. diff -r 8221df643176 -r 31ed65f9c5ad mercurial/commands.py --- a/mercurial/commands.py Thu May 03 11:56:49 2018 +0900 +++ b/mercurial/commands.py Thu May 03 12:10:47 2018 +0900 @@ -335,13 +335,13 @@ formatrev = formathex = pycompat.bytestr opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser), - ('number', ' ', lambda x: x.fctx.rev(), formatrev), - ('changeset', ' ', lambda x: hexfn(x.fctx.node()), formathex), + ('rev', ' ', lambda x: x.fctx.rev(), formatrev), + ('node', ' ', lambda x: hexfn(x.fctx.node()), formathex), ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)), ('file', ' ', lambda x: x.fctx.path(), pycompat.bytestr), ('line_number', ':', lambda x: x.lineno, pycompat.bytestr), ] - fieldnamemap = {'number': 'rev', 'changeset': 'node'} + opnamemap = {'rev': 'number', 'node': 'changeset'} if (not opts.get('user') and not opts.get('changeset') and not opts.get('date') and not opts.get('file')): @@ -359,11 +359,11 @@ else: def makefunc(get, fmt): return get - funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap - if opts.get(op)] + funcmap = [(makefunc(get, fmt), sep) for fn, sep, get, fmt in opmap + if opts.get(opnamemap.get(fn, fn))] funcmap[0] = (funcmap[0][0], '') # no separator in front of first column - fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap - if opts.get(op)) + fields = ' '.join(fn for fn, sep, get, fmt in opmap + if opts.get(opnamemap.get(fn, fn))) def bad(x, y): raise error.Abort("%s: %s" % (x, y))