threads / patch / 18164

patch, 5 partsUse a single function to match names against patterns

Subject: [PATCH 2/5] Use a single function to match names against patterns

## tl;dr

2 messages between Mar 6, 2009 and Mar 7, 2009. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Daniel Barkalow· Mar 6, 2009, 04:56 UTC · lore
This will help when the matching changes.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 remote.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
Show changes to remote.c +9 −3
diff --git a/remote.c b/remote.c
index d7079c6..709300b 100644
--- a/remote.c
+++ b/remote.c
@@ -719,6 +719,12 @@ int remote_has_url(struct remote *remote, const char *url)
 	return 0;
 }
 
+static int name_fits_pattern(const char *key, const char *name)
+{
+	int ret = !prefixcmp(key, name);
+	return ret;
+}
+
 int remote_find_tracking(struct remote *remote, struct refspec *refspec)
 {
 	int find_src = refspec->src == NULL;
@@ -742,7 +748,7 @@ int remote_find_tracking(struct remote *remote, struct refspec *refspec)
 		if (!fetch->dst)
 			continue;
 		if (fetch->pattern) {
-			if (!prefixcmp(needle, key)) {
+			if (name_fits_pattern(key, needle)) {
 				*result = xmalloc(strlen(value) +
 						  strlen(needle) -
 						  strlen(key) + 1);
@@ -1020,7 +1026,7 @@ static const struct refspec *check_pattern_match(const struct refspec *rs,
 			continue;
 		}
 
-		if (rs[i].pattern && !prefixcmp(src->name, rs[i].src))
+		if (rs[i].pattern && name_fits_pattern(rs[i].src, src->name))
 			return rs + i;
 	}
 	if (matching_refs != -1)
@@ -1160,7 +1166,7 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
 	for (ref = remote_refs; ref; ref = ref->next) {
 		if (strchr(ref->name, '^'))
 			continue; /* a dereference item */
-		if (!prefixcmp(ref->name, refspec->src)) {
+		if (name_fits_pattern(refspec->src, ref->name)) {
 			const char *match;
 			struct ref *cpy = copy_ref(ref);
 			match = ref->name + remote_prefix_len;
-- 
1.6.1.286.gd33a4.dirty
Daniel Barkalow· Mar 7, 2009, 06:11 UTC · re: Daniel Barkalow · lore

[PATCH v2 2/5] Use a single function to match names against patterns

This will help when the matching changes.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
Improved the function name for its eventual use.
 remote.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
Show changes to remote.c +9 −3
diff --git a/remote.c b/remote.c
index d7079c6..2816723 100644
--- a/remote.c
+++ b/remote.c
@@ -719,6 +719,12 @@ int remote_has_url(struct remote *remote, const char *url)
 	return 0;
 }
 
+static int match_name_with_pattern(const char *key, const char *name)
+{
+	int ret = !prefixcmp(key, name);
+	return ret;
+}
+
 int remote_find_tracking(struct remote *remote, struct refspec *refspec)
 {
 	int find_src = refspec->src == NULL;
@@ -742,7 +748,7 @@ int remote_find_tracking(struct remote *remote, struct refspec *refspec)
 		if (!fetch->dst)
 			continue;
 		if (fetch->pattern) {
-			if (!prefixcmp(needle, key)) {
+			if (match_name_with_pattern(key, needle)) {
 				*result = xmalloc(strlen(value) +
 						  strlen(needle) -
 						  strlen(key) + 1);
@@ -1020,7 +1026,7 @@ static const struct refspec *check_pattern_match(const struct refspec *rs,
 			continue;
 		}
 
-		if (rs[i].pattern && !prefixcmp(src->name, rs[i].src))
+		if (rs[i].pattern && match_name_with_pattern(rs[i].src, src->name))
 			return rs + i;
 	}
 	if (matching_refs != -1)
@@ -1160,7 +1166,7 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
 	for (ref = remote_refs; ref; ref = ref->next) {
 		if (strchr(ref->name, '^'))
 			continue; /* a dereference item */
-		if (!prefixcmp(ref->name, refspec->src)) {
+		if (match_name_with_pattern(refspec->src, ref->name)) {
 			const char *match;
 			struct ref *cpy = copy_ref(ref);
 			match = ref->name + remote_prefix_len;
-- 
1.6.1.286.gd33a4.dirty

← back to recent threads