Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit c65d569

Browse files
peffjrn
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent c93c92f commit c65d569

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

remote-curl.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,33 +185,32 @@ static struct discovery* discover_refs(const char *service, int for_push)
185185
struct strbuf exp = STRBUF_INIT;
186186
struct strbuf type = STRBUF_INIT;
187187
struct strbuf buffer = STRBUF_INIT;
188+
struct strbuf refs_url = STRBUF_INIT;
188189
struct discovery *last = last_discovery;
189-
char *refs_url;
190190
int http_ret, maybe_smart = 0;
191191
struct http_get_options options;
192192

193193
if (last && !strcmp(service, last->service))
194194
return last;
195195
free_discovery(last);
196196

197-
strbuf_addf(&buffer, "%sinfo/refs", url);
197+
strbuf_addf(&refs_url, "%sinfo/refs", url);
198198
if ((!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) &&
199199
git_env_bool("GIT_SMART_HTTP", 1)) {
200200
maybe_smart = 1;
201201
if (!strchr(url, '?'))
202-
strbuf_addch(&buffer, '?');
202+
strbuf_addch(&refs_url, '?');
203203
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);
206206
}
207-
refs_url = strbuf_detach(&buffer, NULL);
208207

209208
memset(&options, 0, sizeof(options));
210209
options.content_type = &type;
211210
options.no_cache = 1;
212211
options.keep_error = 1;
213212

214-
http_ret = http_get_strbuf(refs_url, &buffer, &options);
213+
http_ret = http_get_strbuf(refs_url.buf, &buffer, &options);
215214
switch (http_ret) {
216215
case HTTP_OK:
217216
break;
@@ -264,7 +263,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
264263
else
265264
last->refs = parse_info_refs(last);
266265

267-
free(refs_url);
266+
strbuf_release(&refs_url);
268267
strbuf_release(&exp);
269268
strbuf_release(&type);
270269
strbuf_release(&buffer);

0 commit comments

Comments
 (0)