X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_name.c;h=77299257bf3aa91079d5b883c6676afa6fd2d01c;hb=79286102ce1620c5b0e73dc4559450eb24918e08;hp=c7f1510ef102512f1270a064fbb7a842b1d9aed9;hpb=103209c6782586d92b04ee1fc71c0fd6f6385f5f;p=git.git diff --git a/sha1_name.c b/sha1_name.c index c7f1510ef..77299257b 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -399,6 +399,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) unsigned long co_time; int co_tz, co_cnt; + /* a @{-N} placed anywhere except the start is an error */ + if (str[at+2] == '-') + return -1; + /* Is it asking for N-th entry, or approxidate? */ for (i = nth = 0; 0 <= nth && i < reflog_len; i++) { char ch = str[at+2+i]; @@ -881,8 +885,28 @@ int interpret_branch_name(const char *name, struct strbuf *buf) if (!len) return len; /* syntax Ok, not enough switches */ - if (0 < len) - return len; /* consumed from the front */ + if (0 < len && len == namelen) + return len; /* consumed all */ + else if (0 < len) { + /* we have extra data, which might need further processing */ + struct strbuf tmp = STRBUF_INIT; + int used = buf->len; + int ret; + + strbuf_add(buf, name + len, namelen - len); + ret = interpret_branch_name(buf->buf, &tmp); + /* that data was not interpreted, remove our cruft */ + if (ret < 0) { + strbuf_setlen(buf, used); + return len; + } + strbuf_reset(buf); + strbuf_addbuf(buf, &tmp); + strbuf_release(&tmp); + /* tweak for size of {-N} versus expanded ref name */ + return ret - used + len; + } + cp = strchr(name, '@'); if (!cp) return -1;