@@ -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 (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
@@ -1687,7 +1720,7 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
16871720 return 0 ;
16881721 }
16891722
1690- create_object_entry (oid , type , pack_name_hash (name ),
1723+ create_object_entry (oid , type , pack_name_hash_fn (name ),
16911724 exclude , name && no_try_delta (name ),
16921725 found_pack , found_offset );
16931726 return 1 ;
@@ -1901,7 +1934,7 @@ static void add_preferred_base_object(const char *name)
19011934{
19021935 struct pbase_tree * it ;
19031936 size_t cmplen ;
1904- unsigned hash = pack_name_hash (name );
1937+ unsigned hash = pack_name_hash_fn (name );
19051938
19061939 if (!num_preferred_base || check_pbase_path (hash ))
19071940 return ;
@@ -3411,7 +3444,7 @@ static void show_object_pack_hint(struct object *object, const char *name,
34113444 * here using a now in order to perhaps improve the delta selection
34123445 * process.
34133446 */
3414- oe -> hash = pack_name_hash (name );
3447+ oe -> hash = pack_name_hash_fn (name );
34153448 oe -> no_try_delta = name && no_try_delta (name );
34163449
34173450 stdin_packs_hints_nr ++ ;
@@ -3561,7 +3594,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
35613594 entry = packlist_find (& to_pack , oid );
35623595 if (entry ) {
35633596 if (name ) {
3564- entry -> hash = pack_name_hash (name );
3597+ entry -> hash = pack_name_hash_fn (name );
35653598 entry -> no_try_delta = no_try_delta (name );
35663599 }
35673600 } else {
@@ -3584,7 +3617,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
35843617 return ;
35853618 }
35863619
3587- entry = create_object_entry (oid , type , pack_name_hash (name ),
3620+ entry = create_object_entry (oid , type , pack_name_hash_fn (name ),
35883621 0 , name && no_try_delta (name ),
35893622 pack , offset );
35903623 }
@@ -4061,6 +4094,15 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
40614094 if (!(bitmap_git = prepare_bitmap_walk (revs , 0 )))
40624095 return -1 ;
40634096
4097+ /*
4098+ * For now, force the name-hash version to be 1 since that
4099+ * is the version implied by the bitmap format. Later, the
4100+ * format can include this version explicitly in its format,
4101+ * allowing readers to know the version that was used during
4102+ * the bitmap write.
4103+ */
4104+ name_hash_version = 1 ;
4105+
40644106 if (pack_options_allow_reuse ())
40654107 reuse_partial_packfile_from_bitmap (bitmap_git ,
40664108 & reuse_packfiles ,
@@ -4436,6 +4478,8 @@ int cmd_pack_objects(int argc,
44364478 OPT_STRING_LIST (0 , "uri-protocol" , & uri_protocols ,
44374479 N_ ("protocol" ),
44384480 N_ ("exclude any configured uploadpack.blobpackfileuri with this protocol" )),
4481+ OPT_INTEGER (0 , "name-hash-version" , & name_hash_version ,
4482+ N_ ("use the specified name-hash function to group similar objects" )),
44394483 OPT_END (),
44404484 };
44414485
@@ -4591,6 +4635,15 @@ int cmd_pack_objects(int argc,
45914635 if (pack_to_stdout || !rev_list_all )
45924636 write_bitmap_index = 0 ;
45934637
4638+ if (name_hash_version < 0 )
4639+ name_hash_version = (int )git_env_ulong ("GIT_TEST_NAME_HASH_VERSION" , 1 );
4640+
4641+ validate_name_hash_version ();
4642+ if (write_bitmap_index && name_hash_version != 1 ) {
4643+ warning (_ ("currently, --write-bitmap-index requires --name-hash-version=1" ));
4644+ name_hash_version = 1 ;
4645+ }
4646+
45944647 if (use_delta_islands )
45954648 strvec_push (& rp , "--topo-order" );
45964649
0 commit comments