Re: [PATCH 2/2] grep: use slash for path delimiter, not colon
- From
Jeff King <peff@peff.net>
- Date
- Sep 24, 2013, 06:57 UTC
- Message-ID
- <20130924065751.GD5875@sigill.intra.peff.net>
- In-Reply-To
- <99F7DE7C-A8D7-4EDF-B9C5-8DB143BFDB53@me.com>
On Sun, Sep 22, 2013 at 12:15:21PM -0700, Jonathon Mah wrote:
Show 7 quoted lines
> A few days ago I came across the same "surprising" output of git-grep, > tried to adjust the code to print "git show"-able object names, and > ran into similar subtleties. I just found this thread, and Jeff's code > handles more cases than mine did (I didn't try Phil's initial patch), > but I can add some more test cases with non-showable output (again > related to git-grep's path scoping): >
If you haven't read the side thread starting at [1], there are some arguments that git-grep is doing the right thing already. I think there are a few issues at play here:
> $ git grep -l cache HEAD:./ | head -1 > HEAD:./:.gitignore
As you show, using a colon separator from a tree-ish that contains a partial path looks bad. The downside of turning this into a slash, though, is that you lose the information of the tree-ish. See [2].
> $ cd Documentation > $ git grep -l cache HEAD | head -1 > HEAD:CodingGuidelines
Grepping from a subdirectory produces relative paths that look like real tree:path specifications, but aren't. Showing the full path would potentially be cluttering if you are in a deep directory. These days we have the "./" syntax, though, so we could perhaps output:
HEAD:./CodingGuidelines
which is succinct but can be used to access the path in the tree (and makes more clear to the user that we have only grepped in the current subdirectory).
> $ git grep -l cache HEAD:Documentation/CodingGuidelines > ../HEAD:Documentation/CodingGuidelines > (woah!)
That one just seems nonsensical and buggy to me. We should not be applying ".." at all to a blob spec like this.
-Peff
[1] http://thread.gmane.org/gmane.comp.version-control.git/232892/focus=232980
[2] http://thread.gmane.org/gmane.comp.version-control.git/232892/focus=233004