diff options
author | Pierre Habouzit <madcoder@debian.org> | 2007-09-25 10:22:44 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-09-26 02:27:06 -0700 |
commit | 1dffb8fa8056860e769f3a0c6e232d436f5a5c17 (patch) | |
tree | 51ac48c04be22c1af391fc1ec3bbdecc751bd0ff /read-cache.c | |
parent | 8289b6209552a57c255561a2585d0edbe96d62d3 (diff) | |
download | git-1dffb8fa8056860e769f3a0c6e232d436f5a5c17.tar.gz |
Small cache_tree_write refactor.
This function cannot fail, make it void. Also make write_one act on a
const char* instead of a char*.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/read-cache.c b/read-cache.c index 2e40a34420..56202d13df 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); } |