git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/3] rev-parse: simplify parsing of ref options
Date: Wed, 15 Mar 2017 14:09:33 -0700	[thread overview]
Message-ID: <xmqq8to6dz76.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170315200802.r4un6p5admfu4h34@sigill.intra.peff.net> (Jeff King's message of "Wed, 15 Mar 2017 16:08:02 -0400")

Jeff King <peff@peff.net> writes:

> This actually drops the last caller for for_each_branch_ref(). I'm not
> sure if we shoulder consider cleaning up the proliferation of
> for_each_ref() helpers.

That is certainly a good thing to do (but outside this series).

I am wondering if "git diff" could have chosen a better way to
arrange deleted and inserted lines.  The first two if statements
in the preimage corresponds to the new opt-with-value(branches)
thing, the next two are repalced by opt-with-value(tags), an
odd-man-out "--glob=" thing is replaced with handle_ref_opt(NULL),
and then two "--remotes" thing are paired with the final
opt-with-value(remotes) thing.  

That would break the usual expectation of seeing all "-" first and
then "+" when there is no intervening " " context lines, so such an
output might break tools, though (I do not think "git apply" would
choke).

>  builtin/rev-parse.c | 45 ++++++++++++++++-----------------------------
>  1 file changed, 16 insertions(+), 29 deletions(-)
>
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index db1417160..76be91350 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -554,6 +554,15 @@ static int opt_with_value(const char *arg, const char *opt, const char **value)
>  	return 0;
>  }
>  
> +static void handle_ref_opt(const char *pattern, const char *prefix)
> +{
> +	if (pattern)
> +		for_each_glob_ref_in(show_reference, pattern, prefix, NULL);
> +	else
> +		for_each_ref_in(prefix, show_reference, NULL);
> +	clear_ref_exclusion(&ref_excludes);
> +}
> +
>  int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>  {
>  	int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
> @@ -749,42 +758,20 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>  				for_each_ref_in("refs/bisect/good", anti_reference, NULL);
>  				continue;
>  			}
> -			if (skip_prefix(arg, "--branches=", &arg)) {
> -				for_each_glob_ref_in(show_reference, arg,
> -					"refs/heads/", NULL);
> -				clear_ref_exclusion(&ref_excludes);
> -				continue;
> -			}
> -			if (!strcmp(arg, "--branches")) {
> -				for_each_branch_ref(show_reference, NULL);
> -				clear_ref_exclusion(&ref_excludes);
> -				continue;
> -			}
> -			if (skip_prefix(arg, "--tags=", &arg)) {
> -				for_each_glob_ref_in(show_reference, arg,
> -					"refs/tags/", NULL);
> -				clear_ref_exclusion(&ref_excludes);
> +			if (opt_with_value(arg, "--branches", &arg)) {
> +				handle_ref_opt(arg, "refs/heads/");
>  				continue;
>  			}
> -			if (!strcmp(arg, "--tags")) {
> -				for_each_tag_ref(show_reference, NULL);
> -				clear_ref_exclusion(&ref_excludes);
> +			if (opt_with_value(arg, "--tags", &arg)) {
> +				handle_ref_opt(arg, "refs/tags/");
>  				continue;
>  			}
>  			if (skip_prefix(arg, "--glob=", &arg)) {
> -				for_each_glob_ref(show_reference, arg, NULL);
> -				clear_ref_exclusion(&ref_excludes);
> -				continue;
> -			}
> -			if (skip_prefix(arg, "--remotes=", &arg)) {
> -				for_each_glob_ref_in(show_reference, arg,
> -					"refs/remotes/", NULL);
> -				clear_ref_exclusion(&ref_excludes);
> +				handle_ref_opt(arg, NULL);
>  				continue;
>  			}
> -			if (!strcmp(arg, "--remotes")) {
> -				for_each_remote_ref(show_reference, NULL);
> -				clear_ref_exclusion(&ref_excludes);
> +			if (opt_with_value(arg, "--remotes", &arg)) {
> +				handle_ref_opt(arg, "refs/remotes/");
>  				continue;
>  			}
>  			if (skip_prefix(arg, "--exclude=", &arg)) {

  reply	other threads:[~2017-03-15 21:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 20:05 [PATCH 0/3] minor rev-parse option-parsing cleanups Jeff King
2017-03-15 20:05 ` [PATCH 1/3] rev-parse: use skip_prefix when parsing options Jeff King
2017-03-15 20:06 ` [PATCH 2/3] rev-parse: add helper for parsing "--foo/--foo=" Jeff King
2017-03-15 20:08 ` [PATCH 3/3] rev-parse: simplify parsing of ref options Jeff King
2017-03-15 21:09   ` Junio C Hamano [this message]
2017-03-15 21:38     ` Jeff King

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq8to6dz76.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).