builtin/ls-remote.c: rearrange xcalloc arguments
[gitweb.git] / http.c
diff --git a/http.c b/http.c
index bcf54aa35f96e8f0b87b6e2fd23408991a684b66..94e1afdee7890825dfda0946b999f524265603fc 100644 (file)
--- a/http.c
+++ b/http.c
@@ -460,7 +460,7 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
                credential_from_url(&http_auth, url);
                if (!ssl_cert_password_required &&
                    getenv("GIT_SSL_CERT_PASSWORD_PROTECTED") &&
-                   !prefixcmp(url, "https://"))
+                   starts_with(url, "https://"))
                        ssl_cert_password_required = 1;
        }
 
@@ -761,6 +761,12 @@ void finish_active_slot(struct active_request_slot *slot)
        if (slot->results != NULL) {
                slot->results->curl_result = slot->curl_result;
                slot->results->http_code = slot->http_code;
+#if LIBCURL_VERSION_NUM >= 0x070a08
+               curl_easy_getinfo(slot->curl, CURLINFO_HTTPAUTH_AVAIL,
+                                 &slot->results->auth_avail);
+#else
+               slot->results->auth_avail = 0;
+#endif
        }
 
        /* Run callback if appropriate */
@@ -874,6 +880,20 @@ int handle_curl_result(struct slot_results *results)
        }
 }
 
+int run_one_slot(struct active_request_slot *slot,
+                struct slot_results *results)
+{
+       slot->results = results;
+       if (!start_active_slot(slot)) {
+               snprintf(curl_errorstr, sizeof(curl_errorstr),
+                        "failed to start HTTP request");
+               return HTTP_START_FAILED;
+       }
+
+       run_active_slot(slot);
+       return handle_curl_result(results);
+}
+
 static CURLcode curlinfo_strbuf(CURL *curl, CURLINFO info, struct strbuf *buf)
 {
        char *ptr;
@@ -901,7 +921,6 @@ static int http_request(const char *url,
        int ret;
 
        slot = get_active_slot();
-       slot->results = &results;
        curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
 
        if (result == NULL) {
@@ -936,14 +955,7 @@ static int http_request(const char *url,
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
 
-       if (start_active_slot(slot)) {
-               run_active_slot(slot);
-               ret = handle_curl_result(&results);
-       } else {
-               snprintf(curl_errorstr, sizeof(curl_errorstr),
-                        "failed to start HTTP request");
-               ret = HTTP_START_FAILED;
-       }
+       ret = run_one_slot(slot, &results);
 
        if (options && options->content_type)
                curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE,
@@ -994,7 +1006,7 @@ static int update_url_from_redirect(struct strbuf *base,
        if (!strcmp(asked, got->buf))
                return 0;
 
-       if (prefixcmp(asked, base->buf))
+       if (!starts_with(asked, base->buf))
                die("BUG: update_url_from_redirect: %s is not a superset of %s",
                    asked, base->buf);
 
@@ -1100,7 +1112,7 @@ int http_fetch_ref(const char *base, struct ref *ref)
                strbuf_rtrim(&buffer);
                if (buffer.len == 40)
                        ret = get_sha1_hex(buffer.buf, ref->old_sha1);
-               else if (!prefixcmp(buffer.buf, "ref: ")) {
+               else if (starts_with(buffer.buf, "ref: ")) {
                        ref->symref = xstrdup(buffer.buf + 5);
                        ret = 0;
                }
@@ -1201,8 +1213,8 @@ int http_get_info_packs(const char *base_url, struct packed_git **packs_head)
                case 'P':
                        i++;
                        if (i + 52 <= buf.len &&
-                           !prefixcmp(data + i, " pack-") &&
-                           !prefixcmp(data + i + 46, ".pack\n")) {
+                           starts_with(data + i, " pack-") &&
+                           starts_with(data + i + 46, ".pack\n")) {
                                get_sha1_hex(data + i + 6, sha1);
                                fetch_and_setup_pack_index(packs_head, sha1,
                                                      base_url);
@@ -1378,7 +1390,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
        unsigned char *sha1)
 {
        char *hex = sha1_to_hex(sha1);
-       char *filename;
+       const char *filename;
        char prevfile[PATH_MAX];
        int prevlocal;
        char prev_buf[PREV_BUF_SIZE];