Merge branch 'jc/diff-tree-stale-comment'
[gitweb.git] / http-push.c
index bd60668707b956160edd9fb22767758023571ebb..67c4d4b472cb1065bcfa20007fdbca55ac8e0052 100644 (file)
@@ -211,7 +211,7 @@ static void curl_setup_http(CURL *curl, const char *url,
 static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum dav_header_flag options)
 {
        struct strbuf buf = STRBUF_INIT;
-       struct curl_slist *dav_headers = NULL;
+       struct curl_slist *dav_headers = http_copy_default_headers();
 
        if (options & DAV_HEADER_IF) {
                strbuf_addf(&buf, "If: (<%s>)", lock->token);
@@ -417,7 +417,7 @@ static void start_put(struct transfer_request *request)
 static void start_move(struct transfer_request *request)
 {
        struct active_request_slot *slot;
-       struct curl_slist *dav_headers = NULL;
+       struct curl_slist *dav_headers = http_copy_default_headers();
 
        slot = get_active_slot();
        slot->callback_func = process_response;
@@ -718,13 +718,13 @@ static int fetch_indices(void)
        return ret;
 }
 
-static void one_remote_object(const unsigned char *sha1)
+static void one_remote_object(const struct object_id *oid)
 {
        struct object *obj;
 
-       obj = lookup_object(sha1);
+       obj = lookup_object(oid->hash);
        if (!obj)
-               obj = parse_object(sha1);
+               obj = parse_object(oid);
 
        /* Ignore remote objects that don't exist locally */
        if (!obj)
@@ -845,7 +845,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
        char *ep;
        char timeout_header[25];
        struct remote_lock *lock = NULL;
-       struct curl_slist *dav_headers = NULL;
+       struct curl_slist *dav_headers = http_copy_default_headers();
        struct xml_ctx ctx;
        char *escaped;
 
@@ -1013,26 +1013,26 @@ static void remote_ls(const char *path, int flags,
                      void *userData);
 
 /* extract hex from sharded "xx/x{40}" filename */
-static int get_sha1_hex_from_objpath(const char *path, unsigned char *sha1)
+static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
 {
-       char hex[40];
+       char hex[GIT_MAX_HEXSZ];
 
-       if (strlen(path) != 41)
+       if (strlen(path) != GIT_SHA1_HEXSZ + 1)
                return -1;
 
        memcpy(hex, path, 2);
        path += 2;
        path++; /* skip '/' */
-       memcpy(hex, path, 38);
+       memcpy(hex, path, GIT_SHA1_HEXSZ - 2);
 
-       return get_sha1_hex(hex, sha1);
+       return get_oid_hex(hex, oid);
 }
 
 static void process_ls_object(struct remote_ls_ctx *ls)
 {
        unsigned int *parent = (unsigned int *)ls->userData;
        const char *path = ls->dentry_name;
-       unsigned char sha1[20];
+       struct object_id oid;
 
        if (!strcmp(ls->path, ls->dentry_name) && (ls->flags & IS_DIR)) {
                remote_dir_exists[*parent] = 1;
@@ -1040,10 +1040,10 @@ static void process_ls_object(struct remote_ls_ctx *ls)
        }
 
        if (!skip_prefix(path, "objects/", &path) ||
-           get_sha1_hex_from_objpath(path, sha1))
+           get_oid_hex_from_objpath(path, &oid))
                return;
 
-       one_remote_object(sha1);
+       one_remote_object(&oid);
 }
 
 static void process_ls_ref(struct remote_ls_ctx *ls)
@@ -1126,7 +1126,7 @@ static void remote_ls(const char *path, int flags,
        struct slot_results results;
        struct strbuf in_buffer = STRBUF_INIT;
        struct buffer out_buffer = { STRBUF_INIT, 0 };
-       struct curl_slist *dav_headers = NULL;
+       struct curl_slist *dav_headers = http_copy_default_headers();
        struct xml_ctx ctx;
        struct remote_ls_ctx ls;
 
@@ -1137,7 +1137,7 @@ static void remote_ls(const char *path, int flags,
        ls.userData = userData;
        ls.userFunc = userFunc;
 
-       strbuf_addf(&out_buffer.buf, PROPFIND_ALL_REQUEST);
+       strbuf_addstr(&out_buffer.buf, PROPFIND_ALL_REQUEST);
 
        dav_headers = curl_slist_append(dav_headers, "Depth: 1");
        dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
@@ -1204,7 +1204,7 @@ static int locking_available(void)
        struct slot_results results;
        struct strbuf in_buffer = STRBUF_INIT;
        struct buffer out_buffer = { STRBUF_INIT, 0 };
-       struct curl_slist *dav_headers = NULL;
+       struct curl_slist *dav_headers = http_copy_default_headers();
        struct xml_ctx ctx;
        int lock_flags = 0;
        char *escaped;
@@ -1312,10 +1312,10 @@ 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(entry.sha1), p);
+                       p = process_tree(lookup_tree(entry.oid), p);
                        break;
                case OBJ_BLOB:
-                       p = process_blob(lookup_blob(entry.sha1), p);
+                       p = process_blob(lookup_blob(entry.oid), p);
                        break;
                default:
                        /* Subproject commit - not in this repository */
@@ -1431,11 +1431,9 @@ static void one_remote_ref(const char *refname)
         */
        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",
-                               oid_to_hex(&ref->old_oid), refname);
-                       add_fetch_request(obj);
-               }
+               fprintf(stderr, "  fetch %s for %s\n",
+                       oid_to_hex(&ref->old_oid), refname);
+               add_fetch_request(obj);
        }
 
        ref->next = remote_refs;
