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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]