git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Brandon Williams <bmwill@google.com>,
	git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v2 2/2] grep: use '/' delimiter for paths
Date: Tue, 07 Feb 2017 12:24:30 -0800	[thread overview]
Message-ID: <xmqq8tphzr41.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170207150414.GD8583@stefanha-x1.localdomain> (Stefan Hajnoczi's message of "Tue, 7 Feb 2017 15:04:14 +0000")

Stefan Hajnoczi <stefanha@redhat.com> writes:

> Perhaps it's better to leave this than to merge code that doesn't work
> correctly 100% of the time.

I am not sure if you are shooting for is "work correctly" to begin
with, to be honest.  The current code always shows the "correct"
output which is "the tree-ish object name (expressed in a way easier
to understand by the humans), followed by a colon, followed by the
path in the tree-ish the hit lies".  You are making it "incorrect
but often more convenient", and sometimes that is a worth goal, but
for the particular use cases you presented, i.e.

    $ git grep -e "$pattern" "$commit:path"

a more natural way to express "I want to find this pattern in the
commit under that path" exists:

    $ git grep -e "$pattern" "$commit" -- path

and because of that, I do not think the former form of the query
should happen _less_ often in the first place, which would make it
"incorrect but more convenient if the user gives an unusual query".

So I am not sure if the change to "grep" is worth it.

Having said that, I actually think "make it more convenient" without
making anything incorrect would be to teach the revision parser to
understand

    <any-expression-to-name-a-tree-ish:<path>

as an extended SHA-1 expression to name the blob or the tree at that
path in the tree-ish, e.g. if we can make the revision parser to
take this

    master:Documentation:git.txt

as the name of the blob object, then the current output is both
correct and more convenient.  After all, this sample string starts
at "master:Documentation" (which is an extended SHA-1 expression to
name a tree-ish), followed by a colon, then followed by the path
"git.txt" in it, and "grep -e pattern master:Documentation" would
show hits in that blob prefixed with it.

I.e.

	T=$(git rev-parse master:Documentation)
	git cat-file blob $T:git.txt

would give you the contents of the source to the Git manual.  It is
not all that unreasonable to expect

	git cat-file blob master:Documentation:git.txt

to be able to show the same thing as well.  You'd need to backtrack
the parsing (e.g. attempt to find "Documentation:git.txt" in
"master", fail to find any, then fall back to find "git.txt" in
"master:Documentation", find one, and be happy, or something like
that), and define how to resolve potential ambiguity (e.g. there may
indeed be "Documentation:git.txt" and "Documentation/git.txt" in the
tree-ish "master"), though.



  parent reply	other threads:[~2017-02-07 20:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20 17:11 [PATCH v2 0/2] grep: make output consistent with revision syntax Stefan Hajnoczi
2017-01-20 17:11 ` [PATCH v2 1/2] grep: only add delimiter if there isn't one already Stefan Hajnoczi
2017-01-20 22:19   ` Junio C Hamano
2017-01-20 17:11 ` [PATCH v2 2/2] grep: use '/' delimiter for paths Stefan Hajnoczi
2017-01-20 22:18   ` Junio C Hamano
2017-01-20 23:51     ` Brandon Williams
2017-02-07 15:04       ` Stefan Hajnoczi
2017-02-07 19:50         ` Jeff King
2017-02-07 20:24         ` Junio C Hamano [this message]
2017-02-07 20:37           ` Junio C Hamano
2017-02-09  3:58           ` Jeff King
2017-02-09  5:14             ` Junio C Hamano
2017-02-09  5:20               ` Jeff King
2017-02-14  9:43                 ` Stefan Hajnoczi
2017-01-20 23:11 ` [PATCH v2 0/2] grep: make output consistent with revision syntax Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq8tphzr41.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).