# HG changeset patch
# User Jordi Gutiérrez Hermoso <jord...@octave.org>
# Date 1550262244 18000
#      Fri Feb 15 15:24:04 2019 -0500
# Node ID b5464436e4acdd1893ee86e5aa03f1d69ce4c4c5
# Parent  a22321f2b1ee18ea09a70fee9e524d2f0298aaaa
grep: give different labels to + and - symbols

I find it more useful to give different colours to plus and minus, but
it's difficult to do so if the default output uses the same label for
both. The following augments the names of columns with some extra
labels, akin to the diff.inserted and diff.deleted labels for the diff
command.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2889,7 +2889,10 @@ def grep(ui, repo, pattern, *pats, **opt
                 ('linenumber', '%d', l.linenum, opts.get('line_number')),
             ]
             if diff:
-                cols.append(('change', '%s', change, True))
+                cols.extend([
+                    ('inserted change' if change == '+' else 'deleted change',
+                     '%s', change, True)
+                ])
             cols.extend([
                 ('user', '%s', formatuser(ctx.user()), opts.get('user')),
                 ('date', '%s', fm.formatdate(ctx.date(), datefmt),
@@ -2899,7 +2902,8 @@ def grep(ui, repo, pattern, *pats, **opt
                 if cond:
                     fm.plain(sep, label='grep.sep')
                 field = fieldnamemap.get(name, name)
-                fm.condwrite(cond, field, fmt, data, label='grep.%s' % name)
+                label = " ".join('grep.%s' % n for n in name.split())
+                fm.condwrite(cond, field, fmt, data, label=label)
             if not opts.get('files_with_matches'):
                 fm.plain(sep, label='grep.sep')
                 if not opts.get('text') and binary():
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to