fsck_commit_buffer(): do not special case the last validation
[gitweb.git] / http-push.c
index 48f39b7f71c632aae6a42d65be929a9e44874d84..bd60668707b956160edd9fb22767758023571ebb 100644 (file)
@@ -251,7 +251,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->sha1);
+       obj_req = new_http_object_request(repo->url, request->obj->oid.hash);
        if (obj_req == NULL) {
                request->state = ABORTED;
                return;
@@ -275,7 +275,7 @@ static void start_fetch_loose(struct transfer_request *request)
 
 static void start_mkcol(struct transfer_request *request)
 {
-       char *hex = sha1_to_hex(request->obj->sha1);
+       char *hex = oid_to_hex(&request->obj->oid);
        struct active_request_slot *slot;
 
        request->url = get_remote_object_url(repo->url, hex, 1);
@@ -304,16 +304,16 @@ static void start_fetch_packed(struct transfer_request *request)
        struct transfer_request *check_request = request_queue_head;
        struct http_pack_request *preq;
 
-       target = find_sha1_pack(request->obj->sha1, repo->packs);
+       target = find_sha1_pack(request->obj->oid.hash, repo->packs);
        if (!target) {
-               fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", sha1_to_hex(request->obj->sha1));
+               fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", oid_to_hex(&request->obj->oid));
                repo->can_update_info_refs = 0;
                release_request(request);
                return;
        }
 
        fprintf(stderr, "Fetching pack %s\n", sha1_to_hex(target->sha1));
-       fprintf(stderr, " which contains %s\n", sha1_to_hex(request->obj->sha1));
+       fprintf(stderr, " which contains %s\n", oid_to_hex(&request->obj->oid));
 
        preq = new_http_pack_request(target, repo->url);
        if (preq == NULL) {
@@ -350,7 +350,7 @@ static void start_fetch_packed(struct transfer_request *request)
 
 static void start_put(struct transfer_request *request)
 {
-       char *hex = sha1_to_hex(request->obj->sha1);
+       char *hex = oid_to_hex(&request->obj->oid);
        struct active_request_slot *slot;
        struct strbuf buf = STRBUF_INIT;
        enum object_type type;
@@ -361,7 +361,7 @@ static void start_put(struct transfer_request *request)
        ssize_t size;
        git_zstream stream;
 
-       unpacked = read_sha1_file(request->obj->sha1, &type, &len);
+       unpacked = read_sha1_file(request->obj->oid.hash, &type, &len);
        hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), len) + 1;
 
        /* Set it up */
@@ -533,11 +533,11 @@ static void finish_request(struct transfer_request *request)
        if (request->state == RUN_MKCOL) {
                if (request->curl_result == CURLE_OK ||
                    request->http_code == 405) {
-                       remote_dir_exists[request->obj->sha1[0]] = 1;
+                       remote_dir_exists[request->obj->oid.hash[0]] = 1;
                        start_put(request);
                } else {
                        fprintf(stderr, "MKCOL %s failed, aborting (%d/%ld)\n",
-                               sha1_to_hex(request->obj->sha1),
+                               oid_to_hex(&request->obj->oid),
                                request->curl_result, request->http_code);
                        request->state = ABORTED;
                        aborted = 1;
@@ -547,7 +547,7 @@ static void finish_request(struct transfer_request *request)
                        start_move(request);
                } else {
                        fprintf(stderr, "PUT %s failed, aborting (%d/%ld)\n",
-                               sha1_to_hex(request->obj->sha1),
+                               oid_to_hex(&request->obj->oid),
                                request->curl_result, request->http_code);
                        request->state = ABORTED;
                        aborted = 1;
@@ -556,12 +556,12 @@ static void finish_request(struct transfer_request *request)
                if (request->curl_result == CURLE_OK) {
                        if (push_verbosely)
                                fprintf(stderr, "    sent %s\n",
-                                       sha1_to_hex(request->obj->sha1));
+                                       oid_to_hex(&request->obj->oid));
                        request->obj->flags |= REMOTE;
                        release_request(request);
                } else {
                        fprintf(stderr, "MOVE %s failed, aborting (%d/%ld)\n",
-                               sha1_to_hex(request->obj->sha1),
+                               oid_to_hex(&request->obj->oid),
                                request->curl_result, request->http_code);
                        request->state = ABORTED;
                        aborted = 1;
@@ -614,7 +614,7 @@ static int fill_active_slot(void *unused)
                        start_fetch_loose(request);
                        return 1;
                } else if (pushing && request->state == NEED_PUSH) {
-                       if (remote_dir_exists[request->obj->sha1[0]] == 1) {
+                       if (remote_dir_exists[request->obj->oid.hash[0]] == 1) {
                                start_put(request);
                        } else {
                                start_mkcol(request);
@@ -638,8 +638,8 @@ static void add_fetch_request(struct object *obj)
         * Don't fetch the object if it's known to exist locally
         * or is already in the request queue
         */
-       if (remote_dir_exists[obj->sha1[0]] == -1)
-               get_remote_object_list(obj->sha1[0]);
+       if (remote_dir_exists[obj->oid.hash[0]] == -1)
+               get_remote_object_list(obj->oid.hash[0]);
        if (obj->flags & (LOCAL | FETCHING))
                return;
 
@@ -671,11 +671,11 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
         * Don't push the object if it's known to exist on the remote
         * or is already in the request queue
         */
-       if (remote_dir_exists[obj->sha1[0]] == -1)
-               get_remote_object_list(obj->sha1[0]);
+       if (remote_dir_exists[obj->oid.hash[0]] == -1)
+               get_remote_object_list(obj->oid.hash[0]);
        if (obj->flags & (REMOTE | PUSHING))
                return 0;
-       target = find_sha1_pack(obj->sha1, repo->packs);
+       target = find_sha1_pack(obj->oid.hash, repo->packs);
        if (target) {
                obj->flags |= REMOTE;
                return 0;
@@ -1277,9 +1277,7 @@ static struct object_list **add_one_object(struct object *obj, struct object_lis
 }
 
 static struct object_list **process_blob(struct blob *blob,
-                                        struct object_list **p,
-                                        struct name_path *path,
-                                        const char *name)
+                                        struct object_list **p)
 {
        struct object *obj = &blob->object;
 
@@ -1293,38 +1291,31 @@ static struct object_list **process_blob(struct blob *blob,
 }
 
 static struct object_list **process_tree(struct tree *tree,
-                                        struct object_list **p,
-                                        struct name_path *path,
-                                        const char *name)
+                                        struct object_list **p)
 {
        struct object *obj = &tree->object;
        struct tree_desc desc;
        struct name_entry entry;
-       struct name_path me;
 
        obj->flags |= LOCAL;
 
        if (obj->flags & (UNINTERESTING | SEEN))
                return p;
        if (parse_tree(tree) < 0)
-               die("bad tree object %s", sha1_to_hex(obj->sha1));
+               die("bad tree object %s", oid_to_hex(&obj->oid));
 
        obj->flags |= SEEN;
-       name = xstrdup(name);
        p = add_one_object(obj, p);
-       me.up = path;
-       me.elem = name;
-       me.elem_len = strlen(name);
 
        init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry))
                switch (object_type(entry.mode)) {
                case OBJ_TREE:
-                       p = process_tree(lookup_tree(entry.sha1), p, &me, name);
+                       p = process_tree(lookup_tree(entry.sha1), p);
                        break;
                case OBJ_BLOB:
-                       p = process_blob(lookup_blob(entry.sha1), p, &me, name);
+                       p = process_blob(lookup_blob(entry.sha1), p);
                        break;
                default:
                        /* Subproject commit - not in this repository */
@@ -1343,7 +1334,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
        int count = 0;
 
        while ((commit = get_revision(revs)) != NULL) {
-               p = process_tree(commit->tree, p, NULL, "");
+               p = process_tree(commit->tree, p);
                commit->object.flags |= LOCAL;
                if (!(commit->object.flags & UNINTERESTING))
                        count += add_send_request(&commit->object, lock);
@@ -1362,14 +1353,14 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
                        continue;
                }
                if (obj->type == OBJ_TREE) {
-                       p = process_tree((struct tree *)obj, p, NULL, name);
+                       p = process_tree((struct tree *)obj, p);
                        continue;
                }
                if (obj->type == OBJ_BLOB) {
-                       p = process_blob((struct blob *)obj, p, NULL, name);
+                       p = process_blob((struct blob *)obj, p);
                        continue;
                }
-               die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name);
+               die("unknown pending object %s (%s)", oid_to_hex(&obj->oid), name);
        }
 
        while (objects) {
@@ -1438,11 +1429,11 @@ static void one_remote_ref(const char *refname)
         * Fetch a copy of the object if it doesn't exist locally - it
         * may be required for updating server info later.
         */
-       if (repo->can_update_info_refs && !has_sha1_file(ref->old_sha1)) {
-               obj = lookup_unknown_object(ref->old_sha1);
+       if (repo->can_update_info_refs && !has_object_file(&ref->old_oid)) {
+               obj = lookup_unknown_object(ref->old_oid.hash);
                if (obj) {
                        fprintf(stderr, "  fetch %s for %s\n",
-                               sha1_to_hex(ref->old_sha1), refname);
+                               oid_to_hex(&ref->old_oid), refname);
                        add_fetch_request(obj);
                }
        }
@@ -1473,24 +1464,24 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
                return;
        }
 
-       o = parse_object(ref->old_sha1);
+       o = parse_object(ref->old_oid.hash);
        if (!o) {
                fprintf(stderr,
                        "Unable to parse object %s for remote ref %s\n",
-                       sha1_to_hex(ref->old_sha1), ls->dentry_name);
+                       oid_to_hex(&ref->old_oid), ls->dentry_name);
                aborted = 1;
                free(ref);
                return;
        }
 
        strbuf_addf(buf, "%s\t%s\n",
-                   sha1_to_hex(ref->old_sha1), ls->dentry_name);
+                   oid_to_hex(&ref->old_oid), ls->dentry_name);
 
        if (o->type == OBJ_TAG) {
                o = deref_tag(o, ls->dentry_name, 0);
                if (o)
                        strbuf_addf(buf, "%s\t%s^{}\n",
-                                   sha1_to_hex(o->sha1), ls->dentry_name);
+                                   oid_to_hex(&o->oid), ls->dentry_name);
        }
        free(ref);
 }
