Skip to content

Commit

Permalink
http-walker: simplify process_alternates_response() using strbuf
Browse files Browse the repository at this point in the history
Use strbuf to build the new base, which takes care of allocations and
the terminating NUL character automatically.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Sep 2, 2014
1 parent 96db324 commit 59b8263
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions http-walker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 59b8263

Please sign in to comment.