@@ -336,12 +336,6 @@ int for_each_tag_ref(each_ref_fn fn, void *cb_data)
336336 return refs_for_each_tag_ref (get_main_ref_store (), fn , cb_data );
337337}
338338
339- int for_each_tag_ref_submodule (const char * submodule , each_ref_fn fn , void * cb_data )
340- {
341- return refs_for_each_tag_ref (get_submodule_ref_store (submodule ),
342- fn , cb_data );
343- }
344-
345339int refs_for_each_branch_ref (struct ref_store * refs , each_ref_fn fn , void * cb_data )
346340{
347341 return refs_for_each_ref_in (refs , "refs/heads/" , fn , cb_data );
@@ -352,12 +346,6 @@ int for_each_branch_ref(each_ref_fn fn, void *cb_data)
352346 return refs_for_each_branch_ref (get_main_ref_store (), fn , cb_data );
353347}
354348
355- int for_each_branch_ref_submodule (const char * submodule , each_ref_fn fn , void * cb_data )
356- {
357- return refs_for_each_branch_ref (get_submodule_ref_store (submodule ),
358- fn , cb_data );
359- }
360-
361349int refs_for_each_remote_ref (struct ref_store * refs , each_ref_fn fn , void * cb_data )
362350{
363351 return refs_for_each_ref_in (refs , "refs/remotes/" , fn , cb_data );
@@ -368,12 +356,6 @@ int for_each_remote_ref(each_ref_fn fn, void *cb_data)
368356 return refs_for_each_remote_ref (get_main_ref_store (), fn , cb_data );
369357}
370358
371- int for_each_remote_ref_submodule (const char * submodule , each_ref_fn fn , void * cb_data )
372- {
373- return refs_for_each_remote_ref (get_submodule_ref_store (submodule ),
374- fn , cb_data );
375- }
376-
377359int head_ref_namespaced (each_ref_fn fn , void * cb_data )
378360{
379361 struct strbuf buf = STRBUF_INIT ;
@@ -1266,27 +1248,21 @@ int refs_rename_ref_available(struct ref_store *refs,
12661248 return ok ;
12671249}
12681250
1269- int head_ref_submodule ( const char * submodule , each_ref_fn fn , void * cb_data )
1251+ int refs_head_ref ( struct ref_store * refs , each_ref_fn fn , void * cb_data )
12701252{
12711253 struct object_id oid ;
12721254 int flag ;
12731255
1274- if (submodule ) {
1275- if (resolve_gitlink_ref (submodule , "HEAD" , oid .hash ) == 0 )
1276- return fn ("HEAD" , & oid , 0 , cb_data );
1277-
1278- return 0 ;
1279- }
1280-
1281- if (!read_ref_full ("HEAD" , RESOLVE_REF_READING , oid .hash , & flag ))
1256+ if (!refs_read_ref_full (refs , "HEAD" , RESOLVE_REF_READING ,
1257+ oid .hash , & flag ))
12821258 return fn ("HEAD" , & oid , flag , cb_data );
12831259
12841260 return 0 ;
12851261}
12861262
12871263int head_ref (each_ref_fn fn , void * cb_data )
12881264{
1289- return head_ref_submodule ( NULL , fn , cb_data );
1265+ return refs_head_ref ( get_main_ref_store () , fn , cb_data );
12901266}
12911267
12921268struct ref_iterator * refs_ref_iterator_begin (
@@ -1344,11 +1320,6 @@ int for_each_ref(each_ref_fn fn, void *cb_data)
13441320 return refs_for_each_ref (get_main_ref_store (), fn , cb_data );
13451321}
13461322
1347- int for_each_ref_submodule (const char * submodule , each_ref_fn fn , void * cb_data )
1348- {
1349- return refs_for_each_ref (get_submodule_ref_store (submodule ), fn , cb_data );
1350- }
1351-
13521323int refs_for_each_ref_in (struct ref_store * refs , const char * prefix ,
13531324 each_ref_fn fn , void * cb_data )
13541325{
@@ -1370,23 +1341,15 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsig
13701341 prefix , fn , 0 , flag , cb_data );
13711342}
13721343
1373- int for_each_ref_in_submodule (const char * submodule , const char * prefix ,
1374- each_ref_fn fn , void * cb_data )
1375- {
1376- return refs_for_each_ref_in (get_submodule_ref_store (submodule ),
1377- prefix , fn , cb_data );
1378- }
1379-
1380- int for_each_fullref_in_submodule (const char * submodule , const char * prefix ,
1381- each_ref_fn fn , void * cb_data ,
1382- unsigned int broken )
1344+ int refs_for_each_fullref_in (struct ref_store * refs , const char * prefix ,
1345+ each_ref_fn fn , void * cb_data ,
1346+ unsigned int broken )
13831347{
13841348 unsigned int flag = 0 ;
13851349
13861350 if (broken )
13871351 flag = DO_FOR_EACH_INCLUDE_BROKEN ;
1388- return do_for_each_ref (get_submodule_ref_store (submodule ),
1389- prefix , fn , 0 , flag , cb_data );
1352+ return do_for_each_ref (refs , prefix , fn , 0 , flag , cb_data );
13901353}
13911354
13921355int for_each_replace_ref (each_ref_fn fn , void * cb_data )
@@ -1521,25 +1484,10 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
15211484int resolve_gitlink_ref (const char * submodule , const char * refname ,
15221485 unsigned char * sha1 )
15231486{
1524- size_t len = strlen (submodule );
15251487 struct ref_store * refs ;
15261488 int flags ;
15271489
1528- while (len && submodule [len - 1 ] == '/' )
1529- len -- ;
1530-
1531- if (!len )
1532- return -1 ;
1533-
1534- if (submodule [len ]) {
1535- /* We need to strip off one or more trailing slashes */
1536- char * stripped = xmemdupz (submodule , len );
1537-
1538- refs = get_submodule_ref_store (stripped );
1539- free (stripped );
1540- } else {
1541- refs = get_submodule_ref_store (submodule );
1542- }
1490+ refs = get_submodule_ref_store (submodule );
15431491
15441492 if (!refs )
15451493 return -1 ;
@@ -1654,39 +1602,43 @@ struct ref_store *get_submodule_ref_store(const char *submodule)
16541602{
16551603 struct strbuf submodule_sb = STRBUF_INIT ;
16561604 struct ref_store * refs ;
1657- int ret ;
1605+ char * to_free = NULL ;
1606+ size_t len ;
16581607
1659- if (!submodule || !* submodule ) {
1660- /*
1661- * FIXME: This case is ideally not allowed. But that
1662- * can't happen until we clean up all the callers.
1663- */
1664- return get_main_ref_store ();
1665- }
1608+ if (!submodule )
1609+ return NULL ;
1610+
1611+ len = strlen (submodule );
1612+ while (len && is_dir_sep (submodule [len - 1 ]))
1613+ len -- ;
1614+ if (!len )
1615+ return NULL ;
1616+
1617+ if (submodule [len ])
1618+ /* We need to strip off one or more trailing slashes */
1619+ submodule = to_free = xmemdupz (submodule , len );
16661620
16671621 refs = lookup_ref_store_map (& submodule_ref_stores , submodule );
16681622 if (refs )
1669- return refs ;
1623+ goto done ;
16701624
16711625 strbuf_addstr (& submodule_sb , submodule );
1672- ret = is_nonbare_repository_dir (& submodule_sb );
1673- strbuf_release (& submodule_sb );
1674- if (!ret )
1675- return NULL ;
1626+ if (!is_nonbare_repository_dir (& submodule_sb ))
1627+ goto done ;
16761628
1677- ret = submodule_to_gitdir (& submodule_sb , submodule );
1678- if (ret ) {
1679- strbuf_release (& submodule_sb );
1680- return NULL ;
1681- }
1629+ if (submodule_to_gitdir (& submodule_sb , submodule ))
1630+ goto done ;
16821631
16831632 /* assume that add_submodule_odb() has been called */
16841633 refs = ref_store_init (submodule_sb .buf ,
16851634 REF_STORE_READ | REF_STORE_ODB );
16861635 register_ref_store_map (& submodule_ref_stores , "submodule" ,
16871636 refs , submodule );
16881637
1638+ done :
16891639 strbuf_release (& submodule_sb );
1640+ free (to_free );
1641+
16901642 return refs ;
16911643}
16921644
0 commit comments