зеркало из https://github.com/microsoft/git.git
upload-pack: support hidden refs with protocol v2
In the v2 protocol, upload-pack's advertisement has been moved to the "ls-refs" command. That command does not respect hidden-ref config (like transfer.hiderefs) at all, and advertises everything. While there are some features that are not supported in v2 (e.g., v2 always allows fetching any sha1 without respect to advertisements), the lack of this feature is not documented and is likely just a bug. Let's make it work, as otherwise upgrading a server to a v2-capable git will start exposing these refs that the repository admin has asked to remain hidden. Note that we assume we're operating on behalf of a fetch here, since that's the only thing implemented in v2 at this point. See the in-code comment. We'll have to figure out how this works when the v2 push protocol is designed (both here in ls-refs, but also rejecting updates to hidden refs). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
98cdfbb84a
Коммит
e20b4192a3
16
ls-refs.c
16
ls-refs.c
|
@ -5,6 +5,7 @@
|
|||
#include "argv-array.h"
|
||||
#include "ls-refs.h"
|
||||
#include "pkt-line.h"
|
||||
#include "config.h"
|
||||
|
||||
/*
|
||||
* 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,
|
|||
const char *refname_nons = strip_namespace(refname);
|
||||
struct strbuf refline = STRBUF_INIT;
|
||||
|
||||
if (ref_is_hidden(refname_nons, refname))
|
||||
return 0;
|
||||
|
||||
if (!ref_match(&data->prefixes, refname))
|
||||
return 0;
|
||||
|
||||
|
@ -69,6 +73,16 @@ static int send_ref(const char *refname, const struct object_id *oid,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int ls_refs_config(const char *var, const char *value, void *data)
|
||||
{
|
||||
/*
|
||||
* We only serve fetches over v2 for now, so respect only "uploadpack"
|
||||
* config. This may need to eventually be expanded to "receive", but we
|
||||
* don't yet know how that information will be passed to ls-refs.
|
||||
*/
|
||||
return parse_hide_refs_config(var, value, "uploadpack");
|
||||
}
|
||||
|
||||
int ls_refs(struct repository *r, struct argv_array *keys,
|
||||
struct packet_reader *request)
|
||||
{
|
||||
|
@ -76,6 +90,8 @@ int ls_refs(struct repository *r, struct argv_array *keys,
|
|||
|
||||
memset(&data, 0, sizeof(data));
|
||||
|
||||
git_config(ls_refs_config, NULL);
|
||||
|
||||
while (packet_reader_read(request) != PACKET_READ_FLUSH) {
|
||||
const char *arg = request->line;
|
||||
const char *out;
|
||||
|
|
|
@ -204,6 +204,12 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs'
|
|||
grep refs/tags/magic actual
|
||||
'
|
||||
|
||||
test_expect_success 'protocol v2 supports hiderefs' '
|
||||
test_config uploadpack.hiderefs refs/tags &&
|
||||
git -c protocol.version=2 ls-remote . >actual &&
|
||||
! grep refs/tags actual
|
||||
'
|
||||
|
||||
test_expect_success 'ls-remote --symref' '
|
||||
git fetch origin &&
|
||||
cat >expect <<-EOF &&
|
||||
|
|
Загрузка…
Ссылка в новой задаче