Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-02-14 09:07:29 +0300
committerJunio C Hamano <gitster@pobox.com>2017-02-14 22:26:37 +0300
commitd0ffc069331b490ca15418ca7025d5b9024fbad5 (patch)
tree52458690c711c5a01d73184e794d0bd37bab0a44 /builtin
parentb5b81136da11638bdf1e336d9ec371b820fbf412 (diff)
grep: avoid resolving revision names in --no-index case
We disallow the use of revisions with --no-index, but we don't actually check and complain until well after we've parsed the revisions. This is the cause of a few problems: 1. We shouldn't be calling get_sha1() at all when we aren't in a repository, as it might access the ref or object databases. For now, this should generally just return failure, but eventually it will become a BUG(). 2. When there's a "--" disambiguator and you're outside a repository, we'll complain early with "unable to resolve revision". But we can give a much more specific error. 3. When there isn't a "--" disambiguator, we still do the normal rev/path checks. This is silly, as we know we cannot have any revs with --no-index. Everything we see must be a path. Outside of a repository this doesn't matter (since we know it won't resolve), but inside one, we may complain unnecessarily if a filename happens to also match a refname. This patch skips the get_sha1() call entirely in the no-index case, and behaves as if it failed (with the exception of giving a better error message). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/grep.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index e83b33bdaa..c4c6325941 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1176,6 +1176,12 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
break;
}
+ if (!use_index) {
+ if (seen_dashdash)
+ die(_("--no-index cannot be used with revs"));
+ break;
+ }
+
if (get_sha1_with_context(arg, 0, sha1, &oc)) {
if (seen_dashdash)
die(_("unable to resolve revision: %s"), arg);