Remove a CURLOPT_HTTPHEADER (un)setting
[gitweb.git] / http-push.c
index 66b81f17266569ee47d32ec58df9d1386e4d0431..176bb29fab011500e882d6fd6a3ed467b853bb18 100644 (file)
@@ -75,7 +75,6 @@ static int aborted;
 static signed char remote_dir_exists[256];
 
 static struct curl_slist *no_pragma_header;
-static struct curl_slist *default_headers;
 
 static int push_verbosely;
 static int push_all = MATCH_REFS_NONE;
@@ -433,7 +432,7 @@ static void start_fetch_packed(struct transfer_request *request)
        packfile = fopen(request->tmpfile, "a");
        if (!packfile) {
                fprintf(stderr, "Unable to open local file %s for pack",
-                       filename);
+                       request->tmpfile);
                remote->can_update_info_refs = 0;
                free(url);
                return;
@@ -925,11 +924,14 @@ static int fetch_index(unsigned char *sha1)
                                     hex);
                }
        } else {
+               free(url);
                return error("Unable to start request");
        }
 
-       if (has_pack_index(sha1))
+       if (has_pack_index(sha1)) {
+               free(url);
                return 0;
+       }
 
        if (push_verbosely)
                fprintf(stderr, "Getting index for pack %s\n", hex);
@@ -939,9 +941,11 @@ static int fetch_index(unsigned char *sha1)
        filename = sha1_pack_index_name(sha1);
        snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
        indexfile = fopen(tmpfile, "a");
-       if (!indexfile)
+       if (!indexfile) {
+               free(url);
                return error("Unable to open local file %s for pack index",
-                            filename);
+                            tmpfile);
+       }
 
        slot = get_active_slot();
        slot->results = &results;
@@ -1135,16 +1139,19 @@ int fetch_ref(char *ref, unsigned char *sha1)
        curl_easy_setopt(slot->curl, CURLOPT_URL, url);
        if (start_active_slot(slot)) {
                run_active_slot(slot);
+               free(url);
                if (results.curl_result != CURLE_OK)
                        return error("Couldn't get %s for %s\n%s",
                                     url, ref, curl_errorstr);
        } else {
+               free(url);
                return error("Unable to start request");
        }
 
+       if (buffer.posn != 41)
+               return 1;
         hex[40] = '\0';
-        get_sha1_hex(hex, sha1);
-        return 0;
+       return get_sha1_hex(hex, sha1);
 }
 
 static void one_remote_object(const char *hex)
@@ -1275,8 +1282,6 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
        char *ep;
        char timeout_header[25];
        struct remote_lock *lock = NULL;
-       XML_Parser parser = XML_ParserCreate(NULL);
-       enum XML_Status result;
        struct curl_slist *dav_headers = NULL;
        struct xml_ctx ctx;
 
@@ -1345,6 +1350,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
        if (start_active_slot(slot)) {
                run_active_slot(slot);
                if (results.curl_result == CURLE_OK) {
+                       XML_Parser parser = XML_ParserCreate(NULL);
+                       enum XML_Status result;
                        ctx.name = xcalloc(10, 1);
                        ctx.len = 0;
                        ctx.cdata = NULL;
@@ -1363,6 +1370,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
                                                XML_GetErrorCode(parser)));
                                lock->timeout = -1;
                        }
+                       XML_ParserFree(parser);
                }
        } else {
                fprintf(stderr, "Unable to start LOCK request\n");
@@ -1525,8 +1533,6 @@ static void remote_ls(const char *path, int flags,
        struct buffer out_buffer;
        char *in_data;
        char *out_data;
-       XML_Parser parser = XML_ParserCreate(NULL);
-       enum XML_Status result;
        struct curl_slist *dav_headers = NULL;
        struct xml_ctx ctx;
        struct remote_ls_ctx ls;
@@ -1569,6 +1575,8 @@ static void remote_ls(const char *path, int flags,
        if (start_active_slot(slot)) {
                run_active_slot(slot);
                if (results.curl_result == CURLE_OK) {
+                       XML_Parser parser = XML_ParserCreate(NULL);
+                       enum XML_Status result;
                        ctx.name = xcalloc(10, 1);
                        ctx.len = 0;
                        ctx.cdata = NULL;
@@ -1587,6 +1595,7 @@ static void remote_ls(const char *path, int flags,
                                        XML_ErrorString(
                                                XML_GetErrorCode(parser)));
                        }
+                       XML_ParserFree(parser);
                }
        } else {
                fprintf(stderr, "Unable to start PROPFIND request\n");
@@ -1620,8 +1629,6 @@ static int locking_available(void)
        struct buffer out_buffer;
        char *in_data;
        char *out_data;
-       XML_Parser parser = XML_ParserCreate(NULL);
-       enum XML_Status result;
        struct curl_slist *dav_headers = NULL;
        struct xml_ctx ctx;
        int lock_flags = 0;
@@ -1658,6 +1665,8 @@ static int locking_available(void)
        if (start_active_slot(slot)) {
                run_active_slot(slot);
                if (results.curl_result == CURLE_OK) {
+                       XML_Parser parser = XML_ParserCreate(NULL);
+                       enum XML_Status result;
                        ctx.name = xcalloc(10, 1);
                        ctx.len = 0;
                        ctx.cdata = NULL;
@@ -1676,6 +1685,7 @@ static int locking_available(void)
                                                XML_GetErrorCode(parser)));
                                lock_flags = 0;
                        }
+                       XML_ParserFree(parser);
                }
        } else {
                fprintf(stderr, "Unable to start PROPFIND request\n");
@@ -2104,6 +2114,7 @@ static int remote_exists(const char *path)
 
         if (start_active_slot(slot)) {
                run_active_slot(slot);
+               free(url);
                if (results.http_code == 404)
                        return 0;
                else if (results.curl_result == CURLE_OK)
@@ -2111,6 +2122,7 @@ static int remote_exists(const char *path)
                else
                        fprintf(stderr, "HEAD HTTP error %ld\n", results.http_code);
        } else {
+               free(url);
                fprintf(stderr, "Unable to start HEAD request\n");
        }
 
@@ -2351,11 +2363,6 @@ int main(int argc, char **argv)
        http_init();
 
        no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
-       default_headers = curl_slist_append(default_headers, "Range:");
-       default_headers = curl_slist_append(default_headers, "Destination:");
-       default_headers = curl_slist_append(default_headers, "If:");
-       default_headers = curl_slist_append(default_headers,
-                                           "Pragma: no-cache");
 
        /* Verify DAV compliance/lock support */
        if (!locking_available()) {
@@ -2535,7 +2542,6 @@ int main(int argc, char **argv)
        free(remote);
 
        curl_slist_free_all(no_pragma_header);
-       curl_slist_free_all(default_headers);
 
        http_cleanup();