Code

Compute prefix at runtime if RUNTIME_PREFIX is set
[git.git] / http-push.c
index 7c6460919bf3eba10c46cede11ffdd9c53fd2dd2..a99fdfc0efe7a12d4f1c7442b483c880c662b5b7 100644 (file)
@@ -87,6 +87,7 @@ static struct object_list *objects;
 struct repo
 {
        char *url;
+       char *path;
        int path_len;
        int has_info_refs;
        int can_update_info_refs;
@@ -1200,7 +1201,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
        /* Make sure leading directories exist for the remote ref */
        ep = strchr(url + strlen(remote->url) + 1, '/');
        while (ep) {
-               *ep = 0;
+               char saved_character = ep[1];
+               ep[1] = '\0';
                slot = get_active_slot();
                slot->results = &results;
                curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
@@ -1222,7 +1224,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
                        free(url);
                        return NULL;
                }
-               *ep = '/';
+               ep[1] = saved_character;
                ep = strchr(ep + 1, '/');
        }
 
@@ -1424,9 +1426,17 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
                                ls->userFunc(ls);
                        }
                } else if (!strcmp(ctx->name, DAV_PROPFIND_NAME) && ctx->cdata) {
-                       ls->dentry_name = xmalloc(strlen(ctx->cdata) -
-                                                 remote->path_len + 1);
-                       strcpy(ls->dentry_name, ctx->cdata + remote->path_len);
+                       char *path = ctx->cdata;
+                       if (*ctx->cdata == 'h') {
+                               path = strstr(path, "//");
+                               if (path) {
+                                       path = strchr(path+2, '/');
+                               }
+                       }
+                       if (path) {
+                               path += remote->path_len;
+                               ls->dentry_name = xstrdup(path);
+                       }
                } else if (!strcmp(ctx->name, DAV_PROPFIND_COLLECTION)) {
                        ls->dentry_flags |= IS_DIR;
                }
@@ -1437,6 +1447,12 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
        }
 }
 
+/*
+ * NEEDSWORK: remote_ls() ignores info/refs on the remote side.  But it
+ * should _only_ heed the information from that file, instead of trying to
+ * determine the refs from the remote file system (badly: it does not even
+ * know about packed-refs).
+ */
 static void remote_ls(const char *path, int flags,
                      void (*userFunc)(struct remote_ls_ctx *ls),
                      void *userData)
@@ -2168,6 +2184,8 @@ int main(int argc, char **argv)
        struct ref *ref;
        char *rewritten_url = NULL;
 
+       git_extract_argv0_path(argv[0]);
+
        setup_git_directory();
 
        remote = xcalloc(sizeof(*remote), 1);
@@ -2206,10 +2224,11 @@ int main(int argc, char **argv)
                if (!remote->url) {
                        char *path = strstr(arg, "//");
                        remote->url = arg;
+                       remote->path_len = strlen(arg);
                        if (path) {
-                               path = strchr(path+2, '/');
-                               if (path)
-                                       remote->path_len = strlen(path);
+                               remote->path = strchr(path+2, '/');
+                               if (remote->path)
+                                       remote->path_len = strlen(remote->path);
                        }
                        continue;
                }
@@ -2238,8 +2257,9 @@ int main(int argc, char **argv)
                rewritten_url = xmalloc(strlen(remote->url)+2);
                strcpy(rewritten_url, remote->url);
                strcat(rewritten_url, "/");
+               remote->path = rewritten_url + (remote->path - remote->url);
+               remote->path_len++;
                remote->url = rewritten_url;
-               ++remote->path_len;
        }
 
        /* Verify DAV compliance/lock support */