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

[PATCH] pathspec: reserve some letters after a colon pathspec

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 23, 2011, 15:32 UTC
Message-ID
<1300894353-19386-1-git-send-email-pclouds@gmail.com>
In-Reply-To
<bc49592f5e524a0d12aa55eeca1c5ca659b6525f.1298974647.git.git@drmicha.warpmail.net>

Pathspec ':something' means 'something' at top directory. Limit it a bit so that ':<non-alnum>something' can be reserved for future extensions. ':\<non-alnum>something' can be used to achieve ':something' before this patch.

All non-alphanumeric chars on the en_US keyboard, except \ and ., are currently reserved.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 This is the better, non-whitespace-damaged version. While I mark
 colon_pathspec_type() static, you can export it to use in git-attr.c
 setup.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/setup.c b/setup.c
index 3bbb01a..684abb5 100644
--- a/setup.c
+++ b/setup.c
@@ -123,6 +123,27 @@ void verify_non_filename(const char *prefix, const char *arg)
 	    "Use '--' to separate filenames from revisions", arg);
 }
 
+static int colon_pathspec_type(const char **pathspec)
+{
+	const char *reserved = "~`!@#$%^&*()-_=+[{]}|;:'\",<>/?";
+	const char *s = *pathspec;
+	int ret;
+
+	if (*s++ != ':')
+		return -1;
+	if (*s == '\\') {
+		s++;
+		ret = 0;
+	}
+	else if (*s && strchr(reserved, *s))
+		ret = -1;
+	else
+		ret = 0;
+
+	*pathspec = s;
+	return ret;
+}
+
 const char **get_pathspec(const char *prefix, const char **pathspec)
 {
 	const char *entry = *pathspec;
@@ -145,8 +166,14 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
 	prefixlen = prefix ? strlen(prefix) : 0;
 	while (*src) {
 		const char *p;
-		if ((*src)[0] == ':')
-			p = prefix_path(NULL, 0, (*src)+1);
+
+		if ((*src)[0] == ':') {
+			const char **s = src;
+			if (colon_pathspec_type(s) != 0)
+				die("Pathspec syntax ':%c' is not supported. %s"
+				    "Quote it for literally match.", (*s)[0], *s);
+			p = prefix_path(NULL, 0, *s);
+		}
 		else
 			p = prefix_path(prefix, prefixlen, *src);
 		*(dst++) = p;
-- 
1.7.4.74.g639db
Previous: Phil HordNext: Junio C Hamano
Message 41 of 46 in “git-grep to operate across who repository and not just CWD?”
  1. David ChantersFeb 28, 2011
  2. Michael J GruberFeb 28, 2011
  3. Jay SoffianFeb 28, 2011
  4. Junio C HamanoFeb 28, 2011
  5. Junio C HamanoFeb 28, 2011
  6. Phil HordFeb 28, 2011
  7. Michael J GruberMar 1, 2011
  8. Nguyen Thai Ngoc DuyMar 1, 2011
  9. Michael J GruberMar 1, 2011
  10. Nguyen Thai Ngoc DuyMar 1, 2011
  11. Nguyen Thai Ngoc DuyMar 1, 2011
  12. 0/2 grep --full-treeMichael J Gruber, Mar 1, 2011
  13. 1/2 grep: --full-treeMichael J Gruber, Mar 1, 2011
  14. 2/2 grep: make --full-tree work with pathspecsMichael J Gruber, Mar 1, 2011
  15. Junio C HamanoMar 1, 2011
  16. setup.c: denote repo wide pathspecs by ':'Michael J Gruber, Mar 1, 2011
  17. Nguyen Thai Ngoc DuyMar 1, 2011
  18. Michael J GruberMar 1, 2011
  19. Nguyen Thai Ngoc DuyMar 1, 2011
  20. Michael J GruberMar 1, 2011
  21. Nguyen Thai Ngoc DuyMar 1, 2011
  22. Junio C HamanoMar 1, 2011
  23. Michael J GruberMar 1, 2011
  24. Junio C HamanoMar 1, 2011
  25. Sverre RabbelierMar 2, 2011
  26. Nguyen Thai Ngoc DuyMar 2, 2011
  27. Michael J GruberMar 2, 2011
  28. Junio C HamanoMar 2, 2011
  29. Michael J GruberMar 2, 2011
  30. Miles BaderMar 3, 2011
  31. Junio C HamanoMar 3, 2011
  32. Phil HordMar 3, 2011
  33. Michael J GruberMar 3, 2011
  34. Phil HordMar 1, 2011
  35. James PickensMar 1, 2011
  36. Nguyen Thai Ngoc DuyMar 2, 2011
  37. Phil HordMar 3, 2011
  38. Michael J GruberMar 3, 2011
  39. Michael J GruberMar 1, 2011
  40. Phil HordMar 1, 2011
  41. pathspec: reserve some letters after a colon pathspecNguyễn Thái Ngọc Duy, Mar 23, 2011
  42. Junio C HamanoMar 23, 2011
  43. Michael J GruberMar 24, 2011
  44. Nguyen Thai Ngoc DuyMar 24, 2011
  45. Junio C HamanoMar 24, 2011
  46. Junio C HamanoMar 24, 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.