Skip to content

Commit 3885ef8

Browse files
committed
pack-objects: prevent name hash version change
When the --name-hash-version option is used in 'git pack-objects', it can change from the initial assignment to when it is used based on interactions with other arguments. Specifically, when writing or reading bitmaps, we must force version 1 for now. This could change in the future when the bitmap format can store a name hash version value, indicating which was used during the writing of the packfile. Protect the 'git pack-objects' process from getting confused by failing with a BUG() statement if the value of the name hash version changes between calls to pack_name_hash_fn(). Signed-off-by: Derrick Stolee <[email protected]>
1 parent 36f2811 commit 3885ef8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

builtin/pack-objects.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ static void validate_name_hash_version(void)
276276

277277
static inline uint32_t pack_name_hash_fn(const char *name)
278278
{
279+
static int seen_version = -1;
280+
281+
if (seen_version < 0)
282+
seen_version = name_hash_version;
283+
else if (seen_version != name_hash_version)
284+
BUG("name hash version changed from %d to %d mid-process",
285+
seen_version, name_hash_version);
286+
279287
switch (name_hash_version)
280288
{
281289
case 1:

0 commit comments

Comments
 (0)