@@ -267,6 +267,39 @@ struct configured_exclusion {
267267static struct oidmap configured_exclusions ;
268268
269269static struct oidset excluded_by_config ;
270+ static int name_hash_version = -1 ;
271+
272+ static void validate_name_hash_version (void )
273+ {
274+ if (name_hash_version < 1 || name_hash_version > 3 )
275+ die (_ ("invalid --name-hash-version option: %d" ), name_hash_version );
276+ }
277+
278+ static inline uint32_t pack_name_hash_fn (const char * name )
279+ {
280+ static int seen_version = -1 ;
281+
282+ if (seen_version < 0 )
283+ seen_version = name_hash_version ;
284+ else if (seen_version != name_hash_version )
285+ BUG ("name hash version changed from %d to %d mid-process" ,
286+ seen_version , name_hash_version );
287+
288+ switch (name_hash_version )
289+ {
290+ case 1 :
291+ return pack_name_hash (name );
292+
293+ case 2 :
294+ return pack_name_hash_v2 (name );
295+
296+ case 3 :
297+ return pack_name_hash_v3 (name );
298+
299+ default :
300+ BUG ("invalid name-hash version: %d" , name_hash_version );
301+ }
302+ }
270303
271304/*
272305 * stats
@@ -1685,7 +1718,7 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
16851718 return 0 ;
16861719 }
16871720
1688- create_object_entry (oid , type , pack_name_hash (name ),
1721+ create_object_entry (oid , type , pack_name_hash_fn (name ),
16891722 exclude , name && no_try_delta (name ),
16901723 found_pack , found_offset );
16911724 return 1 ;
@@ -1899,7 +1932,7 @@ static void add_preferred_base_object(const char *name)
18991932{
19001933 struct pbase_tree * it ;
19011934 size_t cmplen ;
1902- unsigned hash = pack_name_hash (name );
1935+ unsigned hash = pack_name_hash_fn (name );
19031936
19041937 if (!num_preferred_base || check_pbase_path (hash ))
19051938 return ;
@@ -3409,7 +3442,7 @@ static void show_object_pack_hint(struct object *object, const char *name,
34093442 * here using a now in order to perhaps improve the delta selection
34103443 * process.
34113444 */
3412- oe -> hash = pack_name_hash (name );
3445+ oe -> hash = pack_name_hash_fn (name );
34133446 oe -> no_try_delta = name && no_try_delta (name );
34143447
34153448 stdin_packs_hints_nr ++ ;
@@ -3559,7 +3592,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
35593592 entry = packlist_find (& to_pack , oid );
35603593 if (entry ) {
35613594 if (name ) {
3562- entry -> hash = pack_name_hash (name );
3595+ entry -> hash = pack_name_hash_fn (name );
35633596 entry -> no_try_delta = no_try_delta (name );
35643597 }
35653598 } else {
@@ -3582,7 +3615,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
35823615 return ;
35833616 }
35843617
3585- entry = create_object_entry (oid , type , pack_name_hash (name ),
3618+ entry = create_object_entry (oid , type , pack_name_hash_fn (name ),
35863619 0 , name && no_try_delta (name ),
35873620 pack , offset );
35883621 }
@@ -4059,6 +4092,15 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
40594092 if (!(bitmap_git = prepare_bitmap_walk (revs , 0 )))
40604093 return -1 ;
40614094
4095+ /*
4096+ * For now, force the name-hash version to be 1 since that
4097+ * is the version implied by the bitmap format. Later, the
4098+ * format can include this version explicitly in its format,
4099+ * allowing readers to know the version that was used during
4100+ * the bitmap write.
4101+ */
4102+ name_hash_version = 1 ;
4103+
40624104 if (pack_options_allow_reuse ())
40634105 reuse_partial_packfile_from_bitmap (bitmap_git ,
40644106 & reuse_packfiles ,
@@ -4434,6 +4476,8 @@ int cmd_pack_objects(int argc,
44344476 OPT_STRING_LIST (0 , "uri-protocol" , & uri_protocols ,
44354477 N_ ("protocol" ),
44364478 N_ ("exclude any configured uploadpack.blobpackfileuri with this protocol" )),
4479+ OPT_INTEGER (0 , "name-hash-version" , & name_hash_version ,
4480+ N_ ("use the specified name-hash function to group similar objects" )),
44374481 OPT_END (),
44384482 };
44394483
@@ -4589,6 +4633,15 @@ int cmd_pack_objects(int argc,
45894633 if (pack_to_stdout || !rev_list_all )
45904634 write_bitmap_index = 0 ;
45914635
4636+ if (name_hash_version < 0 )
4637+ name_hash_version = (int )git_env_ulong ("GIT_TEST_NAME_HASH_VERSION" , 1 );
4638+
4639+ validate_name_hash_version ();
4640+ if (write_bitmap_index && name_hash_version != 1 ) {
4641+ warning (_ ("currently, --write-bitmap-index requires --name-hash-version=1" ));
4642+ name_hash_version = 1 ;
4643+ }
4644+
45924645 if (use_delta_islands )
45934646 strvec_push (& rp , "--topo-order" );
45944647
0 commit comments