Commit 0bc091dd by Josh Triplett

git_packbuilder_write: Unify cleanup path

Clean up and return via a single label, to avoid duplicate error
handling before each return, and to make it easier to extend the set of
cleanups needed.
parent 27cb4e0e
...@@ -1384,8 +1384,9 @@ int git_packbuilder_write( ...@@ -1384,8 +1384,9 @@ int git_packbuilder_write(
git_indexer_progress_cb progress_cb, git_indexer_progress_cb progress_cb,
void *progress_cb_payload) void *progress_cb_payload)
{ {
int error = -1;
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
git_indexer *indexer; git_indexer *indexer = NULL;
git_indexer_progress stats; git_indexer_progress stats;
struct pack_write_context ctx; struct pack_write_context ctx;
int t; int t;
...@@ -1395,9 +1396,8 @@ int git_packbuilder_write( ...@@ -1395,9 +1396,8 @@ int git_packbuilder_write(
opts.progress_cb = progress_cb; opts.progress_cb = progress_cb;
opts.progress_cb_payload = progress_cb_payload; opts.progress_cb_payload = progress_cb_payload;
if (git_indexer_new( if ((error = git_indexer_new(&indexer, path, mode, pb->odb, &opts)) < 0)
&indexer, path, mode, pb->odb, &opts) < 0) goto cleanup;
return -1;
if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t)
git_indexer__set_fsync(indexer, 1); git_indexer__set_fsync(indexer, 1);
...@@ -1405,16 +1405,17 @@ int git_packbuilder_write( ...@@ -1405,16 +1405,17 @@ int git_packbuilder_write(
ctx.indexer = indexer; ctx.indexer = indexer;
ctx.stats = &stats; ctx.stats = &stats;
if (git_packbuilder_foreach(pb, write_cb, &ctx) < 0 || if ((error = git_packbuilder_foreach(pb, write_cb, &ctx)) < 0)
git_indexer_commit(indexer, &stats) < 0) { goto cleanup;
git_indexer_free(indexer);
return -1; if ((error = git_indexer_commit(indexer, &stats)) < 0)
} goto cleanup;
git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer)); git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer));
cleanup:
git_indexer_free(indexer); git_indexer_free(indexer);
return 0; return error;
} }
#undef PREPARE_PACK #undef PREPARE_PACK
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment