Skip to content

Commit

Permalink
http-push and http-fetch: handle URLs without trailing /
Browse files Browse the repository at this point in the history
The URL to a repository http-push and http-fetch takes should
have a trailing slash.  Instead of failing the request, add it
ourselves before attempting such a request.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Grégoire Barbier authored and Junio C Hamano committed Jan 20, 2008
1 parent 325ce39 commit 3057ded
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions builtin-http-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
const char **write_ref = NULL;
char **commit_id;
const char *url;
char *rewritten_url = NULL;
int arg = 1;
int rc = 0;
int get_tree = 0;
Expand Down Expand Up @@ -51,6 +52,12 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
commits = 1;
}
url = argv[arg];
if (url && url[strlen(url)-1] != '/') {
rewritten_url = malloc(strlen(url)+2);
strcpy(rewritten_url, url);
strcat(rewritten_url, "/");
url = rewritten_url;
}

walker = get_http_walker(url);
walker->get_tree = get_tree;
Expand All @@ -73,5 +80,8 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)

walker_free(walker);

if (rewritten_url)
free(rewritten_url);

return rc;
}
11 changes: 11 additions & 0 deletions http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,7 @@ int main(int argc, char **argv)
int i;
int new_refs;
struct ref *ref;
char *rewritten_url = NULL;

setup_git_directory();

Expand Down Expand Up @@ -2236,6 +2237,14 @@ 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()) {
rc = 1;
Expand Down Expand Up @@ -2416,6 +2425,8 @@ int main(int argc, char **argv)
}

cleanup:
if (rewritten_url)
free(rewritten_url);
if (info_ref_lock)
unlock_remote(info_ref_lock);
free(remote);
Expand Down

0 comments on commit 3057ded

Please sign in to comment.