Skip to content

Commit bb2a1ce

Browse files
ttaylorrgitster
authored andcommitted
midx-write.c: simplify fill_packs_from_midx()
When enumerating packs within fill_packs_from_midx(), we open the pack's index iff we are either writing a reverse index, have a preferred pack (by name) or both. Let's simplify this into a single case by setting the MIDX_WRITE_REV_INDEX flag bit when we have a preferred_pack_name. This is a little bit of a shortcut to reduce the line length in the loop below. But it sets us up nicely to extract the inner loop of this function out into its own function, where we will no longer have to pass the preferred_pack_name. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aaaddf6 commit bb2a1ce

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

midx-write.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,19 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,
943943
{
944944
struct multi_pack_index *m;
945945

946+
if (preferred_pack_name) {
947+
/*
948+
* If a preferred pack is specified, need to have
949+
* packed_git's loaded to ensure the chosen preferred
950+
* pack has a non-zero object count.
951+
*
952+
* Trick ourselves into thinking that we're writing a
953+
* reverse index in this case in order to open up the
954+
* pack index file.
955+
*/
956+
flags |= MIDX_WRITE_REV_INDEX;
957+
}
958+
946959
for (m = ctx->m; m; m = m->base_midx) {
947960
uint32_t i;
948961

@@ -953,13 +966,8 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,
953966
* If generating a reverse index, need to have
954967
* packed_git's loaded to compare their
955968
* mtimes and object count.
956-
*
957-
* If a preferred pack is specified, need to
958-
* have packed_git's loaded to ensure the chosen
959-
* preferred pack has a non-zero object count.
960969
*/
961-
if (flags & MIDX_WRITE_REV_INDEX ||
962-
preferred_pack_name) {
970+
if (flags & MIDX_WRITE_REV_INDEX) {
963971
if (prepare_midx_pack(ctx->repo, m,
964972
m->num_packs_in_base + i)) {
965973
error(_("could not load pack"));

0 commit comments

Comments
 (0)