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

[PATCH/WIP 01/10] pathspec: allow to use alternate char for quoting long magic mnemonic

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 13, 2013, 12:49 UTC
Message-ID
<1358081379-17752-2-git-send-email-pclouds@gmail.com>
In-Reply-To
<1358081379-17752-1-git-send-email-pclouds@gmail.com>

Currently use parentheses, e.g. ":(icase,literal)path", but they do not play well with unix shells because they have special meaning and we need to quote them. Allow an alternate syntax ":q/icase,literal/path".

Similar to ed's s/// syntax, '/' can be replaced with anything. If the opening quote has a closing counterpart, e.g. () [] <> {}, then it'll be quoted as such.

It may even be a good thing to kill ':(...)' syntax, which can easily be replaced with ':q(...)'. It's unlikely that anybody is used to it yet.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 setup.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/setup.c b/setup.c
index 69ca047..9db6093 100644
--- a/setup.c
+++ b/setup.c
@@ -196,14 +196,32 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 
 	if (elt[0] != ':') {
 		; /* nothing to do */
-	} else if (elt[1] == '(') {
+	} else if (elt[1] == '(' || elt[1] == 'q') {
 		/* longhand */
 		const char *nextat;
-		for (copyfrom = elt + 2;
-		     *copyfrom && *copyfrom != ')';
+		char close = ')';
+		char sep[3] = ",)";
+		if (elt[1] == '(')
+			copyfrom = elt + 2;
+		else {
+			copyfrom = elt + 3;
+			switch (elt[2]) {
+			case '(': close = ')'; break;
+			case '[': close = ']'; break;
+			case '{': close = '}'; break;
+			case '<': close = '>'; break;
+			case '\0':
+				die("Invalid pathspec '%s'", elt);
+			default:
+				close = elt[2];
+			}
+			sep[1] = close;
+		}
+		for (;
+		     *copyfrom && *copyfrom != close;
 		     copyfrom = nextat) {
-			size_t len = strcspn(copyfrom, ",)");
-			if (copyfrom[len] == ')')
+			size_t len = strcspn(copyfrom, sep);
+			if (copyfrom[len] == close)
 				nextat = copyfrom + len;
 			else
 				nextat = copyfrom + len + 1;
@@ -219,7 +237,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 				die("Invalid pathspec magic '%.*s' in '%s'",
 				    (int) len, copyfrom, elt);
 		}
-		if (*copyfrom == ')')
+		if (*copyfrom == close)
 			copyfrom++;
 	} else {
 		/* shorthand */
-- 
1.8.0.rc2.23.g1fb49df
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 2 of 11 in “Fancy pathspec stuff”
  1. 00/10 Fancy pathspec stuffNguyễn Thái Ngọc Duy, Jan 13, 2013
  2. 01/10 pathspec: allow to use alternate char for quoting long magic mnemonicNguyễn Thái Ngọc Duy, Jan 13, 2013
  3. 02/10 parse_pathspec: make sure the prefix part is wildcard-freeNguyễn Thái Ngọc Duy, Jan 13, 2013
  4. 03/10 pathspec: support :(literal) syntax for noglob pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  5. 04/10 parse_pathspec: save prefix informationNguyễn Thái Ngọc Duy, Jan 13, 2013
  6. 05/10 pathspec: prepare for :(glob)path syntaxNguyễn Thái Ngọc Duy, Jan 13, 2013
  7. 06/10 Enable :(glob)path syntax for a lot of commandsNguyễn Thái Ngọc Duy, Jan 13, 2013
  8. 07/10 parse_pathspec: accept :(icase)path syntaxNguyễn Thái Ngọc Duy, Jan 13, 2013
  9. 08/10 common_prefix/read_directory: treat PATHSPEC_ICASE like wildcardsNguyễn Thái Ngọc Duy, Jan 13, 2013
  10. 09/10 pathspec: support icase in match_pathspec_depth and tree_entry_interestingNguyễn Thái Ngọc Duy, Jan 13, 2013
  11. 10/10 Enable ls-files and ls-tree for testing PATHSPEC_ICASENguyễn Thái Ngọc Duy, Jan 13, 2013

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.