1919#include "ll-merge.h"
2020#include "resolve-undo.h"
2121#include "submodule.h"
22+ #include "argv-array.h"
2223
2324static const char * const checkout_usage [] = {
2425 "git checkout [options] <branch>" ,
@@ -588,24 +589,12 @@ static void update_refs_for_switch(struct checkout_opts *opts,
588589 report_tracking (new );
589590}
590591
591- struct rev_list_args {
592- int argc ;
593- int alloc ;
594- const char * * argv ;
595- };
596-
597- static void add_one_rev_list_arg (struct rev_list_args * args , const char * s )
598- {
599- ALLOC_GROW (args -> argv , args -> argc + 1 , args -> alloc );
600- args -> argv [args -> argc ++ ] = s ;
601- }
602-
603592static int add_one_ref_to_rev_list_arg (const char * refname ,
604593 const unsigned char * sha1 ,
605594 int flags ,
606595 void * cb_data )
607596{
608- add_one_rev_list_arg (cb_data , refname );
597+ argv_array_push (cb_data , refname );
609598 return 0 ;
610599}
611600
@@ -684,15 +673,14 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
684673 */
685674static void orphaned_commit_warning (struct commit * commit )
686675{
687- struct rev_list_args args = { 0 , 0 , NULL } ;
676+ struct argv_array args = ARGV_ARRAY_INIT ;
688677 struct rev_info revs ;
689678
690- add_one_rev_list_arg (& args , "(internal)" );
691- add_one_rev_list_arg (& args , sha1_to_hex (commit -> object .sha1 ));
692- add_one_rev_list_arg (& args , "--not" );
679+ argv_array_push (& args , "(internal)" );
680+ argv_array_push (& args , sha1_to_hex (commit -> object .sha1 ));
681+ argv_array_push (& args , "--not" );
693682 for_each_ref (add_one_ref_to_rev_list_arg , & args );
694- add_one_rev_list_arg (& args , "--" );
695- add_one_rev_list_arg (& args , NULL );
683+ argv_array_push (& args , "--" );
696684
697685 init_revisions (& revs , NULL );
698686 if (setup_revisions (args .argc - 1 , args .argv , & revs , NULL ) != 1 )
@@ -704,6 +692,7 @@ static void orphaned_commit_warning(struct commit *commit)
704692 else
705693 describe_detached_head (_ ("Previous HEAD position was" ), commit );
706694
695+ argv_array_clear (& args );
707696 clear_commit_marks (commit , -1 );
708697 for_each_ref (clear_commit_marks_from_one_ref , NULL );
709698}
0 commit comments