Skip to content

Commit 4805125

Browse files
ttaylorrgitster
authored andcommitted
pack-objects: prepare write_reused_pack() for multi-pack reuse
The function `write_reused_pack()` within `builtin/pack-objects.c` is responsible for performing pack-reuse on a single pack, and has two main functions: - it dispatches a call to `write_reused_pack_verbatim()` to see if we can reuse portions of the packfile in whole-word chunks - for any remaining objects (that is, any objects that appear after the first "gap" in the bitmap), call write_reused_pack_one() on that object to record it for reuse. Prepare this function for multi-pack reuse by removing the assumption that the bit position corresponding to the first object being reused from a given pack must be at bit position zero. The changes in this function are mostly straightforward. Initialize `i` to the position of the first word to contain bits corresponding to that reuse pack. In most situations, we throw the initialized value away, since we end up replacing it with the return value from write_reused_pack_verbatim(), moving us past the section of whole words that we reused. Likewise, modify the per-object loop to ignore any bits at the beginning of the first word that do not belong to the pack currently being reused, as well as skip to the "done" section once we have processed the last bit corresponding to this pack. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 073b40e commit 4805125

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

builtin/pack-objects.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ static size_t write_reused_pack_verbatim(struct bitmapped_pack *reuse_packfile,
11271127
static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
11281128
struct hashfile *f)
11291129
{
1130-
size_t i = 0;
1130+
size_t i = reuse_packfile->bitmap_pos / BITS_IN_EWORD;
11311131
uint32_t offset;
11321132
off_t pack_start = hashfile_total(f) - sizeof(struct pack_header);
11331133
struct pack_window *w_curs = NULL;
@@ -1145,17 +1145,23 @@ static void write_reused_pack(struct bitmapped_pack *reuse_packfile,
11451145
break;
11461146

11471147
offset += ewah_bit_ctz64(word >> offset);
1148+
if (pos + offset < reuse_packfile->bitmap_pos)
1149+
continue;
1150+
if (pos + offset >= reuse_packfile->bitmap_pos + reuse_packfile->bitmap_nr)
1151+
goto done;
11481152
/*
11491153
* Can use bit positions directly, even for MIDX
11501154
* bitmaps. See comment in try_partial_reuse()
11511155
* for why.
11521156
*/
1153-
write_reused_pack_one(reuse_packfile->p, pos + offset,
1157+
write_reused_pack_one(reuse_packfile->p,
1158+
pos + offset - reuse_packfile->bitmap_pos,
11541159
f, pack_start, &w_curs);
11551160
display_progress(progress_state, ++written);
11561161
}
11571162
}
11581163

1164+
done:
11591165
unuse_pack(&w_curs);
11601166
}
11611167

0 commit comments

Comments
 (0)