]> git.ipfire.org Git - thirdparty/git.git/blobdiff - http-push.c
Merge branch 'bc/sha-256-part-2'
[thirdparty/git.git] / http-push.c
index 5eaf551b51e7aaf87219d4af0ca19873484c90ca..ac7868ffeef5151a9dcc9fa2382d882f88e71aa6 100644 (file)
@@ -14,7 +14,7 @@
 #include "argv-array.h"
 #include "packfile.h"
 #include "object-store.h"
-
+#include "commit-reach.h"
 
 #ifdef EXPAT_NEEDS_XMLPARSE_H
 #include <xmlparse.h>
@@ -117,6 +117,7 @@ enum transfer_state {
 
 struct transfer_request {
        struct object *obj;
+       struct packed_git *target;
        char *url;
        char *dest;
        struct remote_lock *lock;
@@ -145,7 +146,7 @@ struct remote_lock {
        char *url;
        char *owner;
        char *token;
-       char tmpfile_suffix[41];
+       char tmpfile_suffix[GIT_MAX_HEXSZ + 1];
        time_t start_time;
        long timeout;
        int refreshing;
@@ -255,7 +256,7 @@ static void start_fetch_loose(struct transfer_request *request)
        struct active_request_slot *slot;
        struct http_object_request *obj_req;
 
-       obj_req = new_http_object_request(repo->url, request->obj->oid.hash);
+       obj_req = new_http_object_request(repo->url, &request->obj->oid);
        if (obj_req == NULL) {
                request->state = ABORTED;
                return;
@@ -314,16 +315,18 @@ static void start_fetch_packed(struct transfer_request *request)
                release_request(request);
                return;
        }
+       close_pack_index(target);
+       request->target = target;
 
-       fprintf(stderr, "Fetching pack %s\n", sha1_to_hex(target->sha1));
+       fprintf(stderr, "Fetching pack %s\n",
+               hash_to_hex(target->hash));
        fprintf(stderr, " which contains %s\n", oid_to_hex(&request->obj->oid));
 
-       preq = new_http_pack_request(target, repo->url);
+       preq = new_http_pack_request(target->hash, repo->url);
        if (preq == NULL) {
                repo->can_update_info_refs = 0;
                return;
        }
-       preq->lst = &repo->packs;
 
        /* Make sure there isn't another open request for this pack */
        while (check_request) {
@@ -365,7 +368,7 @@ static void start_put(struct transfer_request *request)
        git_zstream stream;
 
        unpacked = read_object_file(&request->obj->oid, &type, &len);
-       hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
+       hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
 
        /* Set it up */
        git_deflate_init(&stream, zlib_compression_level);
@@ -398,7 +401,7 @@ static void start_put(struct transfer_request *request)
        request->dest = strbuf_detach(&buf, NULL);
 
        append_remote_object_url(&buf, repo->url, hex, 0);
-       strbuf_add(&buf, request->lock->tmpfile_suffix, 41);
+       strbuf_add(&buf, request->lock->tmpfile_suffix, the_hash_algo->hexsz + 1);
        request->url = strbuf_detach(&buf, NULL);
 
        slot = get_active_slot();
@@ -500,10 +503,10 @@ static void release_request(struct transfer_request *request)
        if (request == request_queue_head) {
                request_queue_head = request->next;
        } else {
-               while (entry->next != NULL && entry->next != request)
+               while (entry && entry->next != request)
                        entry = entry->next;
-               if (entry->next == request)
-                       entry->next = entry->next->next;
+               if (entry)
+                       entry->next = request->next;
        }
 
        free(request->url);
@@ -525,8 +528,8 @@ static void finish_request(struct transfer_request *request)
        if (request->headers != NULL)
                curl_slist_free_all(request->headers);
 
-       /* URL is reused for MOVE after PUT */
-       if (request->state != RUN_PUT) {
+       /* URL is reused for MOVE after PUT and used during FETCH */
+       if (request->state != RUN_PUT && request->state != RUN_FETCH_PACKED) {
                FREE_AND_NULL(request->url);
        }
 
@@ -596,6 +599,8 @@ static void finish_request(struct transfer_request *request)
                }
                if (fail)
                        repo->can_update_info_refs = 0;
+               else
+                       http_install_packfile(request->target, &repo->packs);
                release_request(request);
        }
 }
@@ -722,7 +727,7 @@ static void one_remote_object(const struct object_id *oid)
 {
        struct object *obj;
 
-       obj = lookup_object(the_repository, oid->hash);
+       obj = lookup_object(the_repository, oid);
        if (!obj)
                obj = parse_object(the_repository, oid);
 
@@ -757,8 +762,8 @@ static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed)
 static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
 {
        struct remote_lock *lock = (struct remote_lock *)ctx->userData;
-       git_SHA_CTX sha_ctx;
-       unsigned char lock_token_sha1[20];
+       git_hash_ctx hash_ctx;
+       unsigned char lock_token_hash[GIT_MAX_RAWSZ];
 
        if (tag_closed && ctx->cdata) {
                if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) {
@@ -770,12 +775,12 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
                } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
                        lock->token = xstrdup(ctx->cdata);
 
-                       git_SHA1_Init(&sha_ctx);
-                       git_SHA1_Update(&sha_ctx, lock->token, strlen(lock->token));
-                       git_SHA1_Final(lock_token_sha1, &sha_ctx);
+                       the_hash_algo->init_fn(&hash_ctx);
+                       the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token));
+                       the_hash_algo->final_fn(lock_token_hash, &hash_ctx);
 
                        lock->tmpfile_suffix[0] = '_';
-                       memcpy(lock->tmpfile_suffix + 1, sha1_to_hex(lock_token_sha1), 40);
+                       memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz);
                }
        }
 }
