@@ -44,7 +44,7 @@ static int config_path_cmp(const void *unused_cmp_data,
4444 const struct submodule_entry * b = entry_or_key ;
4545
4646 return strcmp (a -> config -> path , b -> config -> path ) ||
47- hashcmp ( a -> config -> gitmodules_sha1 , b -> config -> gitmodules_sha1 );
47+ oidcmp ( & a -> config -> gitmodules_oid , & b -> config -> gitmodules_oid );
4848}
4949
5050static int config_name_cmp (const void * unused_cmp_data ,
@@ -56,7 +56,7 @@ static int config_name_cmp(const void *unused_cmp_data,
5656 const struct submodule_entry * b = entry_or_key ;
5757
5858 return strcmp (a -> config -> name , b -> config -> name ) ||
59- hashcmp ( a -> config -> gitmodules_sha1 , b -> config -> gitmodules_sha1 );
59+ oidcmp ( & a -> config -> gitmodules_oid , & b -> config -> gitmodules_oid );
6060}
6161
6262static struct submodule_cache * submodule_cache_alloc (void )
@@ -109,17 +109,17 @@ void submodule_cache_free(struct submodule_cache *cache)
109109 free (cache );
110110}
111111
112- static unsigned int hash_sha1_string (const unsigned char * sha1 ,
113- const char * string )
112+ static unsigned int hash_oid_string (const struct object_id * oid ,
113+ const char * string )
114114{
115- return memhash (sha1 , 20 ) + strhash (string );
115+ return memhash (oid -> hash , the_hash_algo -> rawsz ) + strhash (string );
116116}
117117
118118static void cache_put_path (struct submodule_cache * cache ,
119119 struct submodule * submodule )
120120{
121- unsigned int hash = hash_sha1_string ( submodule -> gitmodules_sha1 ,
122- submodule -> path );
121+ unsigned int hash = hash_oid_string ( & submodule -> gitmodules_oid ,
122+ submodule -> path );
123123 struct submodule_entry * e = xmalloc (sizeof (* e ));
124124 hashmap_entry_init (e , hash );
125125 e -> config = submodule ;
@@ -129,8 +129,8 @@ static void cache_put_path(struct submodule_cache *cache,
129129static void cache_remove_path (struct submodule_cache * cache ,
130130 struct submodule * submodule )
131131{
132- unsigned int hash = hash_sha1_string ( submodule -> gitmodules_sha1 ,
133- submodule -> path );
132+ unsigned int hash = hash_oid_string ( & submodule -> gitmodules_oid ,
133+ submodule -> path );
134134 struct submodule_entry e ;
135135 struct submodule_entry * removed ;
136136 hashmap_entry_init (& e , hash );
@@ -142,23 +142,23 @@ static void cache_remove_path(struct submodule_cache *cache,
142142static void cache_add (struct submodule_cache * cache ,
143143 struct submodule * submodule )
144144{
145- unsigned int hash = hash_sha1_string ( submodule -> gitmodules_sha1 ,
146- submodule -> name );
145+ unsigned int hash = hash_oid_string ( & submodule -> gitmodules_oid ,
146+ submodule -> name );
147147 struct submodule_entry * e = xmalloc (sizeof (* e ));
148148 hashmap_entry_init (e , hash );
149149 e -> config = submodule ;
150150 hashmap_add (& cache -> for_name , e );
151151}
152152
153153static const struct submodule * cache_lookup_path (struct submodule_cache * cache ,
154- const unsigned char * gitmodules_sha1 , const char * path )
154+ const struct object_id * gitmodules_oid , const char * path )
155155{
156156 struct submodule_entry * entry ;
157- unsigned int hash = hash_sha1_string ( gitmodules_sha1 , path );
157+ unsigned int hash = hash_oid_string ( gitmodules_oid , path );
158158 struct submodule_entry key ;
159159 struct submodule key_config ;
160160
161- hashcpy ( key_config .gitmodules_sha1 , gitmodules_sha1 );
161+ oidcpy ( & key_config .gitmodules_oid , gitmodules_oid );
162162 key_config .path = path ;
163163
164164 hashmap_entry_init (& key , hash );
@@ -171,14 +171,14 @@ static const struct submodule *cache_lookup_path(struct submodule_cache *cache,
171171}
172172
173173static struct submodule * cache_lookup_name (struct submodule_cache * cache ,
174- const unsigned char * gitmodules_sha1 , const char * name )
174+ const struct object_id * gitmodules_oid , const char * name )
175175{
176176 struct submodule_entry * entry ;
177- unsigned int hash = hash_sha1_string ( gitmodules_sha1 , name );
177+ unsigned int hash = hash_oid_string ( gitmodules_oid , name );
178178 struct submodule_entry key ;
179179 struct submodule key_config ;
180180
181- hashcpy ( key_config .gitmodules_sha1 , gitmodules_sha1 );
181+ oidcpy ( & key_config .gitmodules_oid , gitmodules_oid );
182182 key_config .name = name ;
183183
184184 hashmap_entry_init (& key , hash );
@@ -207,12 +207,12 @@ static int name_and_item_from_var(const char *var, struct strbuf *name,
207207}
208208
209209static struct submodule * lookup_or_create_by_name (struct submodule_cache * cache ,
210- const unsigned char * gitmodules_sha1 , const char * name )
210+ const struct object_id * gitmodules_oid , const char * name )
211211{
212212 struct submodule * submodule ;
213213 struct strbuf name_buf = STRBUF_INIT ;
214214
215- submodule = cache_lookup_name (cache , gitmodules_sha1 , name );
215+ submodule = cache_lookup_name (cache , gitmodules_oid , name );
216216 if (submodule )
217217 return submodule ;
218218
@@ -230,7 +230,7 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
230230 submodule -> branch = NULL ;
231231 submodule -> recommend_shallow = -1 ;
232232
233- hashcpy ( submodule -> gitmodules_sha1 , gitmodules_sha1 );
233+ oidcpy ( & submodule -> gitmodules_oid , gitmodules_oid );
234234
235235 cache_add (cache , submodule );
236236
@@ -341,21 +341,21 @@ int parse_push_recurse_submodules_arg(const char *opt, const char *arg)
341341 return parse_push_recurse (opt , arg , 1 );
342342}
343343
344- static void warn_multiple_config (const unsigned char * treeish_name ,
344+ static void warn_multiple_config (const struct object_id * treeish_name ,
345345 const char * name , const char * option )
346346{
347347 const char * commit_string = "WORKTREE" ;
348348 if (treeish_name )
349- commit_string = sha1_to_hex (treeish_name );
349+ commit_string = oid_to_hex (treeish_name );
350350 warning ("%s:.gitmodules, multiple configurations found for "
351351 "'submodule.%s.%s'. Skipping second one!" ,
352352 commit_string , name , option );
353353}
354354
355355struct parse_config_parameter {
356356 struct submodule_cache * cache ;
357- const unsigned char * treeish_name ;
358- const unsigned char * gitmodules_sha1 ;
357+ const struct object_id * treeish_name ;
358+ const struct object_id * gitmodules_oid ;
359359 int overwrite ;
360360};
361361
@@ -371,7 +371,7 @@ static int parse_config(const char *var, const char *value, void *data)
371371 return 0 ;
372372
373373 submodule = lookup_or_create_by_name (me -> cache ,
374- me -> gitmodules_sha1 ,
374+ me -> gitmodules_oid ,
375375 name .buf );
376376
377377 if (!strcmp (item .buf , "path" )) {
@@ -389,7 +389,7 @@ static int parse_config(const char *var, const char *value, void *data)
389389 }
390390 } else if (!strcmp (item .buf , "fetchrecursesubmodules" )) {
391391 /* when parsing worktree configurations we can die early */
392- int die_on_error = is_null_sha1 (me -> gitmodules_sha1 );
392+ int die_on_error = is_null_oid (me -> gitmodules_oid );
393393 if (!me -> overwrite &&
394394 submodule -> fetch_recurse != RECURSE_SUBMODULES_NONE )
395395 warn_multiple_config (me -> treeish_name , submodule -> name ,
@@ -511,10 +511,10 @@ static const struct submodule *config_from(struct submodule_cache *cache,
511511
512512 switch (lookup_type ) {
513513 case lookup_name :
514- submodule = cache_lookup_name (cache , oid . hash , key );
514+ submodule = cache_lookup_name (cache , & oid , key );
515515 break ;
516516 case lookup_path :
517- submodule = cache_lookup_path (cache , oid . hash , key );
517+ submodule = cache_lookup_path (cache , & oid , key );
518518 break ;
519519 }
520520 if (submodule )
@@ -526,8 +526,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
526526
527527 /* fill the submodule config into the cache */
528528 parameter .cache = cache ;
529- parameter .treeish_name = treeish_name -> hash ;
530- parameter .gitmodules_sha1 = oid . hash ;
529+ parameter .treeish_name = treeish_name ;
530+ parameter .gitmodules_oid = & oid ;
531531 parameter .overwrite = 0 ;
532532 git_config_from_mem (parse_config , CONFIG_ORIGIN_SUBMODULE_BLOB , rev .buf ,
533533 config , config_size , & parameter );
@@ -536,9 +536,9 @@ static const struct submodule *config_from(struct submodule_cache *cache,
536536
537537 switch (lookup_type ) {
538538 case lookup_name :
539- return cache_lookup_name (cache , oid . hash , key );
539+ return cache_lookup_name (cache , & oid , key );
540540 case lookup_path :
541- return cache_lookup_path (cache , oid . hash , key );
541+ return cache_lookup_path (cache , & oid , key );
542542 default :
543543 return NULL ;
544544 }
@@ -567,7 +567,7 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
567567
568568 parameter .cache = repo -> submodule_cache ;
569569 parameter .treeish_name = NULL ;
570- parameter .gitmodules_sha1 = null_sha1 ;
570+ parameter .gitmodules_oid = & null_oid ;
571571 parameter .overwrite = 1 ;
572572
573573 return parse_config (var , value , & parameter );
0 commit comments