threads / rfc / 25652

[RFC] Using gitrevisions :/search style with other operators

Subject: [RFC] Using gitrevisions :/search style with other operators

## tl;dr

6 messages between Nov 5, 2010 and Nov 9, 2010.

replies: 5people: 3as markdown or json

Kevin Ballard· Nov 5, 2010, 22:38 UTC · lore

Most of the ways to refer to a git revision can be combined, e.g. I can type something silly like

  HEAD~2^^2^2~4^{tree}
and this will work as expected.

There is one operator that doesn't allow this at all, and that's the commit message search (e.g. :/foo). Every character after the :/ is taken to be part of the regular expression. This is rather unfortunate as it prevents me from doing something like :/foo^ to refer to the parent of the matching commit.

Does anybody have any opinions on changing this operator? My suggestion would be to treat a second / as a termination of the pattern and allow operators (such as ^ or ~<n>) to occur at that point. This would look like

  :/Merge branch 'foo'/^
If you need a / in your message then you can just escape it with a backslash.

A second change to consider is a syntax to specify that you want the 2nd (or nth) match rather than the first. This could be done like

  :/foo/2
unless someone has a better idea.

And finally, I'd love to be able to specify the ref to search from. The current behavior is to find the earliest matching commit on any ref, but it seems I should be able to type something like

  git merge 'origin/pu:/jh\/notes-merge/^2'

in order to grab the jh/notes-merge topic branch from origin/pu and merge it into HEAD. Currently trying to type something like master:/test will treat /test as a file path on master, which is something that will never resolve to a real file due to the leading slash.

Comments/suggestions/critiques are welcome.
-Kevin Ballard
Junio C Hamano· Nov 8, 2010, 19:09 UTC · re: Kevin Ballard · lore

Re: [RFC] Using gitrevisions :/search style with other operators

Kevin Ballard <kevin@sb.org> writes:
Show 6 quoted lines
> There is one operator that doesn't allow this at all, and that's the commit
> message search (e.g. :/foo). Every character after the :/ is taken to be
> part of the regular expression. This is rather unfortunate as it prevents me
> from doing something like :/foo^ to refer to the parent of the matching commit.
>
> Does anybody have any opinions on changing this operator?

If you mean to change what ":/Merge branch 'kb/blame-author-email'" means, and make my scripts suddenly start breaking, I would be moderately unhappy.

It is fine if we can enhance the extended SHA-1 vocabulary by introducing a syntax that used to be illegal, hence there is no chance somebody was using it for other purposes.

I wonder if we can introduce something like ':( ... )' to group things. E.g.

    $ git log 'HEAD..:( :/Merge branch 'kb/blame-author-email' )^2'

I haven't visited the particular codepath for some time, so I don't know offhand how involved the change would be, though.

Kevin Ballard· Nov 8, 2010, 22:11 UTC · re: Junio C Hamano · lore

Re: [RFC] Using gitrevisions :/search style with other operators

On Nov 8, 2010, at 11:09 AM, Junio C Hamano wrote:
Show 11 quoted lines
> Kevin Ballard <kevin@sb.org> writes:
> 
>> There is one operator that doesn't allow this at all, and that's the commit
>> message search (e.g. :/foo). Every character after the :/ is taken to be
>> part of the regular expression. This is rather unfortunate as it prevents me
>> from doing something like :/foo^ to refer to the parent of the matching commit.
>> 
>> Does anybody have any opinions on changing this operator?
> 
> If you mean to change what ":/Merge branch 'kb/blame-author-email'" means,
> and make my scripts suddenly start breaking, I would be moderately unhappy.
Ah yes, I suppose you do have a common case it would break.
Show 11 quoted lines
> It is fine if we can enhance the extended SHA-1 vocabulary by introducing
> a syntax that used to be illegal, hence there is no chance somebody was
> using it for other purposes.
> 
> I wonder if we can introduce something like ':( ... )' to group things.
> E.g.
> 
>    $ git log 'HEAD..:( :/Merge branch 'kb/blame-author-email' )^2'
> 
> I haven't visited the particular codepath for some time, so I don't know
> offhand how involved the change would be, though.

Interesting idea. It certainly solves the problem of being able to embed it within other operations (though you do then have to worry about escaping any embedded close-parens in the search), though it does mean my suggestion for being able to select the 2nd (or nth) match won't work. When I have the time I'll start taking a look at the code.

Any comments on my suggestion to specify the ref to search from, e.g. origin/pu:/"Merge 'kb/blame-author-email'"? As I stated before, I believe this syntax is currently-unused (as it is interpreted as a file lookup, but file paths starting with / will never resolve to anything in testing), but I want to make sure I'm not overlooking something.

