]> asedeno.scripts.mit.edu Git - git.git/blobdiff - http-push.c
gitignore(5): Allow "foo/" in ignore list to match directory "foo"
[git.git] / http-push.c
index af00ea10b96ffe6c2a29d69603d48093dd12e441..b2b410df902f2a4f2bca634d82cf103d288c9042 100644 (file)
@@ -1067,88 +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;
-       int ret;
-
-       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);
-               if (results.curl_result == CURLE_OK) {
-                       strbuf_rtrim(&buffer);
-                       if (buffer.len == 40)
-                               ret = get_sha1_hex(buffer.buf, sha1);
-                       else
-                               ret = 1;
-               } else {
-                       ret = error("Couldn't get %s for %s\n%s",
-                                   url, ref, curl_errorstr);
-               }
-       } else {
-               ret = error("Unable to start request");
-       }
-
-       strbuf_release(&buffer);
-       free(url);
-       return ret;
-}
-
 static void one_remote_object(const char *hex)
 {
        unsigned char sha1[20];
@@ -1645,9 +1563,17 @@ static int locking_available(void)
                                lock_flags = 0;
                        }
                        XML_ParserFree(parser);
+                       if (!lock_flags)
+                               error("Error: no DAV locking support on %s",
+                                     remote->url);
+
+               } else {
+                       error("Cannot access URL %s, return code %d",
+                             remote->url, results.curl_result);
+                       lock_flags = 0;
                }
        } else {
-               fprintf(stderr, "Unable to start PROPFIND request\n");
+               error("Unable to start PROPFIND request on %s", remote->url);
        }
 
        strbuf_release(&out_buffer.buf);
@@ -1834,7 +1760,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);
@@ -1966,7 +1893,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);
@@ -2059,7 +1987,6 @@ static int remote_exists(const char *path)
 
        if (start_active_slot(slot)) {
                run_active_slot(slot);
-               free(url);
                if (results.http_code == 404)
                        ret = 0;
                else if (results.curl_result == CURLE_OK)
@@ -2067,7 +1994,6 @@ 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");
        }
 
@@ -2243,6 +2169,7 @@ int main(int argc, char **argv)
        int i;
        int new_refs;
        struct ref *ref;
+       char *rewritten_url = NULL;
 
        setup_git_directory();
 
@@ -2294,6 +2221,10 @@ int main(int argc, char **argv)
                break;
        }
 
+#ifndef USE_CURL_MULTI
+       die("git-push is not available for http/https repository when not compiled with USE_CURL_MULTI");
+#endif
+
        if (!remote->url)
                usage(http_push_usage);
 
@@ -2306,9 +2237,16 @@ int main(int argc, char **argv)
 
        no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
 
+       if (remote->url && remote->url[strlen(remote->url)-1] != '/') {
+               rewritten_url = malloc(strlen(remote->url)+2);
+               strcpy(rewritten_url, remote->url);
+               strcat(rewritten_url, "/");
+               remote->url = rewritten_url;
+               ++remote->path_len;
+       }
+
        /* Verify DAV compliance/lock support */
        if (!locking_available()) {
-               fprintf(stderr, "Error: no DAV locking support on remote repo %s\n", remote->url);
                rc = 1;
                goto cleanup;
        }
@@ -2321,6 +2259,11 @@ int main(int argc, char **argv)
                info_ref_lock = lock_remote("info/refs", LOCK_TIME);
                if (info_ref_lock)
                        remote->can_update_info_refs = 1;
+               else {
+                       fprintf(stderr, "Error: cannot lock existing info/refs\n");
+                       rc = 1;
+                       goto cleanup;
+               }
        }
        if (remote->has_info_packs)
                fetch_indices();
@@ -2342,11 +2285,14 @@ int main(int argc, char **argv)
        if (!remote_tail)
                remote_tail = &remote_refs;
        if (match_refs(local_refs, remote_refs, &remote_tail,
-                      nr_refspec, (const char **) refspec, push_all))
-               return -1;
+                      nr_refspec, (const char **) refspec, push_all)) {
+               rc = -1;
+               goto cleanup;
+       }
        if (!remote_refs) {
                fprintf(stderr, "No refs in common and none specified; doing nothing.\n");
-               return 0;
+               rc = 0;
+               goto cleanup;
        }
 
        new_refs = 0;
@@ -2477,10 +2423,12 @@ int main(int argc, char **argv)
                        fprintf(stderr, "Unable to update server info\n");
                }
        }
-       if (info_ref_lock)
-               unlock_remote(info_ref_lock);
 
  cleanup:
+       if (rewritten_url)
+               free(rewritten_url);
+       if (info_ref_lock)
+               unlock_remote(info_ref_lock);
        free(remote);
 
        curl_slist_free_all(no_pragma_header);