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

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

 



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

--
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]