summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-04-08 16:18:46 -0700
committerJunio C Hamano <gitster@pobox.com>2011-04-08 16:19:48 -0700
commit2f6c9760debfb4705f6efb5862e2b3a23b2b951c (patch)
treef05e5e3d198fda2079c0c4a5ebb0d8f6d1877b43 /setup.c
parent8a42c9850177cc91e9f38779e8aca89682a02975 (diff)
downloadgit-2f6c9760debfb4705f6efb5862e2b3a23b2b951c.tar.gz
magic pathspec: futureproof shorthand form
The earlier design was to take whatever non-alnum that the short format parser happens to support, leaving the rest as part of the pattern, so a version of git that knows '*' magic and a version that does not would have behaved differently when given ":*Makefile". The former would have applied the '*' magic to the pattern "Makefile", while the latter would used no magic to the pattern "*Makefile". Instead, just reserve all non-alnum ASCII letters that are neither glob nor regexp special as potential magic signature, and when we see a magic that is not supported, die with an error message, just like the longhand codepath does. With this, ":%#!*Makefile" will always mean "%#!" magic applied to the pattern "*Makefile", no matter what version of git is used (it is a different matter if the version of git supports all of these three magic matching rules). Also make ':' without anything else to mean "there is no pathspec". This would allow differences between "git log" and "git log ." run from the top level of the working tree (the latter simplifies no-op commits away from the history) to be expressed from a subdirectory by saying "git log :". Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/setup.c b/setup.c
index 820ed05b27..5048252d78 100644
--- a/setup.c
+++ b/setup.c
@@ -197,19 +197,26 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
}
if (*copyfrom == ')')
copyfrom++;
+ } else if (!elt[1]) {
+ /* Just ':' -- no element! */
+ return NULL;
} else {
/* shorthand */
for (copyfrom = elt + 1;
*copyfrom && *copyfrom != ':';
copyfrom++) {
char ch = *copyfrom;
+
+ if (!is_pathspec_magic(ch))
+ break;
for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++)
if (pathspec_magic[i].mnemonic == ch) {
magic |= pathspec_magic[i].bit;
break;
}
if (ARRAY_SIZE(pathspec_magic) <= i)
- break;
+ die("Unimplemented pathspec magic '%c' in '%s'",
+ ch, elt);
}
if (*copyfrom == ':')
copyfrom++;