Skip to content

Commit d46a830

Browse files
peffgitster
authored andcommitted
fix parsing of @{-1}@{u} combination
Previously interpret_branch_name would see @{-1} and stop parsing, leaving the @{u} as cruft that provoked an error. Instead, we should recurse if there is more to parse. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42cab60 commit d46a830

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

sha1_name.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,28 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
881881

882882
if (!len)
883883
return len; /* syntax Ok, not enough switches */
884-
if (0 < len)
885-
return len; /* consumed from the front */
884+
if (0 < len && len == namelen)
885+
return len; /* consumed all */
886+
else if (0 < len) {
887+
/* we have extra data, which might need further processing */
888+
struct strbuf tmp = STRBUF_INIT;
889+
int used = buf->len;
890+
int ret;
891+
892+
strbuf_add(buf, name + len, namelen - len);
893+
ret = interpret_branch_name(buf->buf, &tmp);
894+
/* that data was not interpreted, remove our cruft */
895+
if (ret < 0) {
896+
strbuf_setlen(buf, used);
897+
return len;
898+
}
899+
strbuf_reset(buf);
900+
strbuf_addbuf(buf, &tmp);
901+
strbuf_release(&tmp);
902+
/* tweak for size of {-N} versus expanded ref name */
903+
return ret - used + len;
904+
}
905+
886906
cp = strchr(name, '@');
887907
if (!cp)
888908
return -1;

t/t1508-at-combinations.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ check "@{-1}" old-two
4343
check "@{-1}@{1}" old-one
4444
check "@{u}" upstream-two
4545
check "@{u}@{1}" upstream-one
46-
fail check "@{-1}@{u}" master-two
47-
fail check "@{-1}@{u}@{1}" master-one
46+
check "@{-1}@{u}" master-two
47+
check "@{-1}@{u}@{1}" master-one
4848
fail nonsense "@{u}@{-1}"
4949
nonsense "@{1}@{u}"
5050

0 commit comments

Comments
 (0)