]> git.ipfire.org Git - thirdparty/git.git/commitdiff
transport-helper: new method reject_atomic_push()
authorJiang Xin <zhiyou.jx@alibaba-inc.com>
Fri, 17 Apr 2020 09:45:36 +0000 (05:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Apr 2020 19:16:32 +0000 (12:16 -0700)
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>
send-pack.c
transport-helper.c
transport.h

index efefb687b2da1329679eed01d62b5db3990ad907..a7c53193c90599429d968eb7022c7b21e8dab6bf 100644 (file)
@@ -320,31 +320,6 @@ free_return:
        return update_seen;
 }
 
-
-static int atomic_push_failure(struct send_pack_args *args,
-                              struct ref *remote_refs,
-                              struct ref *failing_ref)
-{
-       struct ref *ref;
-       /* Mark other refs as failed */
-       for (ref = remote_refs; ref; ref = ref->next) {
-               if (!ref->peer_ref && !args->send_mirror)
-                       continue;
-
-               switch (ref->status) {
-               case REF_STATUS_NONE:
-               case REF_STATUS_OK:
-               case REF_STATUS_EXPECTING_REPORT:
-                       ref->status = REF_STATUS_ATOMIC_PUSH_FAILED;
-                       continue;
-               default:
-                       break; /* do nothing */
-               }
-       }
-       return error("atomic push failed for ref %s. status: %d\n",
-                    failing_ref->name, failing_ref->status);
-}
-
 #define NONCE_LEN_LIMIT 256
 
 static void reject_invalid_nonce(const char *nonce, int len)
@@ -489,7 +464,9 @@ int send_pack(struct send_pack_args *args,
                        if (use_atomic) {
                                strbuf_release(&req_buf);
                                strbuf_release(&cap_buf);
-                               atomic_push_failure(args, remote_refs, ref);
+                               reject_atomic_push(remote_refs, args->send_mirror);
+                               error("atomic push failed for ref %s. status: %d\n",
+                                     ref->name, ref->status);
                                return args->porcelain ? 0 : -1;
                        }
                        /* else fallthrough */
index ab3b52eb1451131e8af84857f7e4bcda829670a9..a46afcb69db615d2f8917f852db28c3dca501de0 100644 (file)
@@ -894,21 +894,7 @@ static int push_refs_with_push(struct transport *transport,
                case REF_STATUS_REJECT_STALE:
                case REF_STATUS_REJECT_ALREADY_EXISTS:
                        if (atomic) {
-                               /* Mark other refs as failed */
-                               for (ref = remote_refs; ref; ref = ref->next) {
-                                       if (!ref->peer_ref && !mirror)
-                                               continue;
-
-                                       switch (ref->status) {
-                                       case REF_STATUS_NONE:
-                                       case REF_STATUS_OK:
-                                       case REF_STATUS_EXPECTING_REPORT:
-                                               ref->status = REF_STATUS_ATOMIC_PUSH_FAILED;
-                                               continue;
-                                       default:
-                                               break; /* do nothing */
-                                       }
-                               }
+                               reject_atomic_push(remote_refs, mirror);
                                string_list_clear(&cas_options, 0);
                                return 0;
                        } else
@@ -1503,3 +1489,25 @@ int bidirectional_transfer_loop(int input, int output)
 
        return tloop_spawnwait_tasks(&state);
 }
+
+void reject_atomic_push(struct ref *remote_refs, int mirror_mode)
+{
+       struct ref *ref;
+
+       /* Mark other refs as failed */
+       for (ref = remote_refs; ref; ref = ref->next) {
+               if (!ref->peer_ref && !mirror_mode)
+                       continue;
+
+               switch (ref->status) {
+               case REF_STATUS_NONE:
+               case REF_STATUS_OK:
+               case REF_STATUS_EXPECTING_REPORT:
+                       ref->status = REF_STATUS_ATOMIC_PUSH_FAILED;
+                       continue;
+               default:
+                       break; /* do nothing */
+               }
+       }
+       return;
+}
index e0131daab987f582801972fe84aa412d235c89f7..4298c855be66bb41c41053a1ca9fced7b077a389 100644 (file)
@@ -265,4 +265,7 @@ int transport_refs_pushed(struct ref *ref);
 void transport_print_push_status(const char *dest, struct ref *refs,
                  int verbose, int porcelain, unsigned int *reject_reasons);
 
+/* common method used by transport-helper.c and send-pack.c */
+void reject_atomic_push(struct ref *refs, int mirror_mode);
+
 #endif