diff mercurial/commands.py @ 38427:7fbb5d76c555

grep: add --diff flag Adds a diff flag, which works exactly same as all, in fact since --all searches diffs, there diff is a better name for it. The all flag is still here for backward compatibility reasons. Some major tests for all has been picked and added for diff. Differential Revision: https://phab.mercurial-scm.org/D3763
author Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
date Sun, 17 Jun 2018 15:52:08 +0530
parents 2ceea1554d1e
children 5d9b765dbe15
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Jun 20 09:27:30 2018 -0700
+++ b/mercurial/commands.py	Sun Jun 17 15:52:08 2018 +0530
@@ -2391,6 +2391,8 @@
 @command('grep',
     [('0', 'print0', None, _('end fields with NUL')),
     ('', 'all', None, _('print all revisions that match')),
+    ('', 'diff', None, _('print all revisions when the term was introduced '
+                         'or removed')),
     ('a', 'text', None, _('treat all files as text')),
     ('f', 'follow', None,
      _('follow changeset history,'
@@ -2419,7 +2421,7 @@
     file in which it finds a match. To get it to print every revision
     that contains a change in match status ("-" for a match that becomes
     a non-match, or "+" for a non-match that becomes a match), use the
-    --all flag.
+    --diff/--all flag.
 
     PATTERN can be any Python (roughly Perl-compatible) regular
     expression.
@@ -2431,6 +2433,7 @@
     Returns 0 if a match is found, 1 otherwise.
     """
     opts = pycompat.byteskwargs(opts)
+    diff = opts.get('all') or opts.get('diff')
     reflags = re.M
     if opts.get('ignore_case'):
         reflags |= re.I
@@ -2527,7 +2530,7 @@
                 return ctx[fn].isbinary()
 
         fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'}
-        if opts.get('all'):
+        if diff:
             iter = difflinestates(pstates, states)
         else:
             iter = [('', l) for l in states]
@@ -2540,7 +2543,7 @@
                 ('rev', rev, True),
                 ('linenumber', l.linenum, opts.get('line_number')),
             ]
-            if opts.get('all'):
+            if diff:
                 cols.append(('change', change, True))
             cols.extend([
                 ('user', formatuser(ctx.user()), opts.get('user')),
@@ -2644,7 +2647,7 @@
             if pstates or states:
                 r = display(fm, fn, ctx, pstates, states)
                 found = found or r
-                if r and not opts.get('all'):
+                if r and not diff:
                     skip[fn] = True
                     if copy:
                         skip[copy] = True