summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a3c8423)
raw | patch | inline | side by side (parent: a3c8423)
author | Daniel Barkalow <barkalow@iabervon.org> | |
Sat, 7 Mar 2009 06:11:34 +0000 (01:11 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 7 Mar 2009 20:19:21 +0000 (12:19 -0800) |
This puts all of the interpretation of the pattern representation in a
single function for easy manipulation.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
single function for easy manipulation.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c | patch | blob | history |
diff --git a/remote.c b/remote.c
index 2816723bb9ec59b7fb873246131615ca8496a9b3..01b8f91c5b3f493eb1ade0d08e6f9f962f7ff992 100644 (file)
--- a/remote.c
+++ b/remote.c
return 0;
}
-static int match_name_with_pattern(const char *key, const char *name)
+static int match_name_with_pattern(const char *key, const char *name,
+ const char *value, char **result)
{
- int ret = !prefixcmp(key, name);
+ size_t klen = strlen(key);
+ int ret = !strncmp(key, name, klen);
+ if (ret && value) {
+ size_t vlen = strlen(value);
+ *result = xmalloc(vlen +
+ strlen(name) -
+ klen + 1);
+ strcpy(*result, value);
+ strcpy(*result + vlen, name + klen);
+ }
return ret;
}
if (!fetch->dst)
continue;
if (fetch->pattern) {
- if (match_name_with_pattern(key, needle)) {
- *result = xmalloc(strlen(value) +
- strlen(needle) -
- strlen(key) + 1);
- strcpy(*result, value);
- strcpy(*result + strlen(value),
- needle + strlen(key));
+ if (match_name_with_pattern(key, needle, value, result)) {
refspec->force = fetch->force;
return 0;
}
continue;
}
- if (rs[i].pattern && match_name_with_pattern(rs[i].src, src->name))
+ if (rs[i].pattern && match_name_with_pattern(rs[i].src, src->name,
+ NULL, NULL))
return rs + i;
}
if (matching_refs != -1)
} else {
const char *dst_side = pat->dst ? pat->dst : pat->src;
- dst_name = xmalloc(strlen(dst_side) +
- strlen(src->name) -
- strlen(pat->src) + 2);
- strcpy(dst_name, dst_side);
- strcat(dst_name, src->name + strlen(pat->src));
+ if (!match_name_with_pattern(pat->src, src->name,
+ dst_side, &dst_name))
+ die("Didn't think it matches any more");
}
dst_peer = find_ref_by_name(dst, dst_name);
if (dst_peer) {
struct ref *ret = NULL;
struct ref **tail = &ret;
- int remote_prefix_len = strlen(refspec->src);
- int local_prefix_len = strlen(refspec->dst);
+ char *expn_name;
for (ref = remote_refs; ref; ref = ref->next) {
if (strchr(ref->name, '^'))
continue; /* a dereference item */
- if (match_name_with_pattern(refspec->src, ref->name)) {
- const char *match;
+ if (match_name_with_pattern(refspec->src, ref->name,
+ refspec->dst, &expn_name)) {
struct ref *cpy = copy_ref(ref);
- match = ref->name + remote_prefix_len;
- cpy->peer_ref = alloc_ref_with_prefix(refspec->dst,
- local_prefix_len, match);
+ cpy->peer_ref = alloc_ref(expn_name);
+ free(expn_name);
if (refspec->force)
cpy->peer_ref->force = 1;
*tail = cpy;