summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2014-09-21 10:23:37 +0200
committerJunio C Hamano <gitster@pobox.com>2014-09-22 12:40:27 -0700
commit07bfa575c1ce741d0e33580c336596d3407129b6 (patch)
tree54e569556bc3be3dde3e0aeaa89d74d3a378c06b /remote.c
parent97b8860c071898d9e162678ea1035a8ced2f8b1f (diff)
downloadgit-07bfa575c1ce741d0e33580c336596d3407129b6.tar.gz
remote: simplify match_name_with_pattern() using strbufrs/remote-simplify
Make the code simpler and shorter by avoiding repetitive use of string length variables and leaving memory allocation to strbuf functions. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/remote.c b/remote.c
index 35e62ee0f5..ce785f8953 100644
--- a/remote.c
+++ b/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 &&
!memcmp(name + namelen - ksuffixlen, kstar + 1, ksuffixlen);
if (ret && value) {
+ struct strbuf sb = STRBUF_INIT;
const char *vstar = strchr(value, '*');
- size_t vlen;
- size_t vsuffixlen;
if (!vstar)
die("Value '%s' of pattern has no '*'", value);
- vlen = vstar - value;
- vsuffixlen = strlen(vstar + 1);
- *result = xmalloc(vlen + vsuffixlen +
- strlen(name) -
- klen - ksuffixlen + 1);
- strncpy(*result, value, vlen);
- strncpy(*result + vlen,
- name + klen, namelen - klen - ksuffixlen);
- strcpy(*result + vlen + namelen - klen - ksuffixlen,
- vstar + 1);
+ strbuf_add(&sb, value, vstar - value);
+ strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
+ strbuf_addstr(&sb, vstar + 1);
+ *result = strbuf_detach(&sb, NULL);
}
return ret;
}