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

[PATCHv9 3/4] pathspec: move prefix check out of the inner loop

From
Stefan Beller <sbeller@google.com>
Date
May 19, 2016, 23:23 UTC
Message-ID
<20160519232323.12775-4-sbeller@google.com>
In-Reply-To
<20160519232323.12775-1-sbeller@google.com>

The prefix check is not related the check of pathspec magic; also there is no code that is relevant after we'd break the loop on a match for "prefix:". So move the check before the loop and shortcircuit the outer loop.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 pathspec.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/pathspec.c b/pathspec.c
index eba37c2..4dff252 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -107,21 +107,22 @@ static void eat_long_magic(struct pathspec_item *item, const char *elt,
 			nextat = copyfrom + len;
 		if (!len)
 			continue;
+
+		if (starts_with(copyfrom, "prefix:")) {
+			char *endptr;
+			*pathspec_prefix = strtol(copyfrom + 7,
+						  &endptr, 10);
+			if (endptr - copyfrom != len)
+				die(_("invalid parameter for pathspec magic 'prefix'"));
+			continue;
+		}
+
 		for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++) {
 			if (strlen(pathspec_magic[i].name) == len &&
 			    !strncmp(pathspec_magic[i].name, copyfrom, len)) {
 				*magic |= pathspec_magic[i].bit;
 				break;
 			}
-			if (starts_with(copyfrom, "prefix:")) {
-				char *endptr;
-				*pathspec_prefix = strtol(copyfrom + 7,
-							  &endptr, 10);
-				if (endptr - copyfrom != len)
-					die(_("invalid parameter for pathspec magic 'prefix'"));
-				/* "i" would be wrong, but it does not matter */
-				break;
-			}
 		}
 		if (ARRAY_SIZE(pathspec_magic) <= i)
 			die(_("Invalid pathspec magic '%.*s' in '%s'"),
-- 
2.8.2.123.gb4ad9b6.dirty
Previous: Stefan BellerNext: Stefan Beller
Message 4 of 9 in “[PATCHv9 0/4] pathspec magic extension to search for attributes”
  1. Stefan BellerMay 19, 2016
  2. 1/4 Documentation: fix a typoStefan Beller, May 19, 2016
  3. 2/4 pathspec: move long magic parsing out of prefix_pathspecStefan Beller, May 19, 2016
  4. 3/4 pathspec: move prefix check out of the inner loopStefan Beller, May 19, 2016
  5. 4/4 pathspec: allow querying for attributesStefan Beller, May 19, 2016
  6. Junio C HamanoMay 19, 2016
  7. Junio C HamanoMay 20, 2016
  8. Stefan BellerMay 20, 2016
  9. Junio C HamanoMay 20, 2016

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.