Skip to content

Commit 859a7db

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0dd7657 commit 859a7db

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

upload-pack.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,15 +1249,15 @@ static void format_session_id(struct strbuf *buf, struct upload_pack_data *d) {
12491249
}
12501250

12511251
static void write_v0_ref(struct upload_pack_data *data,
1252-
const char *refname, const char *refname_nons,
1253-
const struct object_id *oid)
1252+
const struct reference *ref,
1253+
const char *refname_nons)
12541254
{
12551255
static const char *capabilities = "multi_ack thin-pack side-band"
12561256
" side-band-64k ofs-delta shallow deepen-since deepen-not"
12571257
" deepen-relative no-progress include-tag multi_ack_detailed";
12581258
struct object_id peeled;
12591259

1260-
if (mark_our_ref(refname_nons, refname, oid, &data->hidden_refs))
1260+
if (mark_our_ref(refname_nons, ref->name, ref->oid, &data->hidden_refs))
12611261
return;
12621262

12631263
if (capabilities) {
@@ -1267,7 +1267,7 @@ static void write_v0_ref(struct upload_pack_data *data,
12671267
format_symref_info(&symref_info, &data->symref);
12681268
format_session_id(&session_id, data);
12691269
packet_fwrite_fmt(stdout, "%s %s%c%s%s%s%s%s%s%s object-format=%s agent=%s\n",
1270-
oid_to_hex(oid), refname_nons,
1270+
oid_to_hex(ref->oid), refname_nons,
12711271
0, capabilities,
12721272
(data->allow_uor & ALLOW_TIP_SHA1) ?
12731273
" allow-tip-sha1-in-want" : "",
@@ -1283,17 +1283,17 @@ static void write_v0_ref(struct upload_pack_data *data,
12831283
strbuf_release(&session_id);
12841284
data->sent_capabilities = 1;
12851285
} else {
1286-
packet_fwrite_fmt(stdout, "%s %s\n", oid_to_hex(oid), refname_nons);
1286+
packet_fwrite_fmt(stdout, "%s %s\n", oid_to_hex(ref->oid), refname_nons);
12871287
}
12881288
capabilities = NULL;
1289-
if (!peel_iterated_oid(the_repository, oid, &peeled))
1289+
if (!reference_get_peeled_oid(the_repository, ref, &peeled))
12901290
packet_fwrite_fmt(stdout, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
12911291
return;
12921292
}
12931293

12941294
static int send_ref(const struct reference *ref, void *cb_data)
12951295
{
1296-
write_v0_ref(cb_data, ref->name, strip_namespace(ref->name), ref->oid);
1296+
write_v0_ref(cb_data, ref, strip_namespace(ref->name));
12971297
return 0;
12981298
}
12991299

@@ -1442,8 +1442,12 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
14421442
send_ref, &data);
14431443
for_each_namespaced_ref_1(send_ref, &data);
14441444
if (!data.sent_capabilities) {
1445-
const char *refname = "capabilities^{}";
1446-
write_v0_ref(&data, refname, refname, null_oid(the_hash_algo));
1445+
struct reference ref = {
1446+
.name = "capabilities^{}",
1447+
.oid = null_oid(the_hash_algo),
1448+
};
1449+
1450+
write_v0_ref(&data, &ref, ref.name);
14471451
}
14481452
/*
14491453
* fflush stdout before calling advertise_shallow_grafts because send_ref

0 commit comments

Comments
 (0)