mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
upload-pack: convert to use reference_get_peeled_oid()
The `write_v0_ref()` callback is invoked from two callsites:
- Once via `send_ref()` which is a callback passed to
`for_each_namespaced_ref_1()` and `refs_head_ref_namespaced()`.
- Once manually to announce capabilities.
When sending references to the client we also send the peeled value of
tags. As we don't have a `struct reference` available in the second
case, we cannot easily peel by calling `reference_get_peeled_oid()`, but
we instead have to depend on on global state via `peel_iterated_oid()`.
We do have a reference available though in the first case, it's only the
second case that keeps us from using `reference_get_peeled_oid()`. But
that second case only announces capabilities anyway, so we're not really
handling a reference at all here.
Adapt that case to construct a reference manually and pass that to
`write_v0_ref()`. Start to use `reference_get_peeled_oid()` now that we
always have a `struct reference` available.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
f898661637
commit
adecd5f0b6
@@ -1249,15 +1249,15 @@ static void format_session_id(struct strbuf *buf, struct upload_pack_data *d) {
|
||||
}
|
||||
|
||||
static void write_v0_ref(struct upload_pack_data *data,
|
||||
const char *refname, const char *refname_nons,
|
||||
const struct object_id *oid)
|
||||
const struct reference *ref,
|
||||
const char *refname_nons)
|
||||
{
|
||||
static const char *capabilities = "multi_ack thin-pack side-band"
|
||||
" side-band-64k ofs-delta shallow deepen-since deepen-not"
|
||||
" deepen-relative no-progress include-tag multi_ack_detailed";
|
||||
struct object_id peeled;
|
||||
|
||||
if (mark_our_ref(refname_nons, refname, oid, &data->hidden_refs))
|
||||
if (mark_our_ref(refname_nons, ref->name, ref->oid, &data->hidden_refs))
|
||||
return;
|
||||
|
||||
if (capabilities) {
|
||||
@@ -1267,7 +1267,7 @@ static void write_v0_ref(struct upload_pack_data *data,
|
||||
format_symref_info(&symref_info, &data->symref);
|
||||
format_session_id(&session_id, data);
|
||||
packet_fwrite_fmt(stdout, "%s %s%c%s%s%s%s%s%s%s object-format=%s agent=%s\n",
|
||||
oid_to_hex(oid), refname_nons,
|
||||
oid_to_hex(ref->oid), refname_nons,
|
||||
0, capabilities,
|
||||
(data->allow_uor & ALLOW_TIP_SHA1) ?
|
||||
" allow-tip-sha1-in-want" : "",
|
||||
@@ -1283,17 +1283,17 @@ static void write_v0_ref(struct upload_pack_data *data,
|
||||
strbuf_release(&session_id);
|
||||
data->sent_capabilities = 1;
|
||||
} else {
|
||||
packet_fwrite_fmt(stdout, "%s %s\n", oid_to_hex(oid), refname_nons);
|
||||
packet_fwrite_fmt(stdout, "%s %s\n", oid_to_hex(ref->oid), refname_nons);
|
||||
}
|
||||
capabilities = NULL;
|
||||
if (!peel_iterated_oid(the_repository, oid, &peeled))
|
||||
if (!reference_get_peeled_oid(the_repository, ref, &peeled))
|
||||
packet_fwrite_fmt(stdout, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
|
||||
return;
|
||||
}
|
||||
|
||||
static int send_ref(const struct reference *ref, void *cb_data)
|
||||
{
|
||||
write_v0_ref(cb_data, ref->name, strip_namespace(ref->name), ref->oid);
|
||||
write_v0_ref(cb_data, ref, strip_namespace(ref->name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1442,8 +1442,12 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
|
||||
send_ref, &data);
|
||||
for_each_namespaced_ref_1(send_ref, &data);
|
||||
if (!data.sent_capabilities) {
|
||||
const char *refname = "capabilities^{}";
|
||||
write_v0_ref(&data, refname, refname, null_oid(the_hash_algo));
|
||||
struct reference ref = {
|
||||
.name = "capabilities^{}",
|
||||
.oid = null_oid(the_hash_algo),
|
||||
};
|
||||
|
||||
write_v0_ref(&data, &ref, ref.name);
|
||||
}
|
||||
/*
|
||||
* fflush stdout before calling advertise_shallow_grafts because send_ref
|
||||
|
||||
Reference in New Issue
Block a user