http-push and http-fetch: handle URLs without trailing /
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>
Grégoire Barbier committed
Jan 19, 2008 at 16:22 UTC
3057ded057f17add305cd38fe0b73173e94c540e
2 files changed
+21
builtin-http-fetch.c
+10
@@ -9,6 +9,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
9
const char **write_ref = NULL;
10
char **commit_id;
11
const char *url;
12
+ char *rewritten_url = NULL;
13
int arg = 1;
14
int rc = 0;
15
int get_tree = 0;
@@ -51,6 +52,12 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
52
commits = 1;
53
}
54
url = argv[arg];
55
+ if (url && url[strlen(url)-1] != '/') {
56
+ rewritten_url = malloc(strlen(url)+2);
57
+ strcpy(rewritten_url, url);
58
+ strcat(rewritten_url, "/");
59
+ url = rewritten_url;
60
+ }
61
62
walker = get_http_walker(url);
63
walker->get_tree = get_tree;
@@ -73,5 +80,8 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
80
81
walker_free(walker);
82
83
+ if (rewritten_url)
84
+ free(rewritten_url);
85
+
86
return rc;
87
}
http-push.c
+11
@@ -2169,6 +2169,7 @@ int main(int argc, char **argv)
2169
int i;
2170
int new_refs;
2171
struct ref *ref;
2172
+ char *rewritten_url = NULL;
2173
2174
setup_git_directory();
2175
@@ -2236,6 +2237,14 @@ int main(int argc, char **argv)
2237
2238
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
2239
2240
+ if (remote->url && remote->url[strlen(remote->url)-1] != '/') {
2241
+ rewritten_url = malloc(strlen(remote->url)+2);
2242
+ strcpy(rewritten_url, remote->url);
2243
+ strcat(rewritten_url, "/");
2244
+ remote->url = rewritten_url;
2245
+ ++remote->path_len;
2246
+ }
2247
+
2248
/* Verify DAV compliance/lock support */
2249
if (!locking_available()) {
2250
rc = 1;
@@ -2416,6 +2425,8 @@ int main(int argc, char **argv)
2425
}
2426
2427
cleanup:
2428
+ if (rewritten_url)
2429
+ free(rewritten_url);
2430
if (info_ref_lock)
2431
unlock_remote(info_ref_lock);
2432
free(remote);