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 <gitster@pobox.com>

Junio C Hamano committed Aug 15, 2014 at 12:29 UTC b783aa71c096032c02a20f9a41c5f42ce7b914c4
1 file changed +30 -19
send-pack.c
+30 -19
@@ -274,7 +274,8 @@ int send_pack(struct send_pack_args *args,
274 advertise_shallow_grafts_buf(&req_buf);
275
276 /*
277 - * Finally, tell the other end!
277 + * Clear the status for each ref and see if we need to send
278 + * the pack data.
279 */
280 for (ref = remote_refs; ref; ref = ref->next) {
281 if (!ref_update_to_be_sent(ref, args))
@@ -283,25 +284,35 @@ int send_pack(struct send_pack_args *args,
284 if (!ref->deletion)
285 need_pack_data = 1;
286
286 - if (args->dry_run) {
287 + if (args->dry_run || !status_report)
288 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++;
316 }
317
318 if (args->stateless_rpc) {