Skip to content

Commit 0bc091d

Browse files
committed
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.
1 parent 27cb4e0 commit 0bc091d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/pack-objects.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,9 @@ int git_packbuilder_write(
13841384
git_indexer_progress_cb progress_cb,
13851385
void *progress_cb_payload)
13861386
{
1387+
int error = -1;
13871388
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
1388-
git_indexer *indexer;
1389+
git_indexer *indexer = NULL;
13891390
git_indexer_progress stats;
13901391
struct pack_write_context ctx;
13911392
int t;
@@ -1395,26 +1396,26 @@ int git_packbuilder_write(
13951396
opts.progress_cb = progress_cb;
13961397
opts.progress_cb_payload = progress_cb_payload;
13971398

1398-
if (git_indexer_new(
1399-
&indexer, path, mode, pb->odb, &opts) < 0)
1400-
return -1;
1399+
if ((error = git_indexer_new(&indexer, path, mode, pb->odb, &opts)) < 0)
1400+
goto cleanup;
14011401

14021402
if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t)
14031403
git_indexer__set_fsync(indexer, 1);
14041404

14051405
ctx.indexer = indexer;
14061406
ctx.stats = &stats;
14071407

1408-
if (git_packbuilder_foreach(pb, write_cb, &ctx) < 0 ||
1409-
git_indexer_commit(indexer, &stats) < 0) {
1410-
git_indexer_free(indexer);
1411-
return -1;
1412-
}
1408+
if ((error = git_packbuilder_foreach(pb, write_cb, &ctx)) < 0)
1409+
goto cleanup;
1410+
1411+
if ((error = git_indexer_commit(indexer, &stats)) < 0)
1412+
goto cleanup;
14131413

14141414
git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer));
14151415

1416+
cleanup:
14161417
git_indexer_free(indexer);
1417-
return 0;
1418+
return error;
14181419
}
14191420

14201421
#undef PREPARE_PACK

0 commit comments

Comments
 (0)