@@ -1464,7 +1462,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
                return;
        }
 
-       o = parse_object(ref->old_oid.hash);
+       o = parse_object(&ref->old_oid);
        if (!o) {
                fprintf(stderr,
                        "Unable to parse object %s for remote ref %s\n",
@@ -1538,7 +1536,7 @@ static int remote_exists(const char *path)
        return ret;
 }
 
-static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
+static void fetch_symref(const char *path, char **symref, struct object_id *oid)
 {
        char *url = xstrfmt("%s%s", repo->url, path);
        struct strbuf buffer = STRBUF_INIT;
@@ -1551,7 +1549,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
 
        free(*symref);
        *symref = NULL;
-       hashclr(sha1);
+       oidclr(oid);
 
        if (buffer.len == 0)
                return;
@@ -1563,16 +1561,17 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
        if (skip_prefix(buffer.buf, "ref: ", &name)) {
                *symref = xmemdupz(name, buffer.len - (name - buffer.buf));
        } else {
-               get_sha1_hex(buffer.buf, sha1);
+               get_oid_hex(buffer.buf, oid);
        }
 
        strbuf_release(&buffer);
 }
 
-static int verify_merge_base(unsigned char *head_sha1, struct ref *remote)
+static int verify_merge_base(struct object_id *head_oid, struct ref *remote)
 {
-       struct commit *head = lookup_commit_or_die(head_sha1, "HEAD");
-       struct commit *branch = lookup_commit_or_die(remote->old_oid.hash, remote->name);
+       struct commit *head = lookup_commit_or_die(head_oid, "HEAD");
+       struct commit *branch = lookup_commit_or_die(&remote->old_oid,
+                                                    remote->name);
 
        return in_merge_bases(branch, head);
 }
@@ -1581,7 +1580,7 @@ static int delete_remote_branch(const char *pattern, int force)
 {
        struct ref *refs = remote_refs;
        struct ref *remote_ref = NULL;
-       unsigned char head_sha1[20];
+       struct object_id head_oid;
        char *symref = NULL;
        int match;
        int patlen = strlen(pattern);
@@ -1612,7 +1611,7 @@ static int delete_remote_branch(const char *pattern, int force)
         * Remote HEAD must be a symref (not exactly foolproof; a remote
         * symlink to a symref will look like a symref)
         */
-       fetch_symref("HEAD", &symref, head_sha1);
+       fetch_symref("HEAD", &symref, &head_oid);
        if (!symref)
                return error("Remote HEAD is not a symref");
 
@@ -1621,7 +1620,7 @@ static int delete_remote_branch(const char *pattern, int force)
                if (!strcmp(remote_ref->name, symref))
                        return error("Remote branch %s is the current HEAD",
                                     remote_ref->name);
-               fetch_symref(symref, &symref, head_sha1);
+               fetch_symref(symref, &symref, &head_oid);
        }
 
        /* Run extra sanity checks if delete is not forced */
@@ -1629,10 +1628,10 @@ static int delete_remote_branch(const char *pattern, int force)
                /* Remote HEAD must resolve to a known object */
                if (symref)
                        return error("Remote HEAD symrefs too deep");
-               if (is_null_sha1(head_sha1))
+               if (is_null_oid(&head_oid))
                        return error("Unable to resolve remote HEAD");
-               if (!has_sha1_file(head_sha1))
-                       return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", sha1_to_hex(head_sha1));
+               if (!has_object_file(&head_oid))
+                       return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid));
 
                /* Remote branch must resolve to a known object */
                if (is_null_oid(&remote_ref->old_oid))
@@ -1642,7 +1641,7 @@ static int delete_remote_branch(const char *pattern, int force)
                        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)) {
+               if (!verify_merge_base(&head_oid, remote_ref)) {
                        return error("The branch '%s' is not an ancestor "
                                     "of your current HEAD.\n"
                                     "If you are sure you want to delete it,"
@@ -1692,12 +1691,12 @@ static void run_request_queue(void)
 #endif
 }
 
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
 {
        struct transfer_request *request;
        struct transfer_request *next_request;
        int nr_refspec = 0;
-       char **refspec = NULL;
+       const char **refspec = NULL;
        struct remote_lock *ref_lock = NULL;
        struct remote_lock *info_ref_lock = NULL;
        struct rev_info revs;
@@ -1709,15 +1708,11 @@ int main(int argc, char **argv)
        int new_refs;
        struct ref *ref, *local_refs;
 
-       git_setup_gettext();
-
-       git_extract_argv0_path(argv[0]);
-
        repo = xcalloc(1, sizeof(*repo));
 
        argv++;
        for (i = 1; i < argc; i++, argv++) {
-               char *arg = *argv;
+               const char *arg = *argv;
 
                if (*arg == '-') {
                        if (!strcmp(arg, "--all")) {