aboutsummaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-05-26 15:10:31 -0400
committerJunio C Hamano <gitster@pobox.com>2017-05-29 11:36:56 +0900
commitc99eddd83519811d6604b4ce4a8d2001787a30d4 (patch)
tree5c0d728962da5896fc340daac414ddb2b2f8e3ae /setup.c
parent42471bcee44e87669eb17f9fa13c8041a0fc35a1 (diff)
downloadgit-c99eddd83519811d6604b4ce4a8d2001787a30d4.tar.gz
git-c99eddd83519811d6604b4ce4a8d2001787a30d4.tar.xz
verify_filename(): treat ":(magic)" as a pathspec
For commands that take revisions and pathspecs, magic pathspecs like ":(exclude)foo" require the user to specify a disambiguating "--", since they do not match a file in the filesystem, like: git grep foo -- :(exclude)bar This makes them more annoying to use than they need to be. We loosened the rules for wildcards in 28fcc0b71 (pathspec: avoid the need of "--" when wildcard is used, 2015-05-02). Let's do the same for pathspecs with long-form magic. We already handle the short-forms ":/" and ":^" specially in check_filename(), so we don't need to handle them here. And in fact, we could do the same with long-form magic, parsing out the actual filename and making sure it exists. But there are a few reasons not to do it that way: - the parsing gets much more complicated, and we'd want to hand it off to the pathspec code. But that code isn't ready to do this kind of speculative parsing (it's happy to die() when it sees a syntactically invalid pathspec). - not all pathspec magic maps to a filesystem path. E.g., :(attr) should be treated as a pathspec regardless of what is in the filesystem - we can be a bit looser with ":(" than with the short-form ":/", because it is much less likely to have a false positive. Whereas ":/" also means "search for a commit with this regex". Note that because the change is in verify_filename() and not in its helper check_filename(), this doesn't affect the verify_non_filename() case. I.e., if an item that matches our new rule doesn't resolve as an object, we may fallback to treating it as a pathspec (rather than complaining it doesn't exist). But if it does resolve (e.g., as a file in the index that starts with an open-paren), we won't then complain that it's also a valid pathspec. This matches the wildcard-exception behavior. And of course in either case, one can always insert the "--" to get more precise results. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/setup.c b/setup.c
index 86bb7c9a9..89fcc12ab 100644
--- a/setup.c
+++ b/setup.c
@@ -186,6 +186,24 @@ static void NORETURN die_verify_filename(const char *prefix,
}
/*
+ * Check for arguments that don't resolve as actual files,
+ * but which look sufficiently like pathspecs that we'll consider
+ * them such for the purposes of rev/pathspec DWIM parsing.
+ */
+static int looks_like_pathspec(const char *arg)
+{
+ /* anything with a wildcard character */
+ if (!no_wildcard(arg))
+ return 1;
+
+ /* long-form pathspec magic */
+ if (starts_with(arg, ":("))
+ return 1;
+
+ return 0;
+}
+
+/*
* Verify a filename that we got as an argument for a pathspec
* entry. Note that a filename that begins with "-" never verifies
* as true, because even if such a filename were to exist, we want
@@ -211,7 +229,7 @@ void verify_filename(const char *prefix,
{
if (*arg == '-')
die("bad flag '%s' used after filename", arg);
- if (check_filename(prefix, arg) || !no_wildcard(arg))
+ if (check_filename(prefix, arg) || looks_like_pathspec(arg))
return;
die_verify_filename(prefix, arg, diagnose_misspelt_rev);
}