git-fetch --upload-pack: disambiguate.
[gitweb.git] / http-push.c
index 293269395c90e5e5ec4b3bb06e02e7677da2dac5..fe925609b4024119c6171dd32350a6570bea8516 100644 (file)
@@ -6,8 +6,6 @@
 #include "blob.h"
 #include "http.h"
 
-#ifdef USE_CURL_MULTI
-
 #include <expat.h>
 
 static const char http_push_usage[] =
@@ -165,6 +163,7 @@ static void start_check(struct transfer_request *request)
        } else {
                request->state = ABORTED;
                free(request->url);
+               request->url = NULL;
        }
 }
 
@@ -198,6 +197,7 @@ static void start_mkcol(struct transfer_request *request)
        } else {
                request->state = ABORTED;
                free(request->url);
+               request->url = NULL;
        }
 }
 
@@ -244,8 +244,6 @@ static void start_put(struct transfer_request *request)
        request->buffer.size = stream.total_out;
        request->buffer.posn = 0;
 
-       if (request->url != NULL)
-               free(request->url);
        request->url = xmalloc(strlen(remote->url) + 
                               strlen(request->lock->token) + 51);
        strcpy(request->url, remote->url);
@@ -281,6 +279,7 @@ static void start_put(struct transfer_request *request)
        } else {
                request->state = ABORTED;
                free(request->url);
+               request->url = NULL;
        }
 }
 
@@ -306,6 +305,7 @@ static void start_move(struct transfer_request *request)
        } else {
                request->state = ABORTED;
                free(request->url);
+               request->url = NULL;
        }
 }
 
@@ -370,6 +370,13 @@ static void finish_request(struct transfer_request *request)
 
        if (request->headers != NULL)
                curl_slist_free_all(request->headers);
+
+       /* URL is reused for MOVE after PUT */
+       if (request->state != RUN_PUT) {
+               free(request->url);
+               request->url = NULL;
+       }               
+
        if (request->state == RUN_HEAD) {
                if (request->http_code == 404) {
                        request->state = NEED_PUSH;
@@ -435,7 +442,8 @@ static void release_request(struct transfer_request *request)
                        entry->next = entry->next->next;
        }
 
-       free(request->url);
+       if (request->url != NULL)
+               free(request->url);
        free(request);
 }
 
@@ -575,6 +583,7 @@ static int fetch_index(unsigned char *sha1)
                }
        } else {
                free(url);
+               fclose(indexfile);
                return error("Unable to start request");
        }
 
@@ -775,7 +784,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
                                        strtol(ctx->cdata + 7, NULL, 10);
                } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
                        if (!strncmp(ctx->cdata, "opaquelocktoken:", 16)) {
-                               lock->token = xmalloc(strlen(ctx->cdata - 15));
+                               lock->token = xmalloc(strlen(ctx->cdata) - 15);
                                strcpy(lock->token, ctx->cdata + 16);
                        }
                }
@@ -999,9 +1008,7 @@ static int unlock_remote(struct active_lock *lock)
        if (lock->owner != NULL)
                free(lock->owner);
        free(lock->url);
-/* Freeing the token causes a segfault...
        free(lock->token);
-*/
        free(lock);
 
        return rc;
@@ -1230,6 +1237,7 @@ int main(int argc, char **argv)
        int rc = 0;
        int i;
 
+       setup_git_directory();
        setup_ident();
 
        remote = xmalloc(sizeof(*remote));
@@ -1264,6 +1272,9 @@ int main(int argc, char **argv)
                break;
        }
 
+       if (!remote->url)
+               usage(http_push_usage);
+
        memset(remote_dir_exists, 0, 256);
 
        http_init();
@@ -1415,10 +1426,3 @@ int main(int argc, char **argv)
 
        return rc;
 }
-#else /* ifdef USE_CURL_MULTI */
-int main(int argc, char **argv)
-{
-       fprintf(stderr, "http-push requires curl 7.9.8 or higher.\n");
-       return 1;
-}
-#endif