Skip to content

Commit b783aa7

Browse files
committed
send-pack: refactor inspecting and resetting status and sending commands
The main loop over remote_refs list inspects the ref status to see if we need to generate pack data (i.e. a delete-only push does not need to send any additional data), resets it to "expecting the status report" state, and formats the actual update commands to be sent. Split the former two out of the main loop, as it will become conditional in later steps. Besides, we should have code that does real thing here, before the "Finally, tell the other end!" part ;-) Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab2b0c9 commit b783aa7

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

send-pack.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ int send_pack(struct send_pack_args *args,
274274
advertise_shallow_grafts_buf(&req_buf);
275275

276276
/*
277-
* Finally, tell the other end!
277+
* Clear the status for each ref and see if we need to send
278+
* the pack data.
278279
*/
279280
for (ref = remote_refs; ref; ref = ref->next) {
280281
if (!ref_update_to_be_sent(ref, args))
@@ -283,25 +284,35 @@ int send_pack(struct send_pack_args *args,
283284
if (!ref->deletion)
284285
need_pack_data = 1;
285286

286-
if (args->dry_run) {
287+
if (args->dry_run || !status_report)
287288
ref->status = REF_STATUS_OK;
288-
} else {
289-
char *old_hex = sha1_to_hex(ref->old_sha1);
290-
char *new_hex = sha1_to_hex(ref->new_sha1);
291-
292-
if (!cmds_sent)
293-
packet_buf_write(&req_buf,
294-
"%s %s %s%c%s",
295-
old_hex, new_hex, ref->name, 0,
296-
cap_buf.buf);
297-
else
298-
packet_buf_write(&req_buf, "%s %s %s",
299-
old_hex, new_hex, ref->name);
300-
ref->status = status_report ?
301-
REF_STATUS_EXPECTING_REPORT :
302-
REF_STATUS_OK;
303-
cmds_sent++;
304-
}
289+
else
290+
ref->status = REF_STATUS_EXPECTING_REPORT;
291+
}
292+
293+
/*
294+
* Finally, tell the other end!
295+
*/
296+
for (ref = remote_refs; ref; ref = ref->next) {
297+
char *old_hex, *new_hex;
298+
299+
if (args->dry_run)
300+
continue;
301+
302+
if (!ref_update_to_be_sent(ref, args))
303+
continue;
304+
305+
old_hex = sha1_to_hex(ref->old_sha1);
306+
new_hex = sha1_to_hex(ref->new_sha1);
307+
if (!cmds_sent)
308+
packet_buf_write(&req_buf,
309+
"%s %s %s%c%s",
310+
old_hex, new_hex, ref->name, 0,
311+
cap_buf.buf);
312+
else
313+
packet_buf_write(&req_buf, "%s %s %s",
314+
old_hex, new_hex, ref->name);
315+
cmds_sent++;
305316
}
306317

307318
if (args->stateless_rpc) {

0 commit comments

Comments
 (0)