diff options
Diffstat (limited to 'http-walker.c')
-rw-r--r-- | http-walker.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/http-walker.c b/http-walker.c index 51a906e9e3..88da5468e7 100644 --- a/http-walker.c +++ b/http-walker.c @@ -230,7 +230,6 @@ static void process_alternates_response(void *callback_data) int okay = 0; int serverlen = 0; struct alt_base *newalt; - char *target = NULL; if (data[i] == '/') { /* * This counts @@ -287,17 +286,15 @@ static void process_alternates_response(void *callback_data) } /* skip "objects\n" at end */ if (okay) { - target = xmalloc(serverlen + posn - i - 6); - memcpy(target, base, serverlen); - memcpy(target + serverlen, data + i, - posn - i - 7); - target[serverlen + posn - i - 7] = 0; + struct strbuf target = STRBUF_INIT; + strbuf_add(&target, base, serverlen); + strbuf_add(&target, data + i, posn - i - 7); if (walker->get_verbosely) - fprintf(stderr, - "Also look at %s\n", target); + fprintf(stderr, "Also look at %s\n", + target.buf); newalt = xmalloc(sizeof(*newalt)); newalt->next = NULL; - newalt->base = target; + newalt->base = strbuf_detach(&target, NULL); newalt->got_indices = 0; newalt->packs = NULL; @@ -341,8 +338,7 @@ static void fetch_alternates(struct walker *walker, const char *base) if (walker->get_verbosely) fprintf(stderr, "Getting alternates list for %s\n", base); - url = xmalloc(strlen(base) + 31); - sprintf(url, "%s/objects/info/http-alternates", base); + url = xstrfmt("%s/objects/info/http-alternates", base); /* * Use a callback to process the result, since another request @@ -396,7 +392,7 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo) return ret; } -static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1) +static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1) { struct packed_git *target; int ret; @@ -524,7 +520,7 @@ static int fetch(struct walker *walker, unsigned char *sha1) if (!fetch_object(walker, altbase, sha1)) return 0; while (altbase) { - if (!fetch_pack(walker, altbase, sha1)) + if (!http_fetch_pack(walker, altbase, sha1)) return 0; fetch_alternates(walker, data->alt->base); altbase = altbase->next; @@ -566,8 +562,7 @@ struct walker *get_http_walker(const char *url) struct walker *walker = xmalloc(sizeof(struct walker)); data->alt = xmalloc(sizeof(*data->alt)); - data->alt->base = xmalloc(strlen(url) + 1); - strcpy(data->alt->base, url); + data->alt->base = xstrdup(url); for (s = data->alt->base + strlen(data->alt->base) - 1; *s == '/'; --s) *s = 0; |