Code

Update draft release notes for 1.5.4
[git.git] / http-push.c
index 0257291b9ba9258558632b1e428df6479a28b9db..64be904921821c077982f06cea8f66c1954eb420 100644 (file)
@@ -1067,83 +1067,6 @@ static int fetch_indices(void)
        return 0;
 }
 
-static inline int needs_quote(int ch)
-{
-       if (((ch >= 'A') && (ch <= 'Z'))
-                       || ((ch >= 'a') && (ch <= 'z'))
-                       || ((ch >= '0') && (ch <= '9'))
-                       || (ch == '/')
-                       || (ch == '-')
-                       || (ch == '.'))
-               return 0;
-       return 1;
-}
-
-static inline int hex(int v)
-{
-       if (v < 10) return '0' + v;
-       else return 'A' + v - 10;
-}
-
-static char *quote_ref_url(const char *base, const char *ref)
-{
-       const char *cp;
-       char *dp, *qref;
-       int len, baselen, ch;
-
-       baselen = strlen(base);
-       len = baselen + 1;
-       for (cp = ref; (ch = *cp) != 0; cp++, len++)
-               if (needs_quote(ch))
-                       len += 2; /* extra two hex plus replacement % */
-       qref = xmalloc(len);
-       memcpy(qref, base, baselen);
-       for (cp = ref, dp = qref + baselen; (ch = *cp) != 0; cp++) {
-               if (needs_quote(ch)) {
-                       *dp++ = '%';
-                       *dp++ = hex((ch >> 4) & 0xF);
-                       *dp++ = hex(ch & 0xF);
-               }
-               else
-                       *dp++ = ch;
-       }
-       *dp = 0;
-
-       return qref;
-}
-
-int fetch_ref(char *ref, unsigned char *sha1)
-{
-       char *url;
-       struct strbuf buffer = STRBUF_INIT;
-       char *base = remote->url;
-       struct active_request_slot *slot;
-       struct slot_results results;
-
-       url = quote_ref_url(base, ref);
-       slot = get_active_slot();
-       slot->results = &results;
-       curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
-       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");
-       }
-
-       strbuf_rtrim(&buffer);
-       if (buffer.len != 40)
-               return 1;
-       return get_sha1_hex(buffer.buf, sha1);
-}
-
 static void one_remote_object(const char *hex)
 {
        unsigned char sha1[20];
@@ -1829,7 +1752,8 @@ static void one_remote_ref(char *refname)
        struct object *obj;
        int len = strlen(refname) + 1;
 
-       if (fetch_ref(refname, remote_sha1) != 0) {
+       if (http_fetch_ref(remote->url, refname + 5 /* "refs/" */,
+                          remote_sha1) != 0) {
                fprintf(stderr,
                        "Unable to fetch ref %s from %s\n",
                        refname, remote->url);
@@ -1961,7 +1885,8 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
        int len;
        char *ref_info;
 
-       if (fetch_ref(ls->dentry_name, remote_sha1) != 0) {
+       if (http_fetch_ref(remote->url, ls->dentry_name + 5 /* "refs/" */,
+                          remote_sha1) != 0) {
                fprintf(stderr,
                        "Unable to fetch ref %s from %s\n",
                        ls->dentry_name, remote->url);
@@ -2043,6 +1968,7 @@ static int remote_exists(const char *path)
        char *url = xmalloc(strlen(remote->url) + strlen(path) + 1);
        struct active_request_slot *slot;
        struct slot_results results;
+       int ret = -1;
 
        sprintf(url, "%s%s", remote->url, path);
 
@@ -2055,9 +1981,9 @@ static int remote_exists(const char *path)
                run_active_slot(slot);
                free(url);
                if (results.http_code == 404)
-                       return 0;
+                       ret = 0;
                else if (results.curl_result == CURLE_OK)
-                       return 1;
+                       ret = 1;
                else
                        fprintf(stderr, "HEAD HTTP error %ld\n", results.http_code);
        } else {
@@ -2065,7 +1991,8 @@ static int remote_exists(const char *path)
                fprintf(stderr, "Unable to start HEAD request\n");
        }
 
-       return -1;
+       free(url);
+       return ret;
 }
 
 static void fetch_symref(const char *path, char **symref, unsigned char *sha1)