[PATCH 1 of 3] grep: give different labels to + and - symbols

Jordi GutiƩrrez Hermoso jordigh at octave.org
Fri Feb 15 15:49:35 EST 2019


# HG changeset patch
# User Jordi GutiƩrrez Hermoso <jordigh at 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():


More information about the Mercurial-devel mailing list