1313#include "sigchain.h"
1414#include "transport.h"
1515#include "submodule.h"
16+ #include "connected.h"
1617
1718static const char * const builtin_fetch_usage [] = {
1819 "git fetch [<options>] [<repository> [<refspec>...]]" ,
@@ -345,62 +346,16 @@ static int update_local_ref(struct ref *ref,
345346 }
346347}
347348
348- /*
349- * The ref_map records the tips of the refs we are fetching. If
350- *
351- * $ git rev-list --verify-objects --stdin --not --all
352- *
353- * (feeding all the refs in ref_map on its standard input) does not
354- * error out, that means everything reachable from these updated refs
355- * locally exists and is connected to some of our existing refs.
356- *
357- * Returns 0 if everything is connected, non-zero otherwise.
358- */
359- static int check_everything_connected (struct ref * ref_map , int quiet )
349+ static int iterate_ref_map (void * cb_data , unsigned char sha1 [20 ])
360350{
361- struct child_process rev_list ;
362- const char * argv [] = {"rev-list" , "--verify-objects" ,
363- "--stdin" , "--not" , "--all" , NULL , NULL };
364- char commit [41 ];
365- struct ref * ref ;
366- int err = 0 ;
367-
368- if (!ref_map )
369- return 0 ;
370-
371- if (quiet )
372- argv [5 ] = "--quiet" ;
373-
374- memset (& rev_list , 0 , sizeof (rev_list ));
375- rev_list .argv = argv ;
376- rev_list .git_cmd = 1 ;
377- rev_list .in = -1 ;
378- rev_list .no_stdout = 1 ;
379- rev_list .no_stderr = quiet ;
380- if (start_command (& rev_list ))
381- return error (_ ("Could not run 'git rev-list'" ));
382-
383- sigchain_push (SIGPIPE , SIG_IGN );
384-
385- memcpy (commit + 40 , "\n" , 2 );
386- for (ref = ref_map ; ref ; ref = ref -> next ) {
387- memcpy (commit , sha1_to_hex (ref -> old_sha1 ), 40 );
388- if (write_in_full (rev_list .in , commit , 41 ) < 0 ) {
389- if (errno != EPIPE && errno != EINVAL )
390- error (_ ("failed write to rev-list: %s" ),
391- strerror (errno ));
392- err = -1 ;
393- break ;
394- }
395- }
396- if (close (rev_list .in )) {
397- error (_ ("failed to close rev-list's stdin: %s" ), strerror (errno ));
398- err = -1 ;
399- }
400-
401- sigchain_pop (SIGPIPE );
351+ struct ref * * rm = cb_data ;
352+ struct ref * ref = * rm ;
402353
403- return finish_command (& rev_list ) || err ;
354+ if (!ref )
355+ return -1 ; /* end of the list */
356+ * rm = ref -> next ;
357+ hashcpy (sha1 , ref -> old_sha1 );
358+ return 0 ;
404359}
405360
406361static int store_updated_refs (const char * raw_url , const char * remote_name ,
@@ -423,7 +378,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
423378 else
424379 url = xstrdup ("foreign" );
425380
426- if (check_everything_connected (ref_map , 0 ))
381+ rm = ref_map ;
382+ if (check_everything_connected (iterate_ref_map , 0 , & rm ))
427383 return error (_ ("%s did not send all necessary objects\n" ), url );
428384
429385 for (rm = ref_map ; rm ; rm = rm -> next ) {
@@ -522,6 +478,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
522478 */
523479static int quickfetch (struct ref * ref_map )
524480{
481+ struct ref * rm = ref_map ;
482+
525483 /*
526484 * If we are deepening a shallow clone we already have these
527485 * objects reachable. Running rev-list here will return with
@@ -531,7 +489,7 @@ static int quickfetch(struct ref *ref_map)
531489 */
532490 if (depth )
533491 return -1 ;
534- return check_everything_connected (ref_map , 1 );
492+ return check_everything_connected (iterate_ref_map , 1 , & rm );
535493}
536494
537495static int fetch_refs (struct transport * transport , struct ref * ref_map )
0 commit comments