@@ -1581,7 +1572,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
 static int verify_merge_base(unsigned char *head_sha1, struct ref *remote)
 {
        struct commit *head = lookup_commit_or_die(head_sha1, "HEAD");
-       struct commit *branch = lookup_commit_or_die(remote->old_sha1, remote->name);
+       struct commit *branch = lookup_commit_or_die(remote->old_oid.hash, remote->name);
 
        return in_merge_bases(branch, head);
 }
@@ -1644,11 +1635,11 @@ static int delete_remote_branch(const char *pattern, int force)
                        return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", sha1_to_hex(head_sha1));
 
                /* Remote branch must resolve to a known object */
-               if (is_null_sha1(remote_ref->old_sha1))
+               if (is_null_oid(&remote_ref->old_oid))
                        return error("Unable to resolve remote branch %s",
                                     remote_ref->name);
-               if (!has_sha1_file(remote_ref->old_sha1))
-                       return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, sha1_to_hex(remote_ref->old_sha1));
+               if (!has_object_file(&remote_ref->old_oid))
+                       return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid));
 
                /* Remote branch must be an ancestor of remote HEAD */
                if (!verify_merge_base(head_sha1, remote_ref)) {
@@ -1861,7 +1852,7 @@ int main(int argc, char **argv)
                if (!ref->peer_ref)
                        continue;
 
-               if (is_null_sha1(ref->peer_ref->new_sha1)) {
+               if (is_null_oid(&ref->peer_ref->new_oid)) {
                        if (delete_remote_branch(ref->name, 1) == -1) {
                                error("Could not remove %s", ref->name);
                                if (helper_status)
@@ -1874,7 +1865,7 @@ int main(int argc, char **argv)
                        continue;
                }
 
-               if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
+               if (!oidcmp(&ref->old_oid, &ref->peer_ref->new_oid)) {
                        if (push_verbosely)
                                fprintf(stderr, "'%s': up-to-date\n", ref->name);
                        if (helper_status)
@@ -1883,11 +1874,11 @@ int main(int argc, char **argv)
                }
 
                if (!force_all &&
-                   !is_null_sha1(ref->old_sha1) &&
+                   !is_null_oid(&ref->old_oid) &&
                    !ref->force) {
-                       if (!has_sha1_file(ref->old_sha1) ||
-                           !ref_newer(ref->peer_ref->new_sha1,
-                                      ref->old_sha1)) {
+                       if (!has_object_file(&ref->old_oid) ||
+                           !ref_newer(&ref->peer_ref->new_oid,
+                                      &ref->old_oid)) {
                                /*
                                 * We do not have the remote ref, or
                                 * we know that the remote ref is not
@@ -1908,14 +1899,14 @@ int main(int argc, char **argv)
                                continue;
                        }
                }
-               hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
+               oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);
                new_refs++;
 
                fprintf(stderr, "updating '%s'", ref->name);
                if (strcmp(ref->name, ref->peer_ref->name))
                        fprintf(stderr, " using '%s'", ref->peer_ref->name);
                fprintf(stderr, "\n  from %s\n  to   %s\n",
-                       sha1_to_hex(ref->old_sha1), sha1_to_hex(ref->new_sha1));
+                       oid_to_hex(&ref->old_oid), oid_to_hex(&ref->new_oid));
                if (dry_run) {
                        if (helper_status)
                                printf("ok %s\n", ref->name);
@@ -1936,10 +1927,10 @@ int main(int argc, char **argv)
                /* Set up revision info for this refspec */
                argv_array_push(&commit_argv, ""); /* ignored */
                argv_array_push(&commit_argv, "--objects");
-               argv_array_push(&commit_argv, sha1_to_hex(ref->new_sha1));
-               if (!push_all && !is_null_sha1(ref->old_sha1))
+               argv_array_push(&commit_argv, oid_to_hex(&ref->new_oid));
+               if (!push_all && !is_null_oid(&ref->old_oid))
                        argv_array_pushf(&commit_argv, "^%s",
-                                        sha1_to_hex(ref->old_sha1));
+                                        oid_to_hex(&ref->old_oid));
                init_revisions(&revs, setup_git_directory());
                setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL);
                revs.edge_hint = 0; /* just in case */
@@ -1962,7 +1953,7 @@ int main(int argc, char **argv)
                run_request_queue();
 
                /* Update the remote branch if all went well */
-               if (aborted || !update_remote(ref->new_sha1, ref_lock))
+               if (aborted || !update_remote(ref->new_oid.hash, ref_lock))
                        rc = 1;
 
                if (!rc)