Patchwork [3,of,5] grep: build list of columns without "grep." label prefix

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 25, 2016, 3:24 p.m.
Message ID <9a00e4df27db537a1f9d.1472138696@mimosa>
Download mbox | patch
Permalink /patch/16413/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 25, 2016, 3:24 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1471497809 -32400
#      Thu Aug 18 14:23:29 2016 +0900
# Node ID 9a00e4df27db537a1f9d0c2259312fd174e8a278
# Parent  8867e120a95b1f3d89c334de323c518b8be16985
grep: build list of columns without "grep." label prefix

Prepares for formatter support. We need field names without "grep.".

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4397,20 +4397,20 @@  def grep(ui, repo, pattern, *pats, **opt
         else:
             iter = [('', l) for l in states]
         for change, l in iter:
-            cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')]
+            cols = [(fn, 'filename'), (str(rev), 'rev')]
 
             if opts.get('line_number'):
-                cols.append((str(l.linenum), 'grep.linenumber'))
+                cols.append((str(l.linenum), 'linenumber'))
             if opts.get('all'):
-                cols.append((change, 'grep.change'))
+                cols.append((change, 'change'))
             if opts.get('user'):
-                cols.append((ui.shortuser(ctx.user()), 'grep.user'))
+                cols.append((ui.shortuser(ctx.user()), 'user'))
             if opts.get('date'):
-                cols.append((datefunc(ctx.date()), 'grep.date'))
-            for col, label in cols[:-1]:
-                ui.write(col, label=label)
+                cols.append((datefunc(ctx.date()), 'date'))
+            for col, field in cols[:-1]:
+                ui.write(col, label='grep.%s' % field)
                 ui.write(sep, label='grep.sep')
-            ui.write(cols[-1][0], label=cols[-1][1])
+            ui.write(cols[-1][0], label='grep.%s' % cols[-1][1])
             if not opts.get('files_with_matches'):
                 ui.write(sep, label='grep.sep')
                 if not opts.get('text') and binary():