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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 28, 2010 at 04:52 UTC
d46a8301930ae83de30fbbbbce1bb02a98745204
2 files changed
+24
-4
sha1_name.c
+22
-2
@@ -881,8 +881,28 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
881
882
if (!len)
883
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
+
906
cp = strchr(name, '@');
907
if (!cp)
908
return -1;
t/t1508-at-combinations.sh
+2
-2
@@ -43,8 +43,8 @@ check "@{-1}" old-two
43
check "@{-1}@{1}" old-one
44
check "@{u}" upstream-two
45
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
48
fail nonsense "@{u}@{-1}"
49
nonsense "@{1}@{u}"
50