@@ -88,29 +88,38 @@ static void setup_enlistment_directory(int argc, const char **argv,
8888
8989static int git_retries = 3 ;
9090
91+ static int run_git_argv (const struct strvec * argv )
92+ {
93+ int res = 0 , attempts ;
94+
95+ for (attempts = 0 , res = 1 ;
96+ res && attempts < git_retries ;
97+ attempts ++ ) {
98+ struct child_process cmd = CHILD_PROCESS_INIT ;
99+
100+ cmd .git_cmd = 1 ;
101+ strvec_pushv (& cmd .args , argv -> v );
102+ res = run_command (& cmd );
103+ }
104+
105+ return res ;
106+ }
107+
91108LAST_ARG_MUST_BE_NULL
92109static int run_git (const char * arg , ...)
93110{
94111 va_list args ;
95112 const char * p ;
96113 struct strvec argv = STRVEC_INIT ;
97- int res = 0 , attempts ;
114+ int res ;
98115
99116 va_start (args , arg );
100117 strvec_push (& argv , arg );
101118 while ((p = va_arg (args , const char * )))
102119 strvec_push (& argv , p );
103120 va_end (args );
104121
105- for (attempts = 0 , res = 1 ;
106- res && attempts < git_retries ;
107- attempts ++ ) {
108- struct child_process cmd = CHILD_PROCESS_INIT ;
109-
110- cmd .git_cmd = 1 ;
111- strvec_pushv (& cmd .args , argv .v );
112- res = run_command (& cmd );
113- }
122+ res = run_git_argv (& argv );
114123
115124 strvec_clear (& argv );
116125 return res ;
@@ -764,6 +773,7 @@ static int cmd_clone(int argc, const char **argv)
764773 const char * cache_server_url = NULL , * local_cache_root = NULL ;
765774 char * default_cache_server_url = NULL , * local_cache_root_abs = NULL ;
766775 int gvfs_protocol = -1 ;
776+ const char * ref_format = NULL ;
767777
768778 struct option clone_options [] = {
769779 OPT_STRING ('b' , "branch" , & branch , N_ ("<branch>" ),
@@ -787,18 +797,22 @@ static int cmd_clone(int argc, const char **argv)
787797 OPT_STRING (0 , "local-cache-path" , & local_cache_root ,
788798 N_ ("<path>" ),
789799 N_ ("override the path for the local Scalar cache" )),
800+ OPT_STRING (0 , "ref-format" , & ref_format , N_ ("format" ),
801+ N_ ("specify the reference format to use" )),
790802 OPT_HIDDEN_BOOL (0 , "no-fetch-commits-and-trees" ,
791803 & dummy , N_ ("no longer used" )),
792804 OPT_END (),
793805 };
794806 const char * const clone_usage [] = {
795807 N_ ("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
796- "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]" ),
808+ "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] [--ref-format <format>]\n"
809+ "\t<url> [<enlistment>]" ),
797810 NULL
798811 };
799812 const char * url ;
800813 char * enlistment = NULL , * dir = NULL ;
801814 struct strbuf buf = STRBUF_INIT ;
815+ struct strvec init_argv = STRVEC_INIT ;
802816 int res ;
803817
804818 argc = parse_options (argc , argv , NULL , clone_options , clone_usage , 0 );
@@ -846,16 +860,26 @@ static int cmd_clone(int argc, const char **argv)
846860 if (!local_cache_root )
847861 die (_ ("could not determine local cache root" ));
848862
849- strbuf_reset (& buf );
863+ strvec_clear (& init_argv );
864+ strvec_pushf (& init_argv , "-c" );
850865 if (branch )
851- strbuf_addf ( & buf , "init.defaultBranch=%s" , branch );
866+ strvec_pushf ( & init_argv , "init.defaultBranch=%s" , branch );
852867 else {
853868 char * b = repo_default_branch_name (the_repository , 1 );
854- strbuf_addf ( & buf , "init.defaultBranch=%s" , b );
869+ strvec_pushf ( & init_argv , "init.defaultBranch=%s" , b );
855870 free (b );
856871 }
857872
858- if ((res = run_git ("-c" , buf .buf , "init" , "--" , dir , NULL )))
873+ strvec_push (& init_argv , "init" );
874+
875+ if (ref_format ) {
876+ strvec_push (& init_argv , "--ref-format" );
877+ strvec_push (& init_argv , ref_format );
878+ }
879+
880+ strvec_push (& init_argv , "--" );
881+ strvec_push (& init_argv , dir );
882+ if ((res = run_git_argv (& init_argv )))
859883 goto cleanup ;
860884
861885 if (chdir (dir ) < 0 ) {
@@ -1005,6 +1029,7 @@ static int cmd_clone(int argc, const char **argv)
10051029 free (enlistment );
10061030 free (dir );
10071031 strbuf_release (& buf );
1032+ strvec_clear (& init_argv );
10081033 free (default_cache_server_url );
10091034 free (local_cache_root_abs );
10101035 return res ;
0 commit comments