git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: PATCH: allow ':/<oneline prefix>' notation to specify a specific file

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 3, 2008, 09:20 UTC
Message-ID
<7v7ic32ujy.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<279b37b20807030152g13492d5dxf21367ab17719993@mail.gmail.com>
"Eric Raible" <raible@gmail.com> writes:
Show 15 quoted lines
> This patch allows git show ":/PATCH: allow":sha1_name.c to show the
> change to the file changed by this patch.
> ...
> @@ -697,8 +698,18 @@ int get_sha1_with_mode(const char *name, unsigned
> char *sha1, unsigned *mode)
>  		int stage = 0;
>  		struct cache_entry *ce;
>  		int pos;
> -		if (namelen > 2 && name[1] == '/')
> -			return get_sha1_oneline(name + 2, sha1);
> +		if (namelen > 2 && name[1] == '/') {
> +			name += 2;
> +			colon = strrchr(name, ':');
> +			if (!get_sha1_oneline(name, sha1) || !colon)
> +				return 0;

So when you have ":/A:B:C", you first try to look for string "A:B:C", and then when it fails try "A:B" and look for path C? I think this fallback makes sense, especially because this cannot break existing use for positive lookup (it _can_ be called a regression if you are checking to see if you have a commit that has A:B:C and you want the lookup to fail if there is A:B that happens to have path C, but I do not think we would care about that usage).

A few observations:
 (1) An obvious micro-optimization. Check if "A:B:C" is a rev, and if and
     only if it fails, run strrchr() to find fallback point;
 (2) When you do not find either "A:B:C" nor "A:B", perhaps try "A" and
     find "B:C" as a path in it?  IOW, you may want to fallback more than
     once;
 (3) If you are given ":/A~20" or ":/A^2", perhaps you would want to do
     something similar?
Other than that, I like what the patch is trying to do.     
Previous: Eric RaibleNext: Johannes Schindelin
Message 2 of 4 in “PATCH: allow ':/<oneline prefix>' notation to specify a specific file”
  1. Eric RaibleJul 3, 2008
  2. Junio C HamanoJul 3, 2008
  3. Johannes SchindelinJul 3, 2008
  4. Johannes SchindelinJul 3, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.