@@ -269,6 +269,39 @@ struct configured_exclusion {
269269static struct oidmap configured_exclusions ;
270270
271271static struct oidset excluded_by_config ;
272+ static int name_hash_version = -1 ;
273+
274+ static void validate_name_hash_version (void )
275+ {
276+ if (name_hash_version < 1 || name_hash_version > 3 )
277+ die (_ ("invalid --name-hash-version option: %d" ), name_hash_version );
278+ }
279+
280+ static inline uint32_t pack_name_hash_fn (const char * name )
281+ {
282+ static int seen_version = -1 ;
283+
284+ if (seen_version < 0 )
285+ seen_version = name_hash_version ;
286+ else if (seen_version != name_hash_version )
287+ BUG ("name hash version changed from %d to %d mid-process" ,
288+ seen_version , name_hash_version );
289+
290+ switch (name_hash_version )
291+ {
292+ case 1 :
293+ return pack_name_hash (name );
294+
295+ case 2 :
296+ return pack_name_hash_v2 ((const unsigned char * )name );
297+
298+ case 3 :
299+ return pack_name_hash_v3 (name );
300+
301+ default :
302+ BUG ("invalid name-hash version: %d" , name_hash_version );
303+ }
304+ }
272305
273306/*
274307 * stats
@@ -1688,7 +1721,7 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
16881721 return 0 ;
16891722 }
16901723
1691- create_object_entry (oid , type , pack_name_hash (name ),
1724+ create_object_entry (oid , type , pack_name_hash_fn (name ),
16921725 exclude , name && no_try_delta (name ),
16931726 found_pack , found_offset );
16941727 return 1 ;
@@ -1902,7 +1935,7 @@ static void add_preferred_base_object(const char *name)
19021935{
19031936 struct pbase_tree * it ;
19041937 size_t cmplen ;
1905- unsigned hash = pack_name_hash (name );
1938+ unsigned hash = pack_name_hash_fn (name );
19061939
19071940 if (!num_preferred_base || check_pbase_path (hash ))
19081941 return ;
@@ -3414,7 +3447,7 @@ static void show_object_pack_hint(struct object *object, const char *name,
34143447 * here using a now in order to perhaps improve the delta selection
34153448 * process.
34163449 */
3417- oe -> hash = pack_name_hash (name );
3450+ oe -> hash = pack_name_hash_fn (name );
34183451 oe -> no_try_delta = name && no_try_delta (name );
34193452
34203453 stdin_packs_hints_nr ++ ;
@@ -3564,7 +3597,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
35643597 entry = packlist_find (& to_pack , oid );
35653598 if (entry ) {
35663599 if (name ) {
3567- entry -> hash = pack_name_hash (name );
3600+ entry -> hash = pack_name_hash_fn (name );
35683601 entry -> no_try_delta = no_try_delta (name );
35693602 }
35703603 } else {
@@ -3587,7 +3620,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
35873620 return ;
35883621 }
35893622
3590- entry = create_object_entry (oid , type , pack_name_hash (name ),
3623+ entry = create_object_entry (oid , type , pack_name_hash_fn (name ),
35913624 0 , name && no_try_delta (name ),
35923625 pack , offset );
35933626 }
@@ -4067,6 +4100,15 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
40674100 if (!(bitmap_git = prepare_bitmap_walk (revs , 0 )))
40684101 return -1 ;
40694102
4103+ /*
4104+ * For now, force the name-hash version to be 1 since that
4105+ * is the version implied by the bitmap format. Later, the
4106+ * format can include this version explicitly in its format,
4107+ * allowing readers to know the version that was used during
4108+ * the bitmap write.
4109+ */
4110+ name_hash_version = 1 ;
4111+
40704112 if (pack_options_allow_reuse ())
40714113 reuse_partial_packfile_from_bitmap (bitmap_git ,
40724114 & reuse_packfiles ,
@@ -4442,6 +4484,8 @@ int cmd_pack_objects(int argc,
44424484 OPT_STRING_LIST (0 , "uri-protocol" , & uri_protocols ,
44434485 N_ ("protocol" ),
44444486 N_ ("exclude any configured uploadpack.blobpackfileuri with this protocol" )),
4487+ OPT_INTEGER (0 , "name-hash-version" , & name_hash_version ,
4488+ N_ ("use the specified name-hash function to group similar objects" )),
44454489 OPT_END (),
44464490 };
44474491
@@ -4597,6 +4641,15 @@ int cmd_pack_objects(int argc,
45974641 if (pack_to_stdout || !rev_list_all )
45984642 write_bitmap_index = 0 ;
45994643
4644+ if (name_hash_version < 0 )
4645+ name_hash_version = (int )git_env_ulong ("GIT_TEST_NAME_HASH_VERSION" , 1 );
4646+
4647+ validate_name_hash_version ();
4648+ if (write_bitmap_index && name_hash_version != 1 ) {
4649+ warning (_ ("currently, --write-bitmap-index requires --name-hash-version=1" ));
4650+ name_hash_version = 1 ;
4651+ }
4652+
46004653 if (use_delta_islands )
46014654 strvec_push (& rp , "--topo-order" );
46024655
0 commit comments