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

timeless timeless at gmail.com
Thu Feb 4 12:10:58 EST 2016


Normally we'd rely on -T, does grep not have it?
On Feb 4, 2016 10:24 AM, "Kostia Balytskyi" <ikostia at fb.com> 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
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160204/c4c89cf3/attachment.html>


More information about the Mercurial-devel mailing list