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

Re: [PATCH 1/4] magic pathspec: add tentative ":/path/from/top/level" pathspec support

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 7, 2011, 01:40 UTC
Message-ID
<7v62qqhm9h.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1302138996-10006-2-git-send-email-gitster@pobox.com>
Junio C Hamano <gitster@pobox.com> writes:
> This patch implements only "top" magic because it is the only kind of
> magic that can be hacked into the system without such a refactoring.
> Other types of magic that are envisioned (e.g. "icase") needs to be able
> to express more than what a simple string can encode and needs to wait.

Actually "icase" could be implemented inside get_pathspec() by doing something like the attached patch.

But "noglob" needs support from the "struct pathspec_item" infrastructure. It is insufficient to parse the magic signature at get_pathspec() level, as I do not see a way to encode these magic in the match string.

I suspect that Duy's favourite "negate" cannot be done if we discard the magic information at the get_pathspec() level, either.

---
 Documentation/glossary-content.txt |    7 +++++--
 setup.c                            |   31 +++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index e51d7e6..0ca029b 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -319,10 +319,13 @@ top `/`;;
 	The magic word `top` (mnemonic: `/`) makes the pattern match
 	from the root of the working tree, even when you are running
 	the command from inside a subdirectory.
+icase;;
+	The magic word `icase` (there is no mnemonic for it) makes the
+	pattern match case insensitively.  E.g. `:(icase)makefile` matches
+	both `Makefile` and `makefile`.
 --
 +
-Currently only the slash `/` is recognized as the "magic signature",
-but it is envisioned that we will support more types of magic in later
+It is envisioned that we will support more types of magic in later
 versions of git.
 
 [[def_parent]]parent::
diff --git a/setup.c b/setup.c
index 820ed05..e66ffbe 100644
--- a/setup.c
+++ b/setup.c
@@ -136,12 +136,12 @@ void verify_non_filename(const char *prefix, const char *arg)
  * Possible future magic semantics include stuff like:
  *
  *	{ PATHSPEC_NOGLOB, '!', "noglob" },
- *	{ PATHSPEC_ICASE, '\0', "icase" },
  *	{ PATHSPEC_RECURSIVE, '*', "recursive" },
  *	{ PATHSPEC_REGEXP, '\0', "regexp" },
  *
  */
 #define PATHSPEC_FROMTOP    (1<<0)
+#define PATHSPEC_ICASE      (1<<1)
 
 struct pathspec_magic {
 	unsigned bit;
@@ -149,6 +149,7 @@ struct pathspec_magic {
 	const char *name;
 } pathspec_magic[] = {
 	{ PATHSPEC_FROMTOP, '/', "top" },
+	{ PATHSPEC_ICASE, '\0', "icase" },
 };
 
 /*
@@ -168,7 +169,8 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
 {
 	unsigned magic = 0;
 	const char *copyfrom = elt;
-	int i;
+	const char *retval;
+	int i, free_source = 0;
 
 	if (elt[0] != ':') {
 		; /* nothing to do */
@@ -215,10 +217,31 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
 			copyfrom++;
 	}
 
+	if (magic & PATHSPEC_ICASE) {
+		struct strbuf sb = STRBUF_INIT;
+		for (i = 0; copyfrom[i]; i++) {
+			int ch = copyfrom[i];
+			if (('a' <= ch && ch <= 'z') ||
+			    ('A' <= ch && ch <= 'Z')) {
+				strbuf_addf(&sb, "[%c%c]",
+					    tolower(ch), toupper(ch));
+			} else {
+				strbuf_addch(&sb, ch);
+			}
+		}
+		if (sb.len) {
+			free_source = 1;
+			copyfrom = strbuf_detach(&sb, NULL);
+		}
+	}
+
 	if (magic & PATHSPEC_FROMTOP)
-		return xstrdup(copyfrom);
+		retval = xstrdup(copyfrom);
 	else
-		return prefix_path(prefix, prefixlen, copyfrom);
+		retval = prefix_path(prefix, prefixlen, copyfrom);
+	if (free_source)
+		free((char *)copyfrom);
+	return retval;
 }
 
 const char **get_pathspec(const char *prefix, const char **pathspec)
Previous: Junio C HamanoNext: Nguyen Thai Ngoc Duy
Message 3 of 35 in “Redoing the "add -u" migration plan”
  1. 0/4 Redoing the "add -u" migration planJunio C Hamano, Apr 7, 2011
  2. 1/4 magic pathspec: add tentative ":/path/from/top/level" pathspec supportJunio C Hamano, Apr 7, 2011
  3. Junio C HamanoApr 7, 2011
  4. Nguyen Thai Ngoc DuyApr 7, 2011
  5. Junio C HamanoApr 7, 2011
  6. Nguyen Thai Ngoc DuyApr 8, 2011
  7. Nguyen Thai Ngoc DuyApr 7, 2011
  8. Junio C HamanoApr 7, 2011
  9. Nguyen Thai Ngoc DuyApr 8, 2011
  10. Junio C HamanoApr 8, 2011
  11. Nguyen Thai Ngoc DuyApr 8, 2011
  12. Junio C HamanoApr 8, 2011
  13. Nguyen Thai Ngoc DuyApr 8, 2011
  14. 2/4 add -u: get rid of "treewideupdate" configurationJunio C Hamano, Apr 7, 2011
  15. Jeff KingApr 8, 2011
  16. Junio C HamanoApr 8, 2011
  17. Jeff KingApr 8, 2011
  18. Junio C HamanoApr 8, 2011
  19. Jeff KingApr 8, 2011
  20. Junio C HamanoApr 8, 2011
  21. Junio C HamanoApr 8, 2011
  22. Nguyen Thai Ngoc DuyApr 9, 2011
  23. Junio C HamanoApr 9, 2011
  24. Nguyen Thai Ngoc DuyApr 9, 2011
  25. Junio C HamanoApr 9, 2011
  26. Nguyen Thai Ngoc DuyApr 9, 2011
  27. Junio C HamanoApr 9, 2011
  28. Nguyen Thai Ngoc DuyApr 9, 2011
  29. Nguyen Thai Ngoc DuyApr 9, 2011
  30. Junio C HamanoApr 9, 2011
  31. Nguyen Thai Ngoc DuyMay 3, 2011
  32. Junio C HamanoMay 3, 2011
  33. Nguyen Thai Ngoc DuyMay 3, 2011
  34. 3/4 add: make "add -u/-A" update full tree without pathspec (step 2)Junio C Hamano, Apr 7, 2011
  35. 4/4 add: make "add -u/-A" update full tree without pathspec (step 3)Junio C Hamano, Apr 7, 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.