* [PATCH] interpret_branch_name(): handle auto-namelen for @{-1}
@ 2017-02-27 9:25 Jeff King
2017-02-27 9:31 ` Jeff King
0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2017-02-27 9:25 UTC (permalink / raw)
To: git; +Cc: Karthik Nayak
The interpret_branch_name() function takes a ptr/len pair
for the name, but you can pass "0" for "namelen", which will
cause it to check the length with strlen().
However, before we do that auto-namelen magic, we call
interpret_nth_prior_checkout(), which gets fed the bogus
"0". This was broken by 8cd4249c4 (interpret_branch_name:
always respect "namelen" parameter, 2014-01-15). Though to
be fair to that commit, it was broken in the _opposite_
direction before, where we would always treat "name" as a
string even if a length was passed.
You can see the bug with "git log -g @{-1}". That code path
always passes "0", and without this patch it cannot figure
out which branch's reflog to show.
We can fix it by a small reordering of the code.
Signed-off-by: Jeff King <peff@peff.net>
---
Noticed while digging on the nearby thread:
http://public-inbox.org/git/20170227090233.uk7dfruggytgmuw2@sigill.intra.peff.net/
sha1_name.c | 3 ++-
t/t0100-previous.sh | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/sha1_name.c b/sha1_name.c
index 73a915ff1..9b5d14b4b 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1263,11 +1263,12 @@ int interpret_branch_name(const char *name, int namelen, struct strbuf *buf)
{
char *at;
const char *start;
- int len = interpret_nth_prior_checkout(name, namelen, buf);
+ int len;
if (!namelen)
namelen = strlen(name);
+ len = interpret_nth_prior_checkout(name, namelen, buf);
if (!len) {
return len; /* syntax Ok, not enough switches */
} else if (len > 0) {
diff --git a/t/t0100-previous.sh b/t/t0100-previous.sh
index e0a694023..58c0b7e9b 100755
--- a/t/t0100-previous.sh
+++ b/t/t0100-previous.sh
@@ -56,5 +56,13 @@ test_expect_success 'merge @{-100} before checking out that many branches yet' '
test_must_fail git merge @{-100}
'
+test_expect_success 'log -g @{-1}' '
+ git checkout -b last_branch &&
+ git checkout -b new_branch &&
+ echo "last_branch@{0}" >expect &&
+ git log -g --format=%gd @{-1} >actual &&
+ test_cmp expect actual
+'
+
test_done
--
2.12.0.624.gbb1b07a2c
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] interpret_branch_name(): handle auto-namelen for @{-1}
2017-02-27 9:25 [PATCH] interpret_branch_name(): handle auto-namelen for @{-1} Jeff King
@ 2017-02-27 9:31 ` Jeff King
2017-02-27 19:27 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2017-02-27 9:31 UTC (permalink / raw)
To: git; +Cc: Karthik Nayak
On Mon, Feb 27, 2017 at 04:25:40AM -0500, Jeff King wrote:
> However, before we do that auto-namelen magic, we call
> interpret_nth_prior_checkout(), which gets fed the bogus
> "0". This was broken by 8cd4249c4 (interpret_branch_name:
> always respect "namelen" parameter, 2014-01-15). Though to
> be fair to that commit, it was broken in the _opposite_
> direction before, where we would always treat "name" as a
> string even if a length was passed.
That commit is mine, by the way. More embarrassing than introducing the
bug is that I _noticed_ the problem at the time and wrote a paragraph in
the commit message rationalizing why it was OK, rather than just doing
this trivial fix.
-Peff
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] interpret_branch_name(): handle auto-namelen for @{-1}
2017-02-27 9:31 ` Jeff King
@ 2017-02-27 19:27 ` Junio C Hamano
0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2017-02-27 19:27 UTC (permalink / raw)
To: Jeff King; +Cc: git, Karthik Nayak
Jeff King <peff@peff.net> writes:
> On Mon, Feb 27, 2017 at 04:25:40AM -0500, Jeff King wrote:
>
>> However, before we do that auto-namelen magic, we call
>> interpret_nth_prior_checkout(), which gets fed the bogus
>> "0". This was broken by 8cd4249c4 (interpret_branch_name:
>> always respect "namelen" parameter, 2014-01-15). Though to
>> be fair to that commit, it was broken in the _opposite_
>> direction before, where we would always treat "name" as a
>> string even if a length was passed.
>
> That commit is mine, by the way. More embarrassing than introducing the
> bug is that I _noticed_ the problem at the time and wrote a paragraph in
> the commit message rationalizing why it was OK, rather than just doing
> this trivial fix.
Thanks, I should also be embarrased since I didn't even notice the
issue when we queued it ;-)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-27 19:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-27 9:25 [PATCH] interpret_branch_name(): handle auto-namelen for @{-1} Jeff King
2017-02-27 9:31 ` Jeff King
2017-02-27 19:27 ` Junio C Hamano
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).