Browse Source

Merge branch 'rs/remote-simplify'

* rs/remote-simplify:
  remote: simplify match_name_with_pattern() using strbuf
maint
Junio C Hamano 10 years ago
parent
commit
60dfd8461b
  1. 17
      remote.c

17
remote.c

@ -862,21 +862,14 @@ static int match_name_with_pattern(const char *key, const char *name,
ret = !strncmp(name, key, klen) && namelen >= klen + ksuffixlen && ret = !strncmp(name, key, klen) && namelen >= klen + ksuffixlen &&
!memcmp(name + namelen - ksuffixlen, kstar + 1, ksuffixlen); !memcmp(name + namelen - ksuffixlen, kstar + 1, ksuffixlen);
if (ret && value) { if (ret && value) {
struct strbuf sb = STRBUF_INIT;
const char *vstar = strchr(value, '*'); const char *vstar = strchr(value, '*');
size_t vlen;
size_t vsuffixlen;
if (!vstar) if (!vstar)
die("Value '%s' of pattern has no '*'", value); die("Value '%s' of pattern has no '*'", value);
vlen = vstar - value; strbuf_add(&sb, value, vstar - value);
vsuffixlen = strlen(vstar + 1); strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
*result = xmalloc(vlen + vsuffixlen + strbuf_addstr(&sb, vstar + 1);
strlen(name) - *result = strbuf_detach(&sb, NULL);
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; return ret;
} }

Loading…
Cancel
Save