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

[PATCH 3/6] Convert prefix_pathspec() to produce struct pathspec_item

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Oct 11, 2011, 22:44 UTC
Message-ID
<1318373083-13840-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1318373083-13840-1-git-send-email-pclouds@gmail.com>

New field plain_len is used to mark the first part of 'match' where no magic can be applied. It's not used though. tree_entry_interesting() should learn to utilize it.

Now we can show get_pathspec() what magic a pathspec has. Make sure only certain magic is accepted because more will come in future and not all of them can be converted to plain string like PATHSPEC_FROMTOP.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 match_pathspec_depth() should also check for unsupported magic..
 cache.h |    1 +
 setup.c |   22 +++++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/cache.h b/cache.h
index fe46f1e..17df06f 100644
--- a/cache.h
+++ b/cache.h
@@ -548,6 +548,7 @@ struct pathspec {
 	struct pathspec_item {
 		const char *match;
 		int len;
+		int plain_len;	/* match[0..plain_len-1] does not have any kind of magic*/
 		unsigned magic;
 	} *items;
 };
diff --git a/setup.c b/setup.c
index 35db910..8f1c2c0 100644
--- a/setup.c
+++ b/setup.c
@@ -126,7 +126,8 @@ static struct pathspec_magic {
  * the prefix part must always match literally, and a single stupid
  * string cannot express such a case.
  */
-static const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
+static const char *prefix_pathspec(struct pathspec_item *item, const char *prefix,
+				   int prefixlen, const char *elt)
 {
 	unsigned magic = 0;
 	const char *copyfrom = elt;
@@ -181,10 +182,17 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char
 			copyfrom++;
 	}
 
+	memset(item, 0, sizeof(*item));
+	item->magic = magic;
+
 	if (magic & PATHSPEC_FROMTOP)
-		return xstrdup(copyfrom);
-	else
-		return prefix_path(prefix, prefixlen, copyfrom);
+		item->match = xstrdup(copyfrom);
+	else {
+		item->match = prefix_path(prefix, prefixlen, copyfrom);
+		item->plain_len = prefixlen;
+	}
+	item->len = strlen(item->match);
+	return 0;
 }
 
 const char **get_pathspec(const char *prefix, const char **pathspec)
@@ -208,7 +216,11 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
 	dst = pathspec;
 	prefixlen = prefix ? strlen(prefix) : 0;
 	while (*src) {
-		*(dst++) = prefix_pathspec(prefix, prefixlen, *src);
+		struct pathspec_item item;
+		prefix_pathspec(&item, prefix, prefixlen, *src);
+		if (item.magic & ~PATHSPEC_FROMTOP)
+			die("Unsupported magic pathspec %s", *src);
+		*(dst++) = item.match;
 		src++;
 	}
 	*dst = NULL;
-- 
1.7.3.1.256.g2539c.dirty
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 7 of 12 in “Negation magic pathspec”
  1. 0/6 Negation magic pathspecNguyễn Thái Ngọc Duy, Oct 11, 2011
  2. 1/6 Recognize magic pathspec as filenamesNguyễn Thái Ngọc Duy, Oct 11, 2011
  3. Junio C HamanoOct 12, 2011
  4. Nguyen Thai Ngoc DuyOct 13, 2011
  5. Junio C HamanoOct 13, 2011
  6. 2/6 Replace has_wildcard with PATHSPEC_NOGLOBNguyễn Thái Ngọc Duy, Oct 11, 2011
  7. 3/6 Convert prefix_pathspec() to produce struct pathspec_itemNguyễn Thái Ngọc Duy, Oct 11, 2011
  8. 4/6 Implement parse_pathspec()Nguyễn Thái Ngọc Duy, Oct 11, 2011
  9. 5/6 Convert simple init_pathspec() cases to parse_pathspec()Nguyễn Thái Ngọc Duy, Oct 11, 2011
  10. Junio C HamanoOct 13, 2011
  11. 6/6 Implement negative pathspecNguyễn Thái Ngọc Duy, Oct 11, 2011
  12. Junio C HamanoOct 11, 2011

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.