[PATCHv2 1/4] refs: add common refname_match_patterns()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Tom Grennan <tmgrennan@xxxxxxxxx>
---
 refs.c |   14 ++++++++++++++
 refs.h |    8 ++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/refs.c b/refs.c
index b8843bb..b42eb4a 100644
--- a/refs.c
+++ b/refs.c
@@ -1057,6 +1057,20 @@ int refname_match(const char *abbrev_name, const char *full_name, const char **r
 	return 0;
 }
 
+int refname_match_patterns(const char **patterns, const char *refname)
+{
+	int given_match_pattern = 0, had_match = 0;
+
+	for (; *patterns; patterns++)
+		if (**patterns != '!') {
+			given_match_pattern = 1;
+			if (!fnmatch(*patterns, refname, 0))
+				had_match = 1;
+		} else if (!fnmatch(*patterns+1, refname, 0))
+			return 0;
+	return given_match_pattern ? had_match : 1;
+}
+
 static struct ref_lock *verify_lock(struct ref_lock *lock,
 	const unsigned char *old_sha1, int mustexist)
 {
diff --git a/refs.h b/refs.h
index 00ba1e2..13015ba 100644
--- a/refs.h
+++ b/refs.h
@@ -152,4 +152,12 @@ int update_ref(const char *action, const char *refname,
 		const unsigned char *sha1, const unsigned char *oldval,
 		int flags, enum action_on_err onerr);
 
+/**
+ * Returns:
+ *   1 with NULL patterns
+ *   0 if refname fnmatch()es any ! prefaced pattern
+ *   1 if refname fnmatch()es any pattern
+ */
+extern int refname_match_patterns(const char **patterns, const char *refname);
+
 #endif /* REFS_H */
-- 
1.7.8

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]