Skip to content

Commit d3b0178

Browse files
committed
Merge branch 'jk/proto-v2-hidden-refs-fix'
The v2 upload-pack protocol implementation failed to honor hidden-ref configuration, which has been corrected. An earlier attempt reverted out of 'next'. * jk/proto-v2-hidden-refs-fix: upload-pack: support hidden refs with protocol v2
2 parents 773e408 + e20b419 commit d3b0178

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ls-refs.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "argv-array.h"
66
#include "ls-refs.h"
77
#include "pkt-line.h"
8+
#include "config.h"
89

910
/*
1011
* Check if one of the prefixes is a prefix of the ref.
@@ -40,6 +41,9 @@ static int send_ref(const char *refname, const struct object_id *oid,
4041
const char *refname_nons = strip_namespace(refname);
4142
struct strbuf refline = STRBUF_INIT;
4243

44+
if (ref_is_hidden(refname_nons, refname))
45+
return 0;
46+
4347
if (!ref_match(&data->prefixes, refname))
4448
return 0;
4549

@@ -69,13 +73,25 @@ static int send_ref(const char *refname, const struct object_id *oid,
6973
return 0;
7074
}
7175

76+
static int ls_refs_config(const char *var, const char *value, void *data)
77+
{
78+
/*
79+
* We only serve fetches over v2 for now, so respect only "uploadpack"
80+
* config. This may need to eventually be expanded to "receive", but we
81+
* don't yet know how that information will be passed to ls-refs.
82+
*/
83+
return parse_hide_refs_config(var, value, "uploadpack");
84+
}
85+
7286
int ls_refs(struct repository *r, struct argv_array *keys,
7387
struct packet_reader *request)
7488
{
7589
struct ls_refs_data data;
7690

7791
memset(&data, 0, sizeof(data));
7892

93+
git_config(ls_refs_config, NULL);
94+
7995
while (packet_reader_read(request) != PACKET_READ_FLUSH) {
8096
const char *arg = request->line;
8197
const char *out;

t/t5512-ls-remote.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
204204
grep refs/tags/magic actual
205205
'
206206

207+
test_expect_success 'protocol v2 supports hiderefs' '
208+
test_config uploadpack.hiderefs refs/tags &&
209+
git -c protocol.version=2 ls-remote . >actual &&
210+
! grep refs/tags actual
211+
'
212+
207213
test_expect_success 'ls-remote --symref' '
208214
git fetch origin &&
209215
cat >expect <<-EOF &&

0 commit comments

Comments
 (0)