@matheusbsbs / matheus-bagliano / commits / dfe1b7f19c
Fork 0

transport-helper: new method reject_atomic_push()

Add new method in transport-helper to reject all references if any reference is failed for atomic push. This method is reused in "send-pack.c" and "transport-helper.c", one for SSH, git and file protocols, and the other for HTTP protocol. Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jiang Xin committed Apr 17, 2020 at 05:45 UTC dfe1b7f19c04fd10e9bafce91bc1da0c18bbb194
3 files changed +29 -41
send-pack.c
+3 -26
@@ -320,31 +320,6 @@ free_return:
320 return update_seen;
321 }
322
323 -
324 -static int atomic_push_failure(struct send_pack_args *args,
325 - struct ref *remote_refs,
326 - struct ref *failing_ref)
327 -{
328 - struct ref *ref;
329 - /* Mark other refs as failed */
330 - for (ref = remote_refs; ref; ref = ref->next) {
331 - if (!ref->peer_ref && !args->send_mirror)
332 - continue;
333 -
334 - switch (ref->status) {
335 - case REF_STATUS_NONE:
336 - case REF_STATUS_OK:
337 - case REF_STATUS_EXPECTING_REPORT:
338 - ref->status = REF_STATUS_ATOMIC_PUSH_FAILED;
339 - continue;
340 - default:
341 - break; /* do nothing */
342 - }
343 - }
344 - return error("atomic push failed for ref %s. status: %d\n",
345 - failing_ref->name, failing_ref->status);
346 -}
347 -
323 #define NONCE_LEN_LIMIT 256
324
325 static void reject_invalid_nonce(const char *nonce, int len)
@@ -489,7 +464,9 @@ int send_pack(struct send_pack_args *args,
464 if (use_atomic) {
465 strbuf_release(&req_buf);
466 strbuf_release(&cap_buf);
492 - atomic_push_failure(args, remote_refs, ref);
467 + reject_atomic_push(remote_refs, args->send_mirror);
468 + error("atomic push failed for ref %s. status: %d\n",
469 + ref->name, ref->status);
470 return args->porcelain ? 0 : -1;
471 }
472 /* else fallthrough */
transport-helper.c
+23 -15
@@ -894,21 +894,7 @@ static int push_refs_with_push(struct transport *transport,
894 case REF_STATUS_REJECT_STALE:
895 case REF_STATUS_REJECT_ALREADY_EXISTS:
896 if (atomic) {
897 - /* Mark other refs as failed */
898 - for (ref = remote_refs; ref; ref = ref->next) {
899 - if (!ref->peer_ref && !mirror)
900 - continue;
901 -
902 - switch (ref->status) {
903 - case REF_STATUS_NONE:
904 - case REF_STATUS_OK:
905 - case REF_STATUS_EXPECTING_REPORT:
906 - ref->status = REF_STATUS_ATOMIC_PUSH_FAILED;
907 - continue;
908 - default:
909 - break; /* do nothing */
910 - }
911 - }
897 + reject_atomic_push(remote_refs, mirror);
898 string_list_clear(&cas_options, 0);
899 return 0;
900 } else
@@ -1503,3 +1489,25 @@ int bidirectional_transfer_loop(int input, int output)
1489
1490 return tloop_spawnwait_tasks(&state);
1491 }
1492 +
1493 +void reject_atomic_push(struct ref *remote_refs, int mirror_mode)
1494 +{
1495 + struct ref *ref;
1496 +
1497 + /* Mark other refs as failed */
1498 + for (ref = remote_refs; ref; ref = ref->next) {
1499 + if (!ref->peer_ref && !mirror_mode)
1500 + continue;
1501 +
1502 + switch (ref->status) {
1503 + case REF_STATUS_NONE:
1504 + case REF_STATUS_OK:
1505 + case REF_STATUS_EXPECTING_REPORT:
1506 + ref->status = REF_STATUS_ATOMIC_PUSH_FAILED;
1507 + continue;
1508 + default:
1509 + break; /* do nothing */
1510 + }
1511 + }
1512 + return;
1513 +}
transport.h
+3
@@ -265,4 +265,7 @@ int transport_refs_pushed(struct ref *ref);
265 void transport_print_push_status(const char *dest, struct ref *refs,
266 int verbose, int porcelain, unsigned int *reject_reasons);
267
268 +/* common method used by transport-helper.c and send-pack.c */
269 +void reject_atomic_push(struct ref *refs, int mirror_mode);
270 +
271 #endif