git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Eric Raible" <raible@gmail.com>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	git@vger.kernel.org, Johannes.Schindelin@gmx.de
Subject: Re: PATCH: allow ':/<oneline prefix>' notation to specify a specific file
Date: Thu, 03 Jul 2008 02:20:17 -0700	[thread overview]
Message-ID: <7v7ic32ujy.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <279b37b20807030152g13492d5dxf21367ab17719993@mail.gmail.com> (Eric Raible's message of "Thu, 3 Jul 2008 01:52:45 -0700")

"Eric Raible" <raible@gmail.com> writes:

> 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.     

  reply	other threads:[~2008-07-03 11:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-03  8:52 PATCH: allow ':/<oneline prefix>' notation to specify a specific file Eric Raible
2008-07-03  9:20 ` Junio C Hamano [this message]
2008-07-03 12:55   ` Johannes Schindelin
2008-07-03 12:53 ` Johannes Schindelin
  -- strict thread matches above, loose matches on Subject: below --
2008-07-03 11:05 PATCH: Allow " Eric Raible

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

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

  git send-email \
    --in-reply-to=7v7ic32ujy.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=raible@gmail.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.
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 NNTP newsgroup(s).