From: Derrick Stolee Date: Mon, 27 Jan 2025 19:02:34 +0000 (+0000) Subject: pack-objects: prevent name hash version change X-Git-Tag: v2.49.0-rc0~43^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b4cf68476a983ff063846b43cd46ee9805f2c0bb;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 8ae77deb92..fa09a35cf5 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -284,6 +284,14 @@ static void validate_name_hash_version(void) static inline uint32_t pack_name_hash_fn(const char *name) { + static int seen_version = -1; + + if (seen_version < 0) + seen_version = name_hash_version; + else if (seen_version != name_hash_version) + BUG("name hash version changed from %d to %d mid-process", + seen_version, name_hash_version); + switch (name_hash_version) { case 1: return pack_name_hash(name);