@@ -980,7 +985,7 @@ static int unlock_remote(struct remote_lock *lock)
                while (prev && prev->next != lock)
                        prev = prev->next;
                if (prev)
-                       prev->next = prev->next->next;
+                       prev->next = lock->next;
        }
 
        free(lock->owner);
@@ -1017,7 +1022,7 @@ static void remote_ls(const char *path, int flags,
 /* extract hex from sharded "xx/x{38}" filename */
 static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
 {
-       if (strlen(path) != GIT_SHA1_HEXSZ + 1)
+       if (strlen(path) != the_hash_algo->hexsz + 1)
                return -1;
 
        if (hex_to_bytes(oid->hash, path, 1))
@@ -1025,7 +1030,7 @@ static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
        path += 2;
        path++; /* skip '/' */
 
-       return hex_to_bytes(oid->hash + 1, path, GIT_SHA1_RAWSZ - 1);
+       return hex_to_bytes(oid->hash + 1, path, the_hash_algo->rawsz - 1);
 }
 
 static void process_ls_object(struct remote_ls_ctx *ls)
@@ -1311,11 +1316,11 @@ static struct object_list **process_tree(struct tree *tree,
        while (tree_entry(&desc, &entry))
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       p = process_tree(lookup_tree(the_repository, entry.oid),
+                       p = process_tree(lookup_tree(the_repository, &entry.oid),
                                         p);
                        break;
                case OBJ_BLOB:
-                       p = process_blob(lookup_blob(the_repository, entry.oid),
+                       p = process_blob(lookup_blob(the_repository, &entry.oid),
                                         p);
                        break;
                default:
@@ -1373,7 +1378,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
        return count;
 }
 
-static int update_remote(unsigned char *sha1, struct remote_lock *lock)
+static int update_remote(const struct object_id *oid, struct remote_lock *lock)
 {
        struct active_request_slot *slot;
        struct slot_results results;
@@ -1382,7 +1387,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
 
        dav_headers = get_dav_token_headers(lock, DAV_HEADER_IF);
 
-       strbuf_addf(&out_buffer.buf, "%s\n", sha1_to_hex(sha1));
+       strbuf_addf(&out_buffer.buf, "%s\n", oid_to_hex(oid));
 
        slot = get_active_slot();
        slot->results = &results;
@@ -1431,7 +1436,7 @@ static void one_remote_ref(const char *refname)
         * may be required for updating server info later.
         */
        if (repo->can_update_info_refs && !has_object_file(&ref->old_oid)) {
-               obj = lookup_unknown_object(ref->old_oid.hash);
+               obj = lookup_unknown_object(&ref->old_oid);
                fprintf(stderr, "  fetch %s for %s\n",
                        oid_to_hex(&ref->old_oid), refname);
                add_fetch_request(obj);
@@ -1859,7 +1864,7 @@ int cmd_main(int argc, const char **argv)
                        continue;
                }
 
-               if (!oidcmp(&ref->old_oid, &ref->peer_ref->new_oid)) {
+               if (oideq(&ref->old_oid, &ref->peer_ref->new_oid)) {
                        if (push_verbosely)
                                fprintf(stderr, "'%s': up-to-date\n", ref->name);
                        if (helper_status)
@@ -1925,7 +1930,7 @@ int cmd_main(int argc, const char **argv)
                if (!push_all && !is_null_oid(&ref->old_oid))
                        argv_array_pushf(&commit_argv, "^%s",
                                         oid_to_hex(&ref->old_oid));
-               init_revisions(&revs, setup_git_directory());
+               repo_init_revisions(the_repository, &revs, setup_git_directory());
                setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL);
                revs.edge_hint = 0; /* just in case */
 
@@ -1933,7 +1938,7 @@ int cmd_main(int argc, const char **argv)
                pushing = 0;
                if (prepare_revision_walk(&revs))
                        die("revision walk setup failed");
-               mark_edges_uninteresting(&revs, NULL);
+               mark_edges_uninteresting(&revs, NULL, 0);
                objects_to_send = get_delta(&revs, ref_lock);
                finish_all_active_slots();
 
@@ -1947,7 +1952,7 @@ int cmd_main(int argc, const char **argv)
                run_request_queue();
 
                /* Update the remote branch if all went well */
-               if (aborted || !update_remote(ref->new_oid.hash, ref_lock))
+               if (aborted || !update_remote(&ref->new_oid, ref_lock))
                        rc = 1;
 
                if (!rc)