From: "Eric Raible" <raible@gmail.com>
To: "Junio C Hamano" <gitster@pobox.com>
Cc: git@vger.kernel.org, Johannes.Schindelin@gmx.de, peff@peff.net
Subject: Re: PATCH: Allow ':/<oneline prefix>' notation to specify a specific file
Date: Thu, 3 Jul 2008 04:05:21 -0700 [thread overview]
Message-ID: <279b37b20807030405s8212daarcd4d0083cc2df03e@mail.gmail.com> (raw)
On Thu, Jul 3, 2008 at 2:20 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 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?
Exactly. And as you pointed out it doesn't break existing usage by design.
> (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;
Done. This version is more careful about return values as well.
> (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?
I agree these are nice but get_sha1_oneline() is time-consuming as is
and I'm not familiar enough with the code to attempt a complete
refactorization.
And without refactoring get_sha1_oneline() would need to be called
repeated for each ~, ^, or : (working backward) until it succeeds.
I'll leave it to Johannes to refactor get_sha1_oneline to handle the
":/A~20" or ":/A^2" cases if he chooses to, as it's currently beyond
my git-fu.
An alternative suggested by Peff:
:/ should stop eating text at the first ':', and allow '\:' for
a literal colon and '\\' for a literal backslash.
is arguably better because it's completely unambiguous and allows
for a simpler implementation but it's not backwards compatible.
I'd be willing to come up with patch for that if people agree that
it's worth it.
Please note that the commit message uses the current subject,
so if this is applied it should be kept consistent.
- Eric
----- 8< -----
Although the rev-parse documentation claims that the tree-ish:path/to/file
syntax is applicable to all tree-ish forms this is not so when using the
:/ "oneline prefix" syntax introduced in v1.5.0.1-227-g28a4d94.
For instance, to see the file changed by this patch one could say:
git show ":/Allow ':/<oneline prefix>'":sha1_name.c
Note that this should but doesn't handle ~ and ^, so it will fail when
trying to show the parent of this commit message by using
git show ":/Allow ':/<oneline prefix>'"^
Signed-off-by: Eric Raible <raible@gmail.com>
---
sha1_name.c | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index b0b2167..415b4ce 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -697,8 +697,20 @@ 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] == '/') {
+ char *copy, *colon;
+ name += 2;
+ ret = get_sha1_oneline(name, sha1);
+ if (!ret || !(colon = strrchr(name, ':')))
+ return ret;
+ copy = xstrdup(name);
+ copy[colon - name] = '\0';
+ ret = get_sha1_oneline(copy, sha1);
+ if (!ret)
+ ret = get_tree_entry(sha1, colon+1, sha1, mode);
+ free(copy);
+ return ret;
+ }
if (namelen < 3 ||
name[2] != ':' ||
name[1] < '0' || '3' < name[1])
--
1.5.6.1.1356.g3885.dirty
next reply other threads:[~2008-07-03 12:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-03 11:05 Eric Raible [this message]
-- strict thread matches above, loose matches on Subject: below --
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
2008-07-03 12:55 ` Johannes Schindelin
2008-07-03 12:53 ` Johannes Schindelin
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=279b37b20807030405s8212daarcd4d0083cc2df03e@mail.gmail.com \
--to=raible@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).