summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-01-15 08:40:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-01-15 20:51:14 (GMT)
commit9892d5d4541d93a8a6a4fd9ac4178d71d0d308e3 (patch)
treef0651d3a363ca45a146e6c24ee5ed7f79c71660f /sha1_name.c
parent3f6eb30f1dbb6f8f715c9121bba43f2a1d294e28 (diff)
downloadgit-9892d5d4541d93a8a6a4fd9ac4178d71d0d308e3.zip
git-9892d5d4541d93a8a6a4fd9ac4178d71d0d308e3.tar.gz
git-9892d5d4541d93a8a6a4fd9ac4178d71d0d308e3.tar.bz2
interpret_branch_name: find all possible @-marks
When we parse a string like "foo@{upstream}", we look for the first "@"-sign, and check to see if it is an upstream mark. However, since branch names can contain an @, we may also see "@foo@{upstream}". In this case, we check only the first @, and ignore the second. As a result, we do not find the upstream. We can solve this by iterating through all @-marks in the string, and seeing if any is a legitimate upstream or empty-at mark. Another strategy would be to parse from the right-hand side of the string. However, that does not work for the "empty_at" case, which allows "@@{upstream}". We need to find the left-most one in this case (and we then recurse as "HEAD@{upstream}"). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 26a5811..15854e3 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1126,6 +1126,7 @@ static int interpret_upstream_mark(const char *name, int namelen,
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);
if (!namelen)
@@ -1140,17 +1141,18 @@ int interpret_branch_name(const char *name, int namelen, struct strbuf *buf)
return reinterpret(name, namelen, len, buf);
}
- at = memchr(name, '@', namelen);
- if (!at)
- return -1;
+ for (start = name;
+ (at = memchr(start, '@', namelen - (start - name)));
+ start = at + 1) {
- len = interpret_empty_at(name, namelen, at - name, buf);
- if (len > 0)
- return reinterpret(name, namelen, len, buf);
+ len = interpret_empty_at(name, namelen, at - name, buf);
+ if (len > 0)
+ return reinterpret(name, namelen, len, buf);
- len = interpret_upstream_mark(name, namelen, at - name, buf);
- if (len > 0)
- return len;
+ len = interpret_upstream_mark(name, namelen, at - name, buf);
+ if (len > 0)
+ return len;
+ }
return -1;
}