From: Brandon Williams <bmwill@google.com>
To: Jeff King <peff@peff.net>
Cc: Jonathan Tan <jonathantanmy@google.com>,
git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH 5/7] grep: fix "--" rev/pathspec disambiguation
Date: Tue, 14 Feb 2017 10:56:21 -0800 [thread overview]
Message-ID: <20170214185621.GC44208@google.com> (raw)
In-Reply-To: <20170214060555.yzh6hhi2t7pkeqvi@sigill.intra.peff.net>
On 02/14, Jeff King wrote:
> - /* Check revs and then paths */
> + /*
> + * We have to find "--" in a separate pass, because its presence
> + * influences how we will parse arguments that come before it.
> + */
> + for (i = 0; i < argc; i++) {
> + if (!strcmp(argv[i], "--")) {
> + seen_dashdash = 1;
> + break;
> + }
> + }
So this simply checks if "--" is an argument that was provided. This
then allows grep to know ahead of time how to handle revs/paths
preceding a "--" or in the absences of the "--". Seems sensible to me.
> +
> + /*
> + * Resolve any rev arguments. If we have a dashdash, then everything up
> + * to it must resolve as a rev. If not, then we stop at the first
> + * non-rev and assume everything else is a path.
> + */
> for (i = 0; i < argc; i++) {
> const char *arg = argv[i];
> unsigned char sha1[20];
> @@ -1158,13 +1173,14 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>
> if (!strcmp(arg, "--")) {
> i++;
> - seen_dashdash = 1;
> break;
> }
>
> - /* Stop at the first non-rev */
> - if (get_sha1_with_context(arg, 0, sha1, &oc))
> + if (get_sha1_with_context(arg, 0, sha1, &oc)) {
> + if (seen_dashdash)
> + die(_("unable to resolve revision: %s"), arg);
> break;
> + }
>
> object = parse_object_or_die(sha1, arg);
> if (!seen_dashdash)
> @@ -1172,7 +1188,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
> add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
> }
>
> - /* The rest are paths */
> + /*
> + * Anything left over is presumed to be a path. But in the non-dashdash
> + * "do what I mean" case, we verify and complain when that isn't true.
> + */
--
Brandon Williams
next prev parent reply other threads:[~2017-02-14 18:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-14 0:11 [PATCH for NEXT] grep: do not unnecessarily query repo for "--" Jonathan Tan
2017-02-14 1:20 ` Jeff King
2017-02-14 6:00 ` [PATCH 0/7] grep rev/path parsing fixes Jeff King
2017-02-14 6:02 ` [PATCH 1/7] grep: move thread initialization a little lower Jeff King
2017-02-14 18:46 ` Brandon Williams
2017-02-14 6:03 ` [PATCH 2/7] grep: do not unnecessarily query repo for "--" Jeff King
2017-02-14 6:03 ` [PATCH 3/7] t7810: make "--no-index --" test more robust Jeff King
2017-02-14 6:04 ` [PATCH 4/7] grep: re-order rev-parsing loop Jeff King
2017-02-14 18:48 ` Brandon Williams
2017-02-14 6:05 ` [PATCH 5/7] grep: fix "--" rev/pathspec disambiguation Jeff King
2017-02-14 18:56 ` Brandon Williams [this message]
2017-02-14 19:51 ` Jeff King
2017-02-14 19:18 ` Junio C Hamano
2017-02-14 6:07 ` [PATCH 6/7] grep: avoid resolving revision names in --no-index case Jeff King
2017-02-14 16:53 ` Jonathan Tan
2017-02-14 18:04 ` Jeff King
2017-02-14 18:19 ` Jonathan Tan
2017-02-14 21:54 ` [PATCH 8/7] grep: treat revs the same for --untracked as for --no-index Jeff King
2017-02-14 21:58 ` Junio C Hamano
2017-02-14 6:08 ` [PATCH 7/7] grep: do not diagnose misspelt revs with --no-index Jeff King
2017-02-14 6:10 ` [PATCH 0/7] grep rev/path parsing fixes Jeff King
2017-02-14 16:58 ` Jonathan Tan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170214185621.GC44208@google.com \
--to=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonathantanmy@google.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).