Skip to content

Commit 60dfd84

Browse files
committed
Merge branch 'rs/remote-simplify'
* rs/remote-simplify: remote: simplify match_name_with_pattern() using strbuf
2 parents 0a2ba82 + 07bfa57 commit 60dfd84

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

remote.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -862,21 +862,14 @@ static int match_name_with_pattern(const char *key, const char *name,
862862
ret = !strncmp(name, key, klen) && namelen >= klen + ksuffixlen &&
863863
!memcmp(name + namelen - ksuffixlen, kstar + 1, ksuffixlen);
864864
if (ret && value) {
865+
struct strbuf sb = STRBUF_INIT;
865866
const char *vstar = strchr(value, '*');
866-
size_t vlen;
867-
size_t vsuffixlen;
868867
if (!vstar)
869868
die("Value '%s' of pattern has no '*'", value);
870-
vlen = vstar - value;
871-
vsuffixlen = strlen(vstar + 1);
872-
*result = xmalloc(vlen + vsuffixlen +
873-
strlen(name) -
874-
klen - ksuffixlen + 1);
875-
strncpy(*result, value, vlen);
876-
strncpy(*result + vlen,
877-
name + klen, namelen - klen - ksuffixlen);
878-
strcpy(*result + vlen + namelen - klen - ksuffixlen,
879-
vstar + 1);
869+
strbuf_add(&sb, value, vstar - value);
870+
strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
871+
strbuf_addstr(&sb, vstar + 1);
872+
*result = strbuf_detach(&sb, NULL);
880873
}
881874
return ret;
882875
}

0 commit comments

Comments
 (0)