@matheusbsbs / matheus-bagliano / commits / bb99190e27
Fork 0

http.c: replace usage of temporary variable for urls

Use preq->url in new_http_pack_request and freq->url in new_http_object_request when calling curl_setopt(CURLOPT_URL), instead of using an intermediate variable, 'url'. Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Aug 10, 2009 at 23:59 UTC bb99190e27c455867bb364059f9a44c0571fc914
1 file changed +6 -9
http.c
+6 -9
@@ -1004,7 +1004,6 @@ int finish_http_pack_request(struct http_pack_request *preq)
1004 struct http_pack_request *new_http_pack_request(
1005 struct packed_git *target, const char *base_url)
1006 {
1007 - char *url;
1007 char *filename;
1008 long prev_posn = 0;
1009 char range[RANGE_HEADER_SIZE];
@@ -1018,8 +1017,7 @@ struct http_pack_request *new_http_pack_request(
1017 end_url_with_slash(&buf, base_url);
1018 strbuf_addf(&buf, "objects/pack/pack-%s.pack",
1019 sha1_to_hex(target->sha1));
1021 - url = strbuf_detach(&buf, NULL);
1022 - preq->url = xstrdup(url);
1020 + preq->url = strbuf_detach(&buf, NULL);
1021
1022 filename = sha1_pack_name(target->sha1);
1023 snprintf(preq->filename, sizeof(preq->filename), "%s", filename);
@@ -1035,7 +1033,7 @@ struct http_pack_request *new_http_pack_request(
1033 preq->slot->local = preq->packfile;
1034 curl_easy_setopt(preq->slot->curl, CURLOPT_FILE, preq->packfile);
1035 curl_easy_setopt(preq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
1038 - curl_easy_setopt(preq->slot->curl, CURLOPT_URL, url);
1036 + curl_easy_setopt(preq->slot->curl, CURLOPT_URL, preq->url);
1037 curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER,
1038 no_pragma_header);
1039
@@ -1059,6 +1057,7 @@ struct http_pack_request *new_http_pack_request(
1057
1058 abort:
1059 free(filename);
1060 + free(preq->url);
1061 free(preq);
1062 return NULL;
1063 }
@@ -1099,7 +1098,6 @@ struct http_object_request *new_http_object_request(const char *base_url,
1098 char *hex = sha1_to_hex(sha1);
1099 char *filename;
1100 char prevfile[PATH_MAX];
1102 - char *url;
1101 int prevlocal;
1102 unsigned char prev_buf[PREV_BUF_SIZE];
1103 ssize_t prev_read = 0;
@@ -1153,8 +1151,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
1151
1152 git_SHA1_Init(&freq->c);
1153
1156 - url = get_remote_object_url(base_url, hex, 0);
1157 - freq->url = xstrdup(url);
1154 + freq->url = get_remote_object_url(base_url, hex, 0);
1155
1156 /*
1157 * If a previous temp file is present, process what was already
@@ -1199,7 +1196,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
1196 curl_easy_setopt(freq->slot->curl, CURLOPT_FILE, freq);
1197 curl_easy_setopt(freq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
1198 curl_easy_setopt(freq->slot->curl, CURLOPT_ERRORBUFFER, freq->errorstr);
1202 - curl_easy_setopt(freq->slot->curl, CURLOPT_URL, url);
1199 + curl_easy_setopt(freq->slot->curl, CURLOPT_URL, freq->url);
1200 curl_easy_setopt(freq->slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
1201
1202 /*
@@ -1219,9 +1216,9 @@ struct http_object_request *new_http_object_request(const char *base_url,
1216
1217 return freq;
1218
1222 - free(url);
1219 abort:
1220 free(filename);
1221 + free(freq->url);
1222 free(freq);
1223 return NULL;
1224 }