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

[PATCH 23/25] pathspec: move getenv() code out of prefix_pathspec()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Apr 6, 2015, 13:52 UTC
Message-ID
<1428328354-14897-24-git-send-email-pclouds@gmail.com>
In-Reply-To
<1428328354-14897-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 pathspec.c | 55 +++++++++++++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/pathspec.c b/pathspec.c
index 9304ee3..5573127 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -88,6 +88,13 @@ static void prefix_short_magic(struct strbuf *sb, int prefixlen,
 	strbuf_addf(sb, ",prefix:%d)", prefixlen);
 }
 
+struct global_flags {
+	unsigned literal : 1;
+	unsigned glob : 1;
+	unsigned noglob : 1;
+	unsigned icase : 1;
+};
+
 /*
  * Take an element of a pathspec and check for magic signatures.
  * Append the result to the prefix. Return the magic bitmap.
@@ -105,39 +112,20 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 				unsigned *p_short_magic,
 				const char **raw, unsigned flags,
 				const char *prefix, int prefixlen,
-				const char *elt)
+				const char *elt,
+				const struct global_flags *global)
 {
-	static int literal_global = -1;
-	static int glob_global = -1;
-	static int noglob_global = -1;
-	static int icase_global = -1;
 	unsigned magic = 0, short_magic = 0, global_magic = 0;
 	const char *copyfrom = elt, *long_magic_end = NULL;
 	char *match;
 	int i, pathspec_prefix = -1;
 
-	if (literal_global < 0)
-		literal_global = git_env_bool(GIT_LITERAL_PATHSPECS_ENVIRONMENT, 0);
-	if (literal_global)
+	if (global->literal)
 		global_magic |= PATHSPEC_LITERAL;
-
-	if (glob_global < 0)
-		glob_global = git_env_bool(GIT_GLOB_PATHSPECS_ENVIRONMENT, 0);
-	if (glob_global)
+	if (global->glob)
 		global_magic |= PATHSPEC_GLOB;
-
-	if (noglob_global < 0)
-		noglob_global = git_env_bool(GIT_NOGLOB_PATHSPECS_ENVIRONMENT, 0);
-
-	if (glob_global && noglob_global)
-		die(_("global 'glob' and 'noglob' pathspec settings are incompatible"));
-
-
-	if (icase_global < 0)
-		icase_global = git_env_bool(GIT_ICASE_PATHSPECS_ENVIRONMENT, 0);
-	if (icase_global)
+	if (global->icase)
 		global_magic |= PATHSPEC_ICASE;
-
 	if ((global_magic & PATHSPEC_LITERAL) &&
 	    (global_magic & ~PATHSPEC_LITERAL))
 		die(_("global 'literal' pathspec setting is incompatible "
@@ -146,7 +134,8 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 	if (flags & PATHSPEC_LITERAL_PATH)
 		global_magic = 0;
 
-	if (elt[0] != ':' || literal_global ||
+
+	if (elt[0] != ':' || global->literal ||
 	    (flags & PATHSPEC_LITERAL_PATH)) {
 		; /* nothing to do */
 	} else if (elt[1] == '(') {
@@ -213,7 +202,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 	*p_short_magic = short_magic;
 
 	/* --noglob-pathspec adds :(literal) _unless_ :(glob) is specified */
-	if (noglob_global && !(magic & PATHSPEC_GLOB))
+	if (global->noglob && !(magic & PATHSPEC_GLOB))
 		global_magic |= PATHSPEC_LITERAL;
 
 	/* --glob-pathspec is overridden by :(literal) */
@@ -247,7 +236,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 	 */
 	if (flags & PATHSPEC_PREFIX_ORIGIN) {
 		struct strbuf sb = STRBUF_INIT;
-		if (prefixlen && !literal_global) {
+		if (prefixlen && !global->literal) {
 			/* Preserve the actual prefix length of each pattern */
 			if (short_magic)
 				prefix_short_magic(&sb, prefixlen, short_magic);
@@ -365,6 +354,7 @@ void parse_pathspec(struct pathspec *pathspec,
 	struct pathspec_item *item;
 	const char *entry = argv ? *argv : NULL;
 	int i, n, prefixlen, nr_exclude = 0;
+	struct global_flags global;
 
 	memset(pathspec, 0, sizeof(*pathspec));
 
@@ -401,6 +391,14 @@ void parse_pathspec(struct pathspec *pathspec,
 		return;
 	}
 
+	memset(&global, 0, sizeof(global));
+	global.literal = git_env_bool(GIT_LITERAL_PATHSPECS_ENVIRONMENT, 0) != 0;
+	global.glob    = git_env_bool(GIT_GLOB_PATHSPECS_ENVIRONMENT,    0) != 0;
+	global.noglob  = git_env_bool(GIT_NOGLOB_PATHSPECS_ENVIRONMENT,  0) != 0;
+	global.icase   = git_env_bool(GIT_ICASE_PATHSPECS_ENVIRONMENT,   0) != 0;
+	if (global.glob && global.noglob)
+		die(_("global 'glob' and 'noglob' pathspec settings are incompatible"));
+
 	n = 0;
 	while (argv[n])
 		n++;
@@ -416,7 +414,8 @@ void parse_pathspec(struct pathspec *pathspec,
 
 		item[i].magic = prefix_pathspec(item + i, &short_magic,
 						argv + i, flags,
-						prefix, prefixlen, entry);
+						prefix, prefixlen, entry,
+						&global);
 		if ((flags & PATHSPEC_LITERAL_PATH) &&
 		    !(magic_mask & PATHSPEC_LITERAL))
 			item[i].magic |= PATHSPEC_LITERAL;
-- 
2.3.0.rc1.137.g477eb31
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 32 of 36 in “list-files redesign”
  1. 00/25 list-files redesignNguyễn Thái Ngọc Duy, Apr 6, 2015
  2. 01/25 ls_colors.c: add $LS_COLORS parsing codeNguyễn Thái Ngọc Duy, Apr 6, 2015
  3. 02/25 ls_colors.c: parse color.ls.* from config fileNguyễn Thái Ngọc Duy, Apr 6, 2015
  4. 03/25 ls_colors.c: add a function to color a file nameNguyễn Thái Ngọc Duy, Apr 6, 2015
  5. 04/25 ls_colors.c: highlight submodules like directoriesNguyễn Thái Ngọc Duy, Apr 6, 2015
  6. 05/25 list-files: command skeletonNguyễn Thái Ngọc Duy, Apr 6, 2015
  7. 06/25 list-files: show paths relative to cwdNguyễn Thái Ngọc Duy, Apr 6, 2015
  8. 07/25 list-files: add tag to each entry, filter duplicate tagsNguyễn Thái Ngọc Duy, Apr 6, 2015
  9. Eric SunshineApr 6, 2015
  10. 08/25 list-files: add --[no-]column, -C and -1Nguyễn Thái Ngọc Duy, Apr 6, 2015
  11. 09/25 list-files: add --max-depth, -R and default to --max-depth=0Nguyễn Thái Ngọc Duy, Apr 6, 2015
  12. 10/25 list-files: show directories as well as filesNguyễn Thái Ngọc Duy, Apr 6, 2015
  13. 11/25 list-files: add --colorNguyễn Thái Ngọc Duy, Apr 6, 2015
  14. Eric SunshineApr 6, 2015
  15. 12/25 list-files: add -F/--classifyNguyễn Thái Ngọc Duy, Apr 6, 2015
  16. 13/25 list-files: new indicator '&' for submodules when -F is usedNguyễn Thái Ngọc Duy, Apr 6, 2015
  17. 14/25 list-files: add --cached and --othersNguyễn Thái Ngọc Duy, Apr 6, 2015
  18. 15/25 list-files: add --ignoredNguyễn Thái Ngọc Duy, Apr 6, 2015
  19. Eric SunshineApr 6, 2015
  20. 16/25 list-files: add --unmergedNguyễn Thái Ngọc Duy, Apr 6, 2015
  21. Eric SunshineApr 6, 2015
  22. 17/25 list-files: add file modification options -[admADM]Nguyễn Thái Ngọc Duy, Apr 6, 2015
  23. Eric SunshineApr 6, 2015
  24. 18/25 list-files: delete redundant cached entriesNguyễn Thái Ngọc Duy, Apr 6, 2015
  25. Eric SunshineApr 6, 2015
  26. Junio C HamanoApr 8, 2015
  27. 19/25 list-files: make alias 'ls' default to 'list-files'Nguyễn Thái Ngọc Duy, Apr 6, 2015
  28. 20/25 list-files: preload indexNguyễn Thái Ngọc Duy, Apr 6, 2015
  29. Eric SunshineApr 6, 2015
  30. 21/25 list-files: reduce match_pathspec calls in matched()Nguyễn Thái Ngọc Duy, Apr 6, 2015
  31. 22/25 list-files: only do diff that is actually usefulNguyễn Thái Ngọc Duy, Apr 6, 2015
  32. 23/25 pathspec: move getenv() code out of prefix_pathspec()Nguyễn Thái Ngọc Duy, Apr 6, 2015
  33. 24/25 list-files: make :(glob) pathspec defaultNguyễn Thái Ngọc Duy, Apr 6, 2015
  34. 25/25 list-files: documentationNguyễn Thái Ngọc Duy, Apr 6, 2015
  35. Eric SunshineApr 6, 2015
  36. Duy NguyenApr 6, 2015

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.