grep: move writing of path outside of column loop
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 30 Jan 2019 16:59:31 -0800
changeset 41526 16454d938299
parent 41525 72a9aacff645
child 41527 718e9b444d97
grep: move writing of path outside of column loop This will make the next patch simpler. Differential Revision: https://phab.mercurial-scm.org/D5776
mercurial/commands.py
--- a/mercurial/commands.py	Tue Jan 29 12:01:13 2019 -0800
+++ b/mercurial/commands.py	Wed Jan 30 16:59:31 2019 -0800
@@ -2867,7 +2867,7 @@
             except error.WdirUnsupported:
                 return ctx[fn].isbinary()
 
-        fieldnamemap = {'filename': 'path', 'linenumber': 'lineno'}
+        fieldnamemap = {'linenumber': 'lineno'}
         if diff:
             iter = difflinestates(pstates, states)
         else:
@@ -2876,9 +2876,9 @@
             fm.startitem()
             fm.context(ctx=ctx)
             fm.data(node=fm.hexfunc(scmutil.binnode(ctx)))
+            fm.write('path', '%s', fn, label='grep.filename')
 
             cols = [
-                ('filename', '%s', fn, True),
                 ('rev', '%d', rev, not plaingrep),
                 ('linenumber', '%d', l.linenum, opts.get('line_number')),
             ]
@@ -2889,13 +2889,11 @@
                 ('date', '%s', fm.formatdate(ctx.date(), datefmt),
                  opts.get('date')),
             ])
-            lastcol = next(
-                name for name, fmt, data, cond in reversed(cols) if cond)
             for name, fmt, data, cond in cols:
+                if cond:
+                    fm.plain(sep, label='grep.sep')
                 field = fieldnamemap.get(name, name)
                 fm.condwrite(cond, field, fmt, data, label='grep.%s' % name)
-                if cond and name != lastcol:
-                    fm.plain(sep, label='grep.sep')
             if not opts.get('files_with_matches'):
                 fm.plain(sep, label='grep.sep')
                 if not opts.get('text') and binary():