Thread (14 messages) flat view 14 messages, 3 authors, 2016-06-15

Re: [RFC/PATCH] tag: make list exclude !<pattern>

From: Tom Grennan <hidden>
Date: 2016-06-15 22:53:02
Subsystem: the rest · Maintainer: Linus Torvalds

On Thu, Feb 09, 2012 at 11:43:36AM -0800, Tom Grennan wrote:
Use the "!" prefix to ignore tags of the given pattern.
This has precedence over other matching patterns.
For example,
...
static int match_pattern(const char **patterns, const char *ref)
{
+	int ret;
+
	/* no pattern means match everything */
	if (!*patterns)
		return 1;
-	for (; *patterns; patterns++)
-		if (!fnmatch(*patterns, ref, 0))
-			return 1;
-	return 0;
+	for (ret = 0; *patterns; patterns++)
+		if (**patterns == '!') {
+		    if (!fnmatch(*patterns+1, ref, 0))
+			    return 0;
+		} else if (!fnmatch(*patterns, ref, 0))
+			ret = 1;
+	return ret;
}
Correction, match_pattern() needs to be as follows to support all these cases,
  $ git tag -l
  $ git tag -l \!*-rc?
  $ git tag -l \!*-rc? v1.7.8*
  $ git tag -l v1.7.8* \!*-rc?
  $ git tag -l v1.7.8*

-- 
TomG
diff --git a/builtin/tag.c b/builtin/tag.c
index 31f02e8..e99be5c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -32,13 +32,16 @@ struct tag_filter {
 
 static int match_pattern(const char **patterns, const char *ref)
 {
-	/* no pattern means match everything */
-	if (!*patterns)
-		return 1;
+	int had_match_pattern = 0, had_match = 0;
+
 	for (; *patterns; patterns++)
-		if (!fnmatch(*patterns, ref, 0))
-			return 1;
-	return 0;
+		if (**patterns != '!') {
+			had_match_pattern = 1;
+			if (!fnmatch(*patterns, ref, 0))
+				had_match = 1;
+		} else if (!fnmatch(*patterns+1, ref, 0))
+			return 0;
+	return had_match_pattern ? had_match : 1;
 }
 
 static int in_commit_list(const struct commit_list *want, struct commit *c)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help