aboutsummaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-09-27 00:52:47 -0700
committerJunio C Hamano <gitster@pobox.com>2007-09-27 00:52:47 -0700
commita17ba31b0b75365e1245e494d46abae4afc57480 (patch)
tree41c1d800c92e60d97a8b984dce086bcb3473dcc2 /read-cache.c
parent0f729f21348c43a1c80f48faed2e753b1c923e85 (diff)
parent6d69b6f6ac27ab6f71a10da34b813ca25fd2a358 (diff)
downloadgit-a17ba31b0b75365e1245e494d46abae4afc57480.tar.gz
git-a17ba31b0b75365e1245e494d46abae4afc57480.tar.xz
Merge branch 'ph/strbuf' into kh/commit
* ph/strbuf: Clean up stripspace a bit, use strbuf even more. Add strbuf_read_file(). rerere: Fix use of an empty strbuf.buf Small cache_tree_write refactor. Make builtin-rerere use of strbuf nicer and more efficient. Add strbuf_cmp. strbuf_setlen(): do not barf on setting length of an empty buffer to 0 sq_quote_argv and add_to_string rework with strbuf's. Full rework of quote_c_style and write_name_quoted. Rework unquote_c_style to work on a strbuf. strbuf API additions and enhancements. nfv?asprintf are broken without va_copy, workaround them. Fix the expansion pattern of the pseudo-static path buffer.
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/read-cache.c b/read-cache.c
index 2e40a3442..56202d13d 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1136,7 +1136,7 @@ int write_index(struct index_state *istate, int newfd)
{
SHA_CTX c;
struct cache_header hdr;
- int i, removed;
+ int i, err, removed;
struct cache_entry **cache = istate->cache;
int entries = istate->cache_nr;
@@ -1165,16 +1165,15 @@ int write_index(struct index_state *istate, int newfd)
/* Write extension data here */
if (istate->cache_tree) {
- unsigned long sz;
- void *data = cache_tree_write(istate->cache_tree, &sz);
- if (data &&
- !write_index_ext_header(&c, newfd, CACHE_EXT_TREE, sz) &&
- !ce_write(&c, newfd, data, sz))
- free(data);
- else {
- free(data);
+ struct strbuf sb;
+
+ strbuf_init(&sb, 0);
+ cache_tree_write(&sb, istate->cache_tree);
+ err = write_index_ext_header(&c, newfd, CACHE_EXT_TREE, sb.len) < 0
+ || ce_write(&c, newfd, sb.buf, sb.len) < 0;
+ strbuf_release(&sb);
+ if (err)
return -1;
- }
}
return ce_flush(&c, newfd);
}