diff mbox series

[v3,5/6] revparse: add `--exclude-hidden=` option

Message ID 68a5e563045f1b3e6db7304206d95ebebcacbe6f.1667823042.git.ps@pks.im (mailing list archive)
State Superseded
Headers show
Series receive-pack: only use visible refs for connectivity check | expand

Commit Message

Patrick Steinhardt Nov. 7, 2022, 12:16 p.m. UTC
Add a new `--exclude-hidden=` option that is similar to the one we just
added to git-rev-list(1). Given a seciton name `transfer`, `uploadpack`
or `receive` as argument, it causes us to exclude all references that
would be hidden by the respective `$seciton.hideRefs` configuration.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Documentation/git-rev-parse.txt | 7 +++++++
 builtin/rev-parse.c             | 4 ++++
 t/t6018-rev-list-glob.sh        | 8 ++++++++
 3 files changed, 19 insertions(+)

Comments

Jeff King Nov. 8, 2022, 2:44 p.m. UTC | #1
On Mon, Nov 07, 2022 at 01:16:39PM +0100, Patrick Steinhardt wrote:

> Add a new `--exclude-hidden=` option that is similar to the one we just
> added to git-rev-list(1). Given a seciton name `transfer`, `uploadpack`
> or `receive` as argument, it causes us to exclude all references that
> would be hidden by the respective `$seciton.hideRefs` configuration.

Thanks for adding this one in. I feel like rev-parse isn't used all that
much these days, and in a sense, we could just let it fall behind what
rev-list could do and probably nobody would care. But since it's only a
few lines, keeping parity with rev-list is nice to have.

-Peff
diff mbox series

Patch

diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 6b8ca085aa..a016cb5abe 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -197,6 +197,13 @@  respectively, and they must begin with `refs/` when applied to `--glob`
 or `--all`. If a trailing '/{asterisk}' is intended, it must be given
 explicitly.
 
+--exclude-hidden=[transfer|receive|uploadpack]::
+	Do not include refs that have been hidden via either one of
+	`transfer.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs` that
+	the next `--all`, `--branches`, `--tags`, `--remotes` or `--glob` would
+	otherwise consider.  This option is cleared when seeing one of these
+	pseudo-refs.
+
 --disambiguate=<prefix>::
 	Show every object whose name begins with the given prefix.
 	The <prefix> must be at least 4 hexadecimal digits long to
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 7fa5b6991b..49730c7a23 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -895,6 +895,10 @@  int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				add_ref_exclusion(&ref_excludes, arg);
 				continue;
 			}
+			if (skip_prefix(arg, "--exclude-hidden=", &arg)) {
+				exclude_hidden_refs(&ref_excludes, arg);
+				continue;
+			}
 			if (!strcmp(arg, "--show-toplevel")) {
 				const char *work_tree = get_git_work_tree();
 				if (work_tree)
diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh
index e1abc5c2b3..f92616de12 100755
--- a/t/t6018-rev-list-glob.sh
+++ b/t/t6018-rev-list-glob.sh
@@ -187,6 +187,14 @@  test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
 	compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
 '
 
+test_expect_success 'rev-parse --exclude-hidden= with --all' '
+	compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--exclude-hidden=transfer --all" "--branches --tags"
+'
+
+test_expect_success 'rev-parse --exclude-hidden= with --all' '
+	compare "-c transfer.hideRefs=refs/heads/subspace/ rev-parse" "--exclude-hidden=transfer --all" "--exclude=refs/heads/subspace/* --all"
+'
+
 test_expect_success 'rev-list --exclude=glob with --branches=glob' '
 	compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
 '