[PATCH] grep: add the option to show full commit hash for every result
Kostia Balytskyi
ikostia at fb.com
Thu Feb 4 13:04:20 EST 2016
On 2/4/16, 5:54 PM, "Augie Fackler" <raf at durin42.com> wrote:
>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.
I did not think of it, but that is a fix of much greater magnitude anyway.
My fix is cheap and solves a very concrete problem, so I see the point
in it.
>
>>
>> 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://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=7bmpcQS8Ua-thQLOHZhJWmgY_etWaKIWs7U_-FBt5oI&s=czplzluolMZnD1j8olLfgBwsjZWij0qNpdwMwFR9r94&e=
More information about the Mercurial-devel
mailing list