Support remote references with slashes in their names
Support remote references with slashes in their names Signed-off-by: Nick Hengeveld <nickh@reactrix.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nick Hengeveld committed
Nov 4, 2005 at 14:22 UTC
0772b9a6331357913417722eab672f8b5aa69e50
1 file changed
+39
-3
http-push.c
+39
-3
@@ -1066,12 +1066,44 @@ char *lock_remote(char *file, int timeout)
1066
struct buffer out_buffer;
1067
char *out_data;
1068
char *url;
1069
+ char *ep;
1070
char timeout_header[25];
1071
struct curl_slist *dav_headers = NULL;
1072
1073
if (lock_token != NULL)
1074
free(lock_token);
1075
1076
+ url = xmalloc(strlen(remote->url) + strlen(file) + 1);
1077
+ sprintf(url, "%s%s", remote->url, file);
1078
+
1079
+ /* Make sure leading directories exist for the remote ref */
1080
+ ep = strchr(url + strlen(remote->url) + 11, '/');
1081
+ while (ep) {
1082
+ *ep = 0;
1083
+ slot = get_active_slot();
1084
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
1085
+ curl_easy_setopt(slot->curl, CURLOPT_URL, url);
1086
+ curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL);
1087
+ curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
1088
+ if (start_active_slot(slot)) {
1089
+ run_active_slot(slot);
1090
+ if (slot->curl_result != CURLE_OK &&
1091
+ slot->http_code != 405) {
1092
+ fprintf(stderr,
1093
+ "Unable to create branch path %s\n",
1094
+ url);
1095
+ free(url);
1096
+ return NULL;
1097
+ }
1098
+ } else {
1099
+ fprintf(stderr, "Unable to start request\n");
1100
+ free(url);
1101
+ return NULL;
1102
+ }
1103
+ *ep = '/';
1104
+ ep = strchr(ep + 1, '/');
1105
+ }
1106
+
1107
out_buffer.size = strlen(LOCK_REQUEST) + strlen(git_default_email) - 2;
1108
out_data = xmalloc(out_buffer.size + 1);
1109
snprintf(out_data, out_buffer.size + 1, LOCK_REQUEST, git_default_email);
@@ -1079,8 +1111,6 @@ char *lock_remote(char *file, int timeout)
1111
out_buffer.buffer = out_data;
1112
1113
sprintf(timeout_header, "Timeout: Second-%d", timeout);
1082
- url = xmalloc(strlen(remote->url) + strlen(file) + 1);
1083
- sprintf(url, "%s%s", remote->url, file);
1114
dav_headers = curl_slist_append(dav_headers, timeout_header);
1115
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
1116
@@ -1098,16 +1128,22 @@ char *lock_remote(char *file, int timeout)
1128
1129
if (start_active_slot(slot)) {
1130
run_active_slot(slot);
1101
- free(out_data);
1131
if (slot->curl_result != CURLE_OK) {
1132
fprintf(stderr, "Got HTTP error %ld\n", slot->http_code);
1133
+ free(url);
1134
+ free(out_data);
1135
return NULL;
1136
}
1137
} else {
1138
+ free(url);
1139
free(out_data);
1140
fprintf(stderr, "Unable to start request\n");
1141
+ return NULL;
1142
}
1143
1144
+ free(url);
1145
+ free(out_data);
1146
+
1147
return strdup(lock_token);
1148
}
1149