diff options
author | Daniel Barkalow <barkalow@iabervon.org> | 2009-03-07 01:11:39 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-03-07 12:19:28 -0800 |
commit | abd2bde78bd994166900290434a2048e660dabed (patch) | |
tree | da95f1db0ca4b46c4220d22da637577cc1460c95 /remote.c | |
parent | 08fbdb30438fd7087c5abe15840a22fe21094515 (diff) | |
download | git-abd2bde78bd994166900290434a2048e660dabed.tar.gz git-abd2bde78bd994166900290434a2048e660dabed.tar.xz |
Support '*' in the middle of a refspec
In order to keep the requirements strict, each * has to be a full path
component, and there may only be one * per side. This requirement is
enforced entirely by check_ref_format(); the matching implementation
will substitute the whatever matches the * in the lhs for the * in the
rhs.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r-- | remote.c | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -511,12 +511,12 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp if (rhs) { size_t rlen = strlen(++rhs); - is_glob = (2 <= rlen && !strcmp(rhs + rlen - 2, "/*")); + is_glob = (1 <= rlen && strchr(rhs, '*')); rs[i].dst = xstrndup(rhs, rlen); } llen = (rhs ? (rhs - lhs - 1) : strlen(lhs)); - if (2 <= llen && !memcmp(lhs + llen - 2, "/*", 2)) { + if (1 <= llen && memchr(lhs, '*', llen)) { if ((rhs && !is_glob) || (!rhs && fetch)) goto invalid; is_glob = 1; @@ -718,22 +718,32 @@ static int match_name_with_pattern(const char *key, const char *name, { const char *kstar = strchr(key, '*'); size_t klen; + size_t ksuffixlen; + size_t namelen; int ret; if (!kstar) die("Key '%s' of pattern had no '*'", key); klen = kstar - key; - ret = !strncmp(key, name, klen); + ksuffixlen = strlen(kstar + 1); + namelen = strlen(name); + ret = !strncmp(name, key, klen) && namelen >= klen + ksuffixlen && + !memcmp(name + namelen - ksuffixlen, kstar + 1, ksuffixlen); if (ret && value) { const char *vstar = strchr(value, '*'); size_t vlen; + size_t vsuffixlen; if (!vstar) die("Value '%s' of pattern has no '*'", value); vlen = vstar - value; - *result = xmalloc(vlen + + vsuffixlen = strlen(vstar + 1); + *result = xmalloc(vlen + vsuffixlen + strlen(name) - - klen + 1); - strcpy(*result, value); - strcpy(*result + vlen, name + klen); + klen - ksuffixlen + 1); + strncpy(*result, value, vlen); + strncpy(*result + vlen, + name + klen, namelen - klen - ksuffixlen); + strcpy(*result + vlen + namelen - klen - ksuffixlen, + vstar + 1); } return ret; } |