Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Christian Sagstetter <christian.sagstetter@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] rev-parse: accept a separate pattern for --glob
Date: Fri, 4 Dec 2026 15:26:20 +0100	[thread overview]
Message-ID: <axLNjFCxEnJmeU0R@pks.im> (raw)
In-Reply-To: <CAFsHQ-aM9X1nABZMn2RqN+Ae-iCvHG5z7J1jqtJrPuokmbNTZQ@mail.gmail.com>

On Fri, Dec 04, 2026 at 05:38:55AM -0800, Christian Sagstetter wrote:
> With a branch named topic/one, "git rev-parse --glob=heads/topic"
> prints its object ID. Passing "heads/topic" as a separate argument
> instead makes rev-parse echo "--glob" and try to resolve "heads/topic"
> on its own. rev-list already accepts both forms.

> Consume the next argument as the pattern, even if it looks like an
> option. As in rev-list, a bare "--" still separates revisions from
> paths, so report a missing pattern if it immediately follows --glob.
> 
> Turn the two corresponding known failures in t6018 into expected
> successes and exercise the missing-pattern diagnostic.

Okay, so we have tests documenting this as a failure, which is a good
indicator that it's something we may want to fix. There's two questions
though coming to my mind:

  - Does it have any downsides to accept this pattern now? Like, does it
    for example introduce inconsistencies with how we parse other
    parameters?

  - Does the change have any upsides? Your patch kind of hints at the
    fact that this improves consistency with git-rev-list(1). But if we
    discover downsides while answering the first question we should
    weigh whether upsides overweight downsides.

  - The conversion is rather easy, so why did somebody bother to add a
    failing test instead of fixing the issue right away? Is there more
    to history here than the `test_expect_failure` indicates?

Ideally, those questions should be discussed as part of the commit
message to allow the reviewer to form an opinion on whether they think
the change makes sense.

> diff --git a/Documentation/git-rev-parse.adoc b/Documentation/git-rev-parse.adoc
> index 9103d54d53..1181ce3b08 100644
> --- a/Documentation/git-rev-parse.adoc
> +++ b/Documentation/git-rev-parse.adoc
> @@ -201,6 +201,7 @@ shown.  If the pattern does not contain a globbing
> character (`?`,
>  `*`, or `[`), it is turned into a prefix match by appending `/*`.
> 
>  --glob=<pattern>::
> +--glob <pattern>::
>  	Show all refs matching the shell glob pattern `pattern`. If
>  	the pattern does not start with `refs/`, this is automatically
>  	prepended.  If the pattern does not contain a globbing

This change is quite uncustomary, to the best of my knowledge we always
have the "=" there.

> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index 25a1e05714..56cc49c0f3 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -969,7 +969,12 @@ int cmd_rev_parse(int argc,
>  				handle_ref_opt(arg, "refs/tags/");
>  				continue;
>  			}
> -			if (skip_prefix(arg, "--glob=", &arg)) {
> +			if (opt_with_value(arg, "--glob", &arg)) {
> +				if (!arg) {
> +					arg = argv[++i];
> +					if (!arg || !strcmp(arg, "--"))
> +						die(_("--glob requires an argument"));
> +				}
>  				handle_ref_opt(arg, NULL);
>  				continue;
>  			}

None of the other options handle the argument with both " " and "=", as
far as I can see. So yes, we align this with how git-rev-list(1) works.
But at the same time we now make this option the only outlier in how
git-rev-parse(1) works.

So from my point of view this fix is too simplistic in its current form,
as I'd like to retain consistency inside git-rev-parse(1), too. And
honestly, the correct way to do that is to convert the command to use
our parse-options subsystem to parse its parameters, as that would now
align its option handling how all our other commands handle them.

That's a much bigger change, but I'm just not sure whether it really
makes sense to do a small localized change and punt on the bigger issue.

Thanks!

Patrick

      reply	other threads:[~2026-12-04 14:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:38 [PATCH] rev-parse: accept a separate pattern for --glob Christian Sagstetter
2026-12-04 14:26 ` Patrick Steinhardt [this message]

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=axLNjFCxEnJmeU0R@pks.im \
    --to=ps@pks.im \
    --cc=christian.sagstetter@gmail.com \
    --cc=git@vger.kernel.org \
    /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