[PATCH] grep: add the option to show full commit hash for every result

Augie Fackler raf at durin42.com
Thu Feb 4 12:54:07 EST 2016


On Thu, Feb 04, 2016 at 07:23:59AM -0800, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia at fb.com>
> # Date 1454599288 28800
> #      Thu Feb 04 07:21:28 2016 -0800
> # Node ID 436dfb325e8ce1b9cdad569a2bbe408a0d33bb5f
> # Parent  d73a5ab18015f61ac61e6e77256512fd82b03818
> grep: add the option to show full commit hash for every result

I didn't look at the full patch, but did you consider adding full
templater support to the output for grep? That would let us avoid
having an extra one-off flag.

>
> People often would want to send the result of hg grep to someone
> else with a remote repo. Currently it's of no big use since revision
> ids are not global. Introducing --hash will allow people to identify
> search results in a global way.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -4084,6 +4084,7 @@
>       _('only search files changed within revision range'), _('REV')),
>      ('u', 'user', None, _('list the author (long with -v)')),
>      ('d', 'date', None, _('list the date (short with -q)')),
> +    ('', 'hash', None, _('show full commit hash instead of revision id')),
>      ] + walkopts,
>      _('[OPTION]... PATTERN [FILE]...'),
>      inferrepo=True)
> @@ -4186,6 +4187,7 @@
>
>      def display(fn, ctx, pstates, states):
>          rev = ctx.rev()
> +        hash = ctx.hex()
>          if ui.quiet:
>              datefunc = util.shortdate
>          else:
> @@ -4201,8 +4203,12 @@
>          else:
>              iter = [('', l) for l in states]
>          for change, l in iter:
> -            cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')]
> -
> +            cols = [(fn, 'grep.filename')]
> +
> +            if opts.get('hash'):
> +                cols.append((str(hash), 'grep.rev'))
> +            else:
> +                cols.append((str(rev), 'grep.rev'))
>              if opts.get('line_number'):
>                  cols.append((str(l.linenum), 'grep.linenumber'))
>              if opts.get('all'):
> diff --git a/tests/test-grep.t b/tests/test-grep.t
> --- a/tests/test-grep.t
> +++ b/tests/test-grep.t
> @@ -173,6 +173,11 @@
>    color:3:-:red
>    color:1:+:red
>
> +Check that --hash option works
> +  $ hg grep --hash --all red
> +  color:[a-f0-9]{40}:-:red (re)
> +  color:[a-f0-9]{40}:\+:red (re)
> +
>    $ cd ..
>
>    $ hg init a
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list