-Kevin Ballard
Jeff King· Nov 9, 2010, 05:16 UTC · re: Kevin Ballard · lore

Re: [RFC] Using gitrevisions :/search style with other operators

On Mon, Nov 08, 2010 at 02:11:54PM -0800, Kevin Ballard wrote:
Show 13 quoted lines
> >    $ git log 'HEAD..:( :/Merge branch 'kb/blame-author-email' )^2'
> > 
> > I haven't visited the particular codepath for some time, so I don't know
> > offhand how involved the change would be, though.
> 
> Interesting idea. It certainly solves the problem of being able to embed it
> within other operations (though you do then have to worry about escaping any
> embedded close-parens in the search), though it does mean my suggestion for
> being able to select the 2nd (or nth) match won't work. When I have the time
> I'll start taking a look at the code.
> 
> Any comments on my suggestion to specify the ref to search from, e.g.
> origin/pu:/"Merge 'kb/blame-author-email'"? As I stated before, I believe

It seems to me the natural way to do that would be to use our existing generic "start at this ref and follow some chain" syntax, which is ref^{foo}. For example: origin/pu^{:Merge 'kb/blame-author-email'}.

We already use it for "follow tree link" and "peel tag objects", and it is syntactically similar to the usual "follow the ancestry chain" syntax ("ref^"). And I believe it should be unambiguous, as nothing that could go in ^{} could start with ":". And presumably one would have to backslash-escape embedded closing curly braces.

We also have ref@{upstream}. The analogue here would be origin/pu@{:Merge 'kb/blame-author-email'}.

I don't recall whether we put any conscious thought into ref@{upstream} versus ref^{upstream}. Certainly the former implies to me finding a particular starting point (as we do for reflogs), and the latter implies walking object graph (either by parent ancestry links, or through dereferencing tag and commit pointers). But I may just be rationalizing after the fact. :)

Certainly this particular case seems to me to be more like "^" or "~"; you are walking the ancestry tree not a specific number of steps, but until you see a particular subject.

-Peff
Junio C Hamano· Nov 9, 2010, 15:59 UTC · re: Jeff King · lore

Re: [RFC] Using gitrevisions :/search style with other operators

Jeff King <peff@peff.net> writes:
Show 12 quoted lines
>> Any comments on my suggestion to specify the ref to search from, e.g.
>> origin/pu:/"Merge 'kb/blame-author-email'"? As I stated before, I believe
>
> It seems to me the natural way to do that would be to use our existing
> generic "start at this ref and follow some chain" syntax, which is
> ref^{foo}. For example: origin/pu^{:Merge 'kb/blame-author-email'}.
>
> We already use it for "follow tree link" and "peel tag objects", and it
> is syntactically similar to the usual "follow the ancestry chain" syntax
> ("ref^"). And I believe it should be unambiguous, as nothing that could
> go in ^{} could start with ":". And presumably one would have to
> backslash-escape embedded closing curly braces.

Yeah, that may make more sense but I think the operation specifier should be '/', not ':', no?

We chose ':' as a "funky SHA-1 expression introducer" that can be followed by other letters to specify what kind of funkiness is being summoned (in the case of ':/string', you are asking for "search" funkiness), so that we can extend it with different kind of funkiness later. That is where my earlier ':(...)' came from.

Show 5 quoted lines
> We also have ref@{upstream}. The analogue here would be
> origin/pu@{:Merge 'kb/blame-author-email'}.
>
> I don't recall whether we put any conscious thought into ref@{upstream}
> versus ref^{upstream}.

I think that is because it is nonsensical to say sha1@{u} for an arbitrary SHA-1 expression (i.e. the operator only makes sense for a branch ref we can find branch.*.merge for). So from that perspective, you are right that "Start from this commit and find an ancestor whose log message contains this string" goes well with "sha1^{/some string}"

Jeff King· Nov 9, 2010, 16:08 UTC · re: Junio C Hamano · lore

Re: [RFC] Using gitrevisions :/search style with other operators

On Tue, Nov 09, 2010 at 07:59:03AM -0800, Junio C Hamano wrote:
Show 6 quoted lines
> > It seems to me the natural way to do that would be to use our existing
> > generic "start at this ref and follow some chain" syntax, which is
> > ref^{foo}. For example: origin/pu^{:Merge 'kb/blame-author-email'}.
> 
> Yeah, that may make more sense but I think the operation specifier should
> be '/', not ':', no?

Yeah, I don't know what I was thinking when I wrote the text above. It should definitely be origin/pu^{/Merge...}.

-Peff

← back to recent threads