@matheusbsbs / matheus-bagliano / commits / 7b5201a60d
Fork 0

Do not name "repo" struct "remote" in push_http.c

This patch is a first step in getting http-push to use http authentication via prompts. The patch renames remote to repo so that it doesn't get confusing with the same remote that is passed around when using http. Signed-off-by: Amos King <amos.l.king@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Amos King committed Mar 18, 2009 at 18:43 UTC 7b5201a60d8f00e7026a3fc4cfdd7852caa9882f
1 file changed +76 -76
http-push.c
+76 -76
@@ -97,7 +97,7 @@ struct repo
97 struct remote_lock *locks;
98 };
99
100 -static struct repo *remote;
100 +static struct repo *repo;
101
102 enum transfer_state {
103 NEED_FETCH,
@@ -324,7 +324,7 @@ static void start_fetch_loose(struct transfer_request *request)
324
325 git_SHA1_Init(&request->c);
326
327 - url = get_remote_object_url(remote->url, hex, 0);
327 + url = get_remote_object_url(repo->url, hex, 0);
328 request->url = xstrdup(url);
329
330 /* If a previous temp file is present, process what was already
@@ -389,7 +389,7 @@ static void start_fetch_loose(struct transfer_request *request)
389 request->state = RUN_FETCH_LOOSE;
390 if (!start_active_slot(slot)) {
391 fprintf(stderr, "Unable to start GET request\n");
392 - remote->can_update_info_refs = 0;
392 + repo->can_update_info_refs = 0;
393 release_request(request);
394 }
395 }
@@ -399,7 +399,7 @@ static void start_mkcol(struct transfer_request *request)
399 char *hex = sha1_to_hex(request->obj->sha1);
400 struct active_request_slot *slot;
401
402 - request->url = get_remote_object_url(remote->url, hex, 1);
402 + request->url = get_remote_object_url(repo->url, hex, 1);
403
404 slot = get_active_slot();
405 slot->callback_func = process_response;
@@ -434,10 +434,10 @@ static void start_fetch_packed(struct transfer_request *request)
434 struct transfer_request *check_request = request_queue_head;
435 struct active_request_slot *slot;
436
437 - target = find_sha1_pack(request->obj->sha1, remote->packs);
437 + target = find_sha1_pack(request->obj->sha1, repo->packs);
438 if (!target) {
439 fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", sha1_to_hex(request->obj->sha1));
440 - remote->can_update_info_refs = 0;
440 + repo->can_update_info_refs = 0;
441 release_request(request);
442 return;
443 }
@@ -450,9 +450,9 @@ static void start_fetch_packed(struct transfer_request *request)
450 snprintf(request->tmpfile, sizeof(request->tmpfile),
451 "%s.temp", filename);
452
453 - url = xmalloc(strlen(remote->url) + 64);
453 + url = xmalloc(strlen(repo->url) + 64);
454 sprintf(url, "%sobjects/pack/pack-%s.pack",
455 - remote->url, sha1_to_hex(target->sha1));
455 + repo->url, sha1_to_hex(target->sha1));
456
457 /* Make sure there isn't another open request for this pack */
458 while (check_request) {
@@ -469,7 +469,7 @@ static void start_fetch_packed(struct transfer_request *request)
469 if (!packfile) {
470 fprintf(stderr, "Unable to open local file %s for pack",
471 request->tmpfile);
472 - remote->can_update_info_refs = 0;
472 + repo->can_update_info_refs = 0;
473 free(url);
474 return;
475 }
@@ -505,7 +505,7 @@ static void start_fetch_packed(struct transfer_request *request)
505 request->state = RUN_FETCH_PACKED;
506 if (!start_active_slot(slot)) {
507 fprintf(stderr, "Unable to start GET request\n");
508 - remote->can_update_info_refs = 0;
508 + repo->can_update_info_refs = 0;
509 release_request(request);
510 }
511 }
@@ -554,10 +554,10 @@ static void start_put(struct transfer_request *request)
554 request->buffer.buf.len = stream.total_out;
555
556 strbuf_addstr(&buf, "Destination: ");
557 - append_remote_object_url(&buf, remote->url, hex, 0);
557 + append_remote_object_url(&buf, repo->url, hex, 0);
558 request->dest = strbuf_detach(&buf, NULL);
559
560 - append_remote_object_url(&buf, remote->url, hex, 0);
560 + append_remote_object_url(&buf, repo->url, hex, 0);
561 strbuf_add(&buf, request->lock->tmpfile_suffix, 41);
562 request->url = strbuf_detach(&buf, NULL);
563
@@ -648,7 +648,7 @@ static int refresh_lock(struct remote_lock *lock)
648
649 static void check_locks(void)
650 {
651 - struct remote_lock *lock = remote->locks;
651 + struct remote_lock *lock = repo->locks;
652 time_t current_time = time(NULL);
653 int time_remaining;
654
@@ -788,7 +788,7 @@ static void finish_request(struct transfer_request *request)
788 if (request->curl_result != CURLE_OK) {
789 fprintf(stderr, "Unable to get pack file %s\n%s",
790 request->url, curl_errorstr);
791 - remote->can_update_info_refs = 0;
791 + repo->can_update_info_refs = 0;
792 } else {
793 off_t pack_size = ftell(request->local_stream);
794
@@ -798,7 +798,7 @@ static void finish_request(struct transfer_request *request)
798 request->filename)) {
799 target = (struct packed_git *)request->userData;
800 target->pack_size = pack_size;
801 - lst = &remote->packs;
801 + lst = &repo->packs;
802 while (*lst != target)
803 lst = &((*lst)->next);
804 *lst = (*lst)->next;
@@ -806,7 +806,7 @@ static void finish_request(struct transfer_request *request)
806 if (!verify_pack(target))
807 install_packed_git(target);
808 else
809 - remote->can_update_info_refs = 0;
809 + repo->can_update_info_refs = 0;
810 }
811 }
812 release_request(request);
@@ -889,7 +889,7 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
889 get_remote_object_list(obj->sha1[0]);
890 if (obj->flags & (REMOTE | PUSHING))
891 return 0;
892 - target = find_sha1_pack(obj->sha1, remote->packs);
892 + target = find_sha1_pack(obj->sha1, repo->packs);
893 if (target) {
894 obj->flags |= REMOTE;
895 return 0;
@@ -930,8 +930,8 @@ static int fetch_index(unsigned char *sha1)
930 struct slot_results results;
931
932 /* Don't use the index if the pack isn't there */
933 - url = xmalloc(strlen(remote->url) + 64);
934 - sprintf(url, "%sobjects/pack/pack-%s.pack", remote->url, hex);
933 + url = xmalloc(strlen(repo->url) + 64);
934 + sprintf(url, "%sobjects/pack/pack-%s.pack", repo->url, hex);
935 slot = get_active_slot();
936 slot->results = &results;
937 curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -956,7 +956,7 @@ static int fetch_index(unsigned char *sha1)
956 if (push_verbosely)
957 fprintf(stderr, "Getting index for pack %s\n", hex);
958
959 - sprintf(url, "%sobjects/pack/pack-%s.idx", remote->url, hex);
959 + sprintf(url, "%sobjects/pack/pack-%s.idx", repo->url, hex);
960
961 filename = sha1_pack_index_name(sha1);
962 snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
@@ -1018,8 +1018,8 @@ static int setup_index(unsigned char *sha1)
1018 return -1;
1019
1020 new_pack = parse_pack_index(sha1);
1021 - new_pack->next = remote->packs;
1022 - remote->packs = new_pack;
1021 + new_pack->next = repo->packs;
1022 + repo->packs = new_pack;
1023 return 0;
1024 }
1025
@@ -1037,8 +1037,8 @@ static int fetch_indices(void)
1037 if (push_verbosely)
1038 fprintf(stderr, "Getting pack list\n");
1039
1040 - url = xmalloc(strlen(remote->url) + 20);
1041 - sprintf(url, "%sobjects/info/packs", remote->url);
1040 + url = xmalloc(strlen(repo->url) + 20);
1041 + sprintf(url, "%sobjects/info/packs", repo->url);
1042
1043 slot = get_active_slot();
1044 slot->results = &results;
@@ -1223,11 +1223,11 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
1223 struct curl_slist *dav_headers = NULL;
1224 struct xml_ctx ctx;
1225
1226 - url = xmalloc(strlen(remote->url) + strlen(path) + 1);
1227 - sprintf(url, "%s%s", remote->url, path);
1226 + url = xmalloc(strlen(repo->url) + strlen(path) + 1);
1227 + sprintf(url, "%s%s", repo->url, path);
1228
1229 /* Make sure leading directories exist for the remote ref */
1230 - ep = strchr(url + strlen(remote->url) + 1, '/');
1230 + ep = strchr(url + strlen(repo->url) + 1, '/');
1231 while (ep) {
1232 char saved_character = ep[1];
1233 ep[1] = '\0';
@@ -1319,8 +1319,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
1319 } else {
1320 lock->url = url;
1321 lock->start_time = time(NULL);
1322 - lock->next = remote->locks;
1323 - remote->locks = lock;
1322 + lock->next = repo->locks;
1323 + repo->locks = lock;
1324 }
1325
1326 return lock;
@@ -1330,7 +1330,7 @@ static int unlock_remote(struct remote_lock *lock)
1330 {
1331 struct active_request_slot *slot;
1332 struct slot_results results;
1333 - struct remote_lock *prev = remote->locks;
1333 + struct remote_lock *prev = repo->locks;
1334 struct curl_slist *dav_headers;
1335 int rc = 0;
1336
@@ -1356,8 +1356,8 @@ static int unlock_remote(struct remote_lock *lock)
1356
1357 curl_slist_free_all(dav_headers);
1358
1359 - if (remote->locks == lock) {
1360 - remote->locks = lock->next;
1359 + if (repo->locks == lock) {
1360 + repo->locks = lock->next;
1361 } else {
1362 while (prev && prev->next != lock)
1363 prev = prev->next;
@@ -1375,7 +1375,7 @@ static int unlock_remote(struct remote_lock *lock)
1375
1376 static void remove_locks(void)
1377 {
1378 - struct remote_lock *lock = remote->locks;
1378 + struct remote_lock *lock = repo->locks;
1379
1380 fprintf(stderr, "Removing remote locks...\n");
1381 while (lock) {
@@ -1457,7 +1457,7 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)
1457 }
1458 }
1459 if (path) {
1460 - path += remote->path_len;
1460 + path += repo->path_len;
1461 ls->dentry_name = xstrdup(path);
1462 }
1463 } else if (!strcmp(ctx->name, DAV_PROPFIND_COLLECTION)) {
@@ -1480,7 +1480,7 @@ static void remote_ls(const char *path, int flags,
1480 void (*userFunc)(struct remote_ls_ctx *ls),
1481 void *userData)
1482 {
1483 - char *url = xmalloc(strlen(remote->url) + strlen(path) + 1);
1483 + char *url = xmalloc(strlen(repo->url) + strlen(path) + 1);
1484 struct active_request_slot *slot;
1485 struct slot_results results;
1486 struct strbuf in_buffer = STRBUF_INIT;
@@ -1496,7 +1496,7 @@ static void remote_ls(const char *path, int flags,
1496 ls.userData = userData;
1497 ls.userFunc = userFunc;
1498
1499 - sprintf(url, "%s%s", remote->url, path);
1499 + sprintf(url, "%s%s", repo->url, path);
1500
1501 strbuf_addf(&out_buffer.buf, PROPFIND_ALL_REQUEST);
1502
@@ -1574,7 +1574,7 @@ static int locking_available(void)
1574 struct xml_ctx ctx;
1575 int lock_flags = 0;
1576
1577 - strbuf_addf(&out_buffer.buf, PROPFIND_SUPPORTEDLOCK_REQUEST, remote->url);
1577 + strbuf_addf(&out_buffer.buf, PROPFIND_SUPPORTEDLOCK_REQUEST, repo->url);
1578
1579 dav_headers = curl_slist_append(dav_headers, "Depth: 0");
1580 dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
@@ -1586,7 +1586,7 @@ static int locking_available(void)
1586 curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
1587 curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
1588 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
1589 - curl_easy_setopt(slot->curl, CURLOPT_URL, remote->url);
1589 + curl_easy_setopt(slot->curl, CURLOPT_URL, repo->url);
1590 curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
1591 curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PROPFIND);
1592 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
@@ -1617,15 +1617,15 @@ static int locking_available(void)
1617 XML_ParserFree(parser);
1618 if (!lock_flags)
1619 error("Error: no DAV locking support on %s",
1620 - remote->url);
1620 + repo->url);
1621
1622 } else {
1623 error("Cannot access URL %s, return code %d",
1624 - remote->url, results.curl_result);
1624 + repo->url, results.curl_result);
1625 lock_flags = 0;
1626 }
1627 } else {
1628 - error("Unable to start PROPFIND request on %s", remote->url);
1628 + error("Unable to start PROPFIND request on %s", repo->url);
1629 }
1630
1631 strbuf_release(&out_buffer.buf);
@@ -1814,10 +1814,10 @@ static void one_remote_ref(char *refname)
1814
1815 ref = alloc_ref(refname);
1816
1817 - if (http_fetch_ref(remote->url, ref) != 0) {
1817 + if (http_fetch_ref(repo->url, ref) != 0) {
1818 fprintf(stderr,
1819 "Unable to fetch ref %s from %s\n",
1820 - refname, remote->url);
1820 + refname, repo->url);
1821 free(ref);
1822 return;
1823 }
@@ -1826,7 +1826,7 @@ static void one_remote_ref(char *refname)
1826 * Fetch a copy of the object if it doesn't exist locally - it
1827 * may be required for updating server info later.
1828 */
1829 - if (remote->can_update_info_refs && !has_sha1_file(ref->old_sha1)) {
1829 + if (repo->can_update_info_refs && !has_sha1_file(ref->old_sha1)) {
1830 obj = lookup_unknown_object(ref->old_sha1);
1831 if (obj) {
1832 fprintf(stderr, " fetch %s for %s\n",
@@ -1921,10 +1921,10 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
1921
1922 ref = alloc_ref(ls->dentry_name);
1923
1924 - if (http_fetch_ref(remote->url, ref) != 0) {
1924 + if (http_fetch_ref(repo->url, ref) != 0) {
1925 fprintf(stderr,
1926 "Unable to fetch ref %s from %s\n",
1927 - ls->dentry_name, remote->url);
1927 + ls->dentry_name, repo->url);
1928 aborted = 1;
1929 free(ref);
1930 return;
@@ -1999,12 +1999,12 @@ static void update_remote_info_refs(struct remote_lock *lock)
1999
2000 static int remote_exists(const char *path)
2001 {
2002 - char *url = xmalloc(strlen(remote->url) + strlen(path) + 1);
2002 + char *url = xmalloc(strlen(repo->url) + strlen(path) + 1);
2003 struct active_request_slot *slot;
2004 struct slot_results results;
2005 int ret = -1;
2006
2007 - sprintf(url, "%s%s", remote->url, path);
2007 + sprintf(url, "%s%s", repo->url, path);
2008
2009 slot = get_active_slot();
2010 slot->results = &results;
@@ -2034,8 +2034,8 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
2034 struct active_request_slot *slot;
2035 struct slot_results results;
2036
2037 - url = xmalloc(strlen(remote->url) + strlen(path) + 1);
2038 - sprintf(url, "%s%s", remote->url, path);
2037 + url = xmalloc(strlen(repo->url) + strlen(path) + 1);
2038 + sprintf(url, "%s%s", repo->url, path);
2039
2040 slot = get_active_slot();
2041 slot->results = &results;
@@ -2150,7 +2150,7 @@ static int delete_remote_branch(char *pattern, int force)
2150 "of your current HEAD.\n"
2151 "If you are sure you want to delete it,"
2152 " run:\n\t'git http-push -D %s %s'",
2153 - remote_ref->name, remote->url, pattern);
2153 + remote_ref->name, repo->url, pattern);
2154 }
2155 }
2156
@@ -2158,8 +2158,8 @@ static int delete_remote_branch(char *pattern, int force)
2158 fprintf(stderr, "Removing remote branch '%s'\n", remote_ref->name);
2159 if (dry_run)
2160 return 0;
2161 - url = xmalloc(strlen(remote->url) + strlen(remote_ref->name) + 1);
2162 - sprintf(url, "%s%s", remote->url, remote_ref->name);
2161 + url = xmalloc(strlen(repo->url) + strlen(remote_ref->name) + 1);
2162 + sprintf(url, "%s%s", repo->url, remote_ref->name);
2163 slot = get_active_slot();
2164 slot->results = &results;
2165 curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
@@ -2202,7 +2202,7 @@ int main(int argc, char **argv)
2202
2203 setup_git_directory();
2204
2205 - remote = xcalloc(sizeof(*remote), 1);
2205 + repo = xcalloc(sizeof(*repo), 1);
2206
2207 argv++;
2208 for (i = 1; i < argc; i++, argv++) {
@@ -2235,14 +2235,14 @@ int main(int argc, char **argv)
2235 continue;
2236 }
2237 }
2238 - if (!remote->url) {
2238 + if (!repo->url) {
2239 char *path = strstr(arg, "//");
2240 - remote->url = arg;
2241 - remote->path_len = strlen(arg);
2240 + repo->url = arg;
2241 + repo->path_len = strlen(arg);
2242 if (path) {
2243 - remote->path = strchr(path+2, '/');
2244 - if (remote->path)
2245 - remote->path_len = strlen(remote->path);
2243 + repo->path = strchr(path+2, '/');
2244 + if (repo->path)
2245 + repo->path_len = strlen(repo->path);
2246 }
2247 continue;
2248 }
@@ -2255,7 +2255,7 @@ int main(int argc, char **argv)
2255 die("git-push is not available for http/https repository when not compiled with USE_CURL_MULTI");
2256 #endif
2257
2258 - if (!remote->url)
2258 + if (!repo->url)
2259 usage(http_push_usage);
2260
2261 if (delete_branch && nr_refspec != 1)
@@ -2267,13 +2267,13 @@ int main(int argc, char **argv)
2267
2268 no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
2269
2270 - if (remote->url && remote->url[strlen(remote->url)-1] != '/') {
2271 - rewritten_url = xmalloc(strlen(remote->url)+2);
2272 - strcpy(rewritten_url, remote->url);
2270 + if (repo->url && repo->url[strlen(repo->url)-1] != '/') {
2271 + rewritten_url = xmalloc(strlen(repo->url)+2);
2272 + strcpy(rewritten_url, repo->url);
2273 strcat(rewritten_url, "/");
2274 - remote->path = rewritten_url + (remote->path - remote->url);
2275 - remote->path_len++;
2276 - remote->url = rewritten_url;
2274 + repo->path = rewritten_url + (repo->path - repo->url);
2275 + repo->path_len++;
2276 + repo->url = rewritten_url;
2277 }
2278
2279 /* Verify DAV compliance/lock support */
@@ -2285,20 +2285,20 @@ int main(int argc, char **argv)
2285 sigchain_push_common(remove_locks_on_signal);
2286
2287 /* Check whether the remote has server info files */
2288 - remote->can_update_info_refs = 0;
2289 - remote->has_info_refs = remote_exists("info/refs");
2290 - remote->has_info_packs = remote_exists("objects/info/packs");
2291 - if (remote->has_info_refs) {
2288 + repo->can_update_info_refs = 0;
2289 + repo->has_info_refs = remote_exists("info/refs");
2290 + repo->has_info_packs = remote_exists("objects/info/packs");
2291 + if (repo->has_info_refs) {
2292 info_ref_lock = lock_remote("info/refs", LOCK_TIME);
2293 if (info_ref_lock)
2294 - remote->can_update_info_refs = 1;
2294 + repo->can_update_info_refs = 1;
2295 else {
2296 fprintf(stderr, "Error: cannot lock existing info/refs\n");
2297 rc = 1;
2298 goto cleanup;
2299 }
2300 }
2301 - if (remote->has_info_packs)
2301 + if (repo->has_info_packs)
2302 fetch_indices();
2303
2304 /* Get a list of all local and remote heads to validate refspecs */
@@ -2456,8 +2456,8 @@ int main(int argc, char **argv)
2456 }
2457
2458 /* Update remote server info if appropriate */
2459 - if (remote->has_info_refs && new_refs) {
2460 - if (info_ref_lock && remote->can_update_info_refs) {
2459 + if (repo->has_info_refs && new_refs) {
2460 + if (info_ref_lock && repo->can_update_info_refs) {
2461 fprintf(stderr, "Updating remote server info\n");
2462 if (!dry_run)
2463 update_remote_info_refs(info_ref_lock);
@@ -2470,7 +2470,7 @@ int main(int argc, char **argv)
2470 free(rewritten_url);
2471 if (info_ref_lock)
2472 unlock_remote(info_ref_lock);
2473 - free(remote);
2473 + free(repo);
2474
2475 curl_slist_free_all(no_pragma_header);
2476