changeset 38363: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 8221df643176
children 57dc72b56b6c
files mercurial/commands.py
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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))