shallow: rewrite functions to take object_id arguments
[gitweb.git] / transport.c
index 88bde1d85e48e7866881806d1ec3f1e3d420ab67..58cb9ed033b2b099e3e1100efbc6f437b4054c55 100644 (file)
@@ -283,7 +283,6 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
 {
        struct strbuf *buf = data;
        int len = buf->len;
-       FILE *f;
 
        /* when called via for_each_ref(), flags is non-zero */
        if (flags && !starts_with(name, "refs/heads/") &&
@@ -292,10 +291,9 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
 
        strbuf_addstr(buf, name);
        if (safe_create_leading_directories(buf->buf) ||
-                       !(f = fopen(buf->buf, "w")) ||
-                       fprintf(f, "%s\n", sha1_to_hex(sha1)) < 0 ||
-                       fclose(f))
-               return error("problems writing temporary file %s", buf->buf);
+           write_file(buf->buf, 0, "%s\n", sha1_to_hex(sha1)))
+               return error("problems writing temporary file %s: %s",
+                            buf->buf, strerror(errno));
        strbuf_setlen(buf, len);
        return 0;
 }
@@ -365,7 +363,10 @@ static int rsync_transport_push(struct transport *transport,
        strbuf_addch(&temp_dir, '/');
 
        if (flags & TRANSPORT_PUSH_ALL) {
-               if (for_each_ref(write_one_ref, &temp_dir))
+               struct each_ref_fn_sha1_adapter wrapped_write_one_ref =
+                       {write_one_ref, &temp_dir};
+
+               if (for_each_ref(each_ref_fn_adapter, &wrapped_write_one_ref))
                        return -1;
        } else if (write_refs_to_temp_dir(&temp_dir, refspec_nr, refspec))
                return -1;
@@ -730,6 +731,10 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count, i
                                                 ref->deletion ? NULL : ref->peer_ref,
                                                 "remote failed to report status", porcelain);
                break;
+       case REF_STATUS_ATOMIC_PUSH_FAILED:
+               print_ref_status('!', "[rejected]", ref, ref->peer_ref,
+                                                "atomic push failed", porcelain);
+               break;
        case REF_STATUS_OK:
                print_ok_ref_status(ref, porcelain);
                break;
@@ -828,6 +833,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
        args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN);
        args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);
        args.push_cert = !!(flags & TRANSPORT_PUSH_CERT);
+       args.atomic = !!(flags & TRANSPORT_PUSH_ATOMIC);
        args.url = transport->url;
 
        ret = send_pack(&args, data->fd, data->conn, remote_refs,