Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
http-walker: simplify process_alternates_response() using strbuf
author
René Scharfe
<l.s.r@web.de>
Sat, 30 Aug 2014 15:55:45 +0000
(17:55 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Tue, 2 Sep 2014 17:57:14 +0000
(10:57 -0700)
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>
http-walker.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
96db324
)
diff --git
a/http-walker.c
b/http-walker.c
index dbddfaa1773265a2917d4715158f16845d7139e5..88da5468e77f5a543edb7583e2846f19eb509653 100644
(file)
--- 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;
int okay = 0;
int serverlen = 0;
struct alt_base *newalt;
- char *target = NULL;
if (data[i] == '/') {
/*
* This counts
if (data[i] == '/') {
/*
* This counts
@@
-287,17
+286,15
@@
static void process_alternates_response(void *callback_data)
}
/* skip "objects\n" at end */
if (okay) {
}
/* 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)
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 = xmalloc(sizeof(*newalt));
newalt->next = NULL;
- newalt->base =
target
;
+ newalt->base =
strbuf_detach(&target, NULL)
;
newalt->got_indices = 0;
newalt->packs = NULL;
newalt->got_indices = 0;
newalt->packs = NULL;