@@ -1278,25 +1278,26 @@ static void receive_shallow_info(struct fetch_pack_args *args,
12781278 args -> deepen = 1 ;
12791279}
12801280
1281- static void receive_wanted_refs (struct packet_reader * reader , struct ref * refs )
1281+ static void receive_wanted_refs (struct packet_reader * reader ,
1282+ struct ref * * sought , int nr_sought )
12821283{
12831284 process_section_header (reader , "wanted-refs" , 0 );
12841285 while (packet_reader_read (reader ) == PACKET_READ_NORMAL ) {
12851286 struct object_id oid ;
12861287 const char * end ;
1287- struct ref * r = NULL ;
1288+ int i ;
12881289
12891290 if (parse_oid_hex (reader -> line , & oid , & end ) || * end ++ != ' ' )
12901291 die (_ ("expected wanted-ref, got '%s'" ), reader -> line );
12911292
1292- for (r = refs ; r ; r = r -> next ) {
1293- if (!strcmp (end , r -> name )) {
1294- oidcpy (& r -> old_oid , & oid );
1293+ for (i = 0 ; i < nr_sought ; i ++ ) {
1294+ if (!strcmp (end , sought [ i ] -> name )) {
1295+ oidcpy (& sought [ i ] -> old_oid , & oid );
12951296 break ;
12961297 }
12971298 }
12981299
1299- if (! r )
1300+ if (i == nr_sought )
13001301 die (_ ("unexpected wanted-ref: '%s'" ), reader -> line );
13011302 }
13021303
@@ -1381,7 +1382,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
13811382 receive_shallow_info (args , & reader );
13821383
13831384 if (process_section_header (& reader , "wanted-refs" , 1 ))
1384- receive_wanted_refs (& reader , ref );
1385+ receive_wanted_refs (& reader , sought , nr_sought );
13851386
13861387 /* get the pack */
13871388 process_section_header (& reader , "packfile" , 0 );
@@ -1448,13 +1449,12 @@ static int remove_duplicates_in_refs(struct ref **ref, int nr)
14481449}
14491450
14501451static void update_shallow (struct fetch_pack_args * args ,
1451- struct ref * refs ,
1452+ struct ref * * sought , int nr_sought ,
14521453 struct shallow_info * si )
14531454{
14541455 struct oid_array ref = OID_ARRAY_INIT ;
14551456 int * status ;
14561457 int i ;
1457- struct ref * r ;
14581458
14591459 if (args -> deepen && alternate_shallow_file ) {
14601460 if (* alternate_shallow_file == '\0' ) { /* --unshallow */
@@ -1496,8 +1496,8 @@ static void update_shallow(struct fetch_pack_args *args,
14961496 remove_nonexistent_theirs_shallow (si );
14971497 if (!si -> nr_ours && !si -> nr_theirs )
14981498 return ;
1499- for (r = refs ; r ; r = r -> next )
1500- oid_array_append (& ref , & r -> old_oid );
1499+ for (i = 0 ; i < nr_sought ; i ++ )
1500+ oid_array_append (& ref , & sought [ i ] -> old_oid );
15011501 si -> ref = & ref ;
15021502
15031503 if (args -> update_shallow ) {
@@ -1531,12 +1531,12 @@ static void update_shallow(struct fetch_pack_args *args,
15311531 * remote is also shallow, check what ref is safe to update
15321532 * without updating .git/shallow
15331533 */
1534- status = xcalloc (ref . nr , sizeof (* status ));
1534+ status = xcalloc (nr_sought , sizeof (* status ));
15351535 assign_shallow_commits_to_refs (si , NULL , status );
15361536 if (si -> nr_ours || si -> nr_theirs ) {
1537- for (r = refs , i = 0 ; r ; r = r -> next , i ++ )
1537+ for (i = 0 ; i < nr_sought ; i ++ )
15381538 if (status [i ])
1539- r -> status = REF_STATUS_REJECT_SHALLOW ;
1539+ sought [ i ] -> status = REF_STATUS_REJECT_SHALLOW ;
15401540 }
15411541 free (status );
15421542 oid_array_clear (& ref );
@@ -1599,7 +1599,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
15991599 args -> connectivity_checked = 1 ;
16001600 }
16011601
1602- update_shallow (args , ref_cpy , & si );
1602+ update_shallow (args , sought , nr_sought , & si );
16031603cleanup :
16041604 clear_shallow_info (& si );
16051605 return ref_cpy ;
0 commit comments