All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rev-parse: accept a separate pattern for --glob
@ 2026-12-04 13:38 Christian Sagstetter
  2026-12-04 14:26 ` Patrick Steinhardt
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Sagstetter @ 2026-12-04 13:38 UTC (permalink / raw)
  To: git

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.

Signed-off-by: Christian Sagstetter <christian.sagstetter@gmail.com>
---
 Documentation/git-rev-parse.adoc |  1 +
 builtin/rev-parse.c              |  7 ++++++-
 t/t6018-rev-list-glob.sh         | 11 +++++++++--
 3 files changed, 16 insertions(+), 3 deletions(-)

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
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;
 			}
diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh
index bb55c7e3c3..e9022554e2 100755
--- a/t/t6018-rev-list-glob.sh
+++ b/t/t6018-rev-list-glob.sh
@@ -78,18 +78,25 @@ test_expect_success 'rev-parse --glob=heads/subspace' '

 '

-test_expect_failure 'rev-parse accepts --glob as detached option' '
+test_expect_success 'rev-parse accepts --glob as detached option' '

 	compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"

 '

-test_expect_failure 'rev-parse is not confused by option-like glob' '
+test_expect_success 'rev-parse is not confused by option-like glob' '

 	compare rev-parse "main" "--glob --symbolic main"

 '

+test_expect_success 'rev-parse --glob requires a pattern' '
+	test_must_fail git rev-parse --glob 2>err &&
+	test_grep "glob requires an argument" err &&
+	test_must_fail git rev-parse --glob -- foo 2>err &&
+	test_grep "glob requires an argument" err
+'
+
 test_expect_success 'rev-parse --branches=subspace/*' '

 	compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"

base-commit: 566b6997dd4710b625c0882cf10a7443bf52d183
-- 
2.53.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rev-parse: accept a separate pattern for --glob
  2026-12-04 13:38 [PATCH] rev-parse: accept a separate pattern for --glob Christian Sagstetter
@ 2026-12-04 14:26 ` Patrick Steinhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Steinhardt @ 2026-12-04 14:26 UTC (permalink / raw)
  To: Christian Sagstetter; +Cc: git

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 13:38 [PATCH] rev-parse: accept a separate pattern for --glob Christian Sagstetter
2026-12-04 14:26 ` Patrick Steinhardt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.