git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/5] wildmatch: remove NEGATE_CLASS(2) macros with trivial refactoring

From
Masahiro Yamada <masahiroy@kernel.org>
Date
Feb 26, 2023, 11:50 UTC
Message-ID
<20230226115021.1681834-4-masahiroy@kernel.org>
In-Reply-To
<20230226115021.1681834-1-masahiroy@kernel.org>

The other glob patterns are hard-coded in dowild(). There is no need to macrofy '!' or '^'. Remove the NEGATE_CLASS and REGATE_CLASS2 defines, then refactor the code.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
(no changes since v1)
 wildmatch.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/wildmatch.c b/wildmatch.c
index a510b3fd23..93800b8eac 100644
--- a/wildmatch.c
+++ b/wildmatch.c
@@ -14,10 +14,6 @@
 
 typedef unsigned char uchar;
 
-/* What character marks an inverted character class? */
-#define NEGATE_CLASS	'!'
-#define NEGATE_CLASS2	'^'
-
 #define CC_EQ(class, len, litmatch) ((len) == sizeof (litmatch)-1 \
 				    && *(class) == *(litmatch) \
 				    && strncmp((char*)class, litmatch, len) == 0)
@@ -137,12 +133,8 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
 			return WM_ABORT_ALL;
 		case '[':
 			p_ch = *++p;
-#ifdef NEGATE_CLASS2
-			if (p_ch == NEGATE_CLASS2)
-				p_ch = NEGATE_CLASS;
-#endif
 			/* Assign literal 1/0 because of "matched" comparison. */
-			negated = p_ch == NEGATE_CLASS ? 1 : 0;
+			negated = p_ch == '!' || p_ch == '^' ? 1 : 0;
 			if (negated) {
 				/* Inverted character class. */
 				p_ch = *++p;
-- 
2.34.1
Previous: Masahiro YamadaNext: Masahiro Yamada
Message 7 of 9 in “Clean up wildmatch.c”
  1. 0/5 Clean up wildmatch.cMasahiro Yamada, Feb 26, 2023
  2. 1/5 git-compat-util: add isblank() and isgraph()Masahiro Yamada, Feb 26, 2023
  3. René ScharfeFeb 26, 2023
  4. Junio C HamanoFeb 27, 2023
  5. 2/5 wildmatch: remove IS*() macrosMasahiro Yamada, Feb 26, 2023
  6. 5/5 wildmatch: more cleanups after killing ucharMasahiro Yamada, Feb 26, 2023
  7. 3/5 wildmatch: remove NEGATE_CLASS(2) macros with trivial refactoringMasahiro Yamada, Feb 26, 2023
  8. 4/5 wildmatch: use char instead of ucharMasahiro Yamada, Feb 26, 2023
  9. Junio C HamanoFeb 27, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.