remote-curl: make refs_url a strbuf

In the discover_refs function, we use a strbuf named "buffer" for multiple purposes. First we build the info/refs URL in it, and then detach that to a bare pointer. Then, we use the same strbuf to store the result of fetching the refs. Let's instead keep a separate refs_url strbuf. This is less confusing, as the "buffer" strbuf is now used for only one thing. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

Jeff King committed Sep 28, 2013 at 04:35 UTC c65d5692cd3434133c2e8f1a20074a261e0267f0
1 file changed +7 -8
remote-curl.c
+7 -8
@@ -185,8 +185,8 @@ static struct discovery* discover_refs(const char *service, int for_push)
185 struct strbuf exp = STRBUF_INIT;
186 struct strbuf type = STRBUF_INIT;
187 struct strbuf buffer = STRBUF_INIT;
188 + struct strbuf refs_url = STRBUF_INIT;
189 struct discovery *last = last_discovery;
189 - char *refs_url;
190 int http_ret, maybe_smart = 0;
191 struct http_get_options options;
192
@@ -194,24 +194,23 @@ static struct discovery* discover_refs(const char *service, int for_push)
194 return last;
195 free_discovery(last);
196
197 - strbuf_addf(&buffer, "%sinfo/refs", url);
197 + strbuf_addf(&refs_url, "%sinfo/refs", url);
198 if ((!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) &&
199 git_env_bool("GIT_SMART_HTTP", 1)) {
200 maybe_smart = 1;
201 if (!strchr(url, '?'))
202 - strbuf_addch(&buffer, '?');
202 + strbuf_addch(&refs_url, '?');
203 else
204 - strbuf_addch(&buffer, '&');
205 - strbuf_addf(&buffer, "service=%s", service);
204 + strbuf_addch(&refs_url, '&');
205 + strbuf_addf(&refs_url, "service=%s", service);
206 }
207 - refs_url = strbuf_detach(&buffer, NULL);
207
208 memset(&options, 0, sizeof(options));
209 options.content_type = &type;
210 options.no_cache = 1;
211 options.keep_error = 1;
212
214 - http_ret = http_get_strbuf(refs_url, &buffer, &options);
213 + http_ret = http_get_strbuf(refs_url.buf, &buffer, &options);
214 switch (http_ret) {
215 case HTTP_OK:
216 break;
@@ -264,7 +263,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
263 else
264 last->refs = parse_info_refs(last);
265
267 - free(refs_url);
266 + strbuf_release(&refs_url);
267 strbuf_release(&exp);
268 strbuf_release(&type);
269 strbuf_release(&buffer);