@@ -89,29 +89,38 @@ static void setup_enlistment_directory(int argc, const char **argv,
8989
9090static int git_retries = 3 ;
9191
92+ static int run_git_argv (const struct strvec * argv )
93+ {
94+ int res = 0 , attempts ;
95+
96+ for (attempts = 0 , res = 1 ;
97+ res && attempts < git_retries ;
98+ attempts ++ ) {
99+ struct child_process cmd = CHILD_PROCESS_INIT ;
100+
101+ cmd .git_cmd = 1 ;
102+ strvec_pushv (& cmd .args , argv -> v );
103+ res = run_command (& cmd );
104+ }
105+
106+ return res ;
107+ }
108+
92109LAST_ARG_MUST_BE_NULL
93110static int run_git (const char * arg , ...)
94111{
95112 va_list args ;
96113 const char * p ;
97114 struct strvec argv = STRVEC_INIT ;
98- int res = 0 , attempts ;
115+ int res ;
99116
100117 va_start (args , arg );
101118 strvec_push (& argv , arg );
102119 while ((p = va_arg (args , const char * )))
103120 strvec_push (& argv , p );
104121 va_end (args );
105122
106- for (attempts = 0 , res = 1 ;
107- res && attempts < git_retries ;
108- attempts ++ ) {
109- struct child_process cmd = CHILD_PROCESS_INIT ;
110-
111- cmd .git_cmd = 1 ;
112- strvec_pushv (& cmd .args , argv .v );
113- res = run_command (& cmd );
114- }
123+ res = run_git_argv (& argv );
115124
116125 strvec_clear (& argv );
117126 return res ;
@@ -775,6 +784,7 @@ static int cmd_clone(int argc, const char **argv)
775784 const char * cache_server_url = NULL , * local_cache_root = NULL ;
776785 char * default_cache_server_url = NULL , * local_cache_root_abs = NULL ;
777786 int gvfs_protocol = -1 ;
787+ const char * ref_format = NULL ;
778788
779789 struct option clone_options [] = {
780790 OPT_STRING ('b' , "branch" , & branch , N_ ("<branch>" ),
@@ -798,18 +808,22 @@ static int cmd_clone(int argc, const char **argv)
798808 OPT_STRING (0 , "local-cache-path" , & local_cache_root ,
799809 N_ ("<path>" ),
800810 N_ ("override the path for the local Scalar cache" )),
811+ OPT_STRING (0 , "ref-format" , & ref_format , N_ ("format" ),
812+ N_ ("specify the reference format to use" )),
801813 OPT_HIDDEN_BOOL (0 , "no-fetch-commits-and-trees" ,
802814 & dummy , N_ ("no longer used" )),
803815 OPT_END (),
804816 };
805817 const char * const clone_usage [] = {
806818 N_ ("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
807- "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]" ),
819+ "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] [--ref-format <format>]\n"
820+ "\t<url> [<enlistment>]" ),
808821 NULL
809822 };
810823 const char * url ;
811824 char * enlistment = NULL , * dir = NULL ;
812825 struct strbuf buf = STRBUF_INIT ;
826+ struct strvec init_argv = STRVEC_INIT ;
813827 int res ;
814828
815829 argc = parse_options (argc , argv , NULL , clone_options , clone_usage , 0 );
@@ -857,16 +871,26 @@ static int cmd_clone(int argc, const char **argv)
857871 if (!local_cache_root )
858872 die (_ ("could not determine local cache root" ));
859873
860- strbuf_reset (& buf );
874+ strvec_clear (& init_argv );
875+ strvec_pushf (& init_argv , "-c" );
861876 if (branch )
862- strbuf_addf ( & buf , "init.defaultBranch=%s" , branch );
877+ strvec_pushf ( & init_argv , "init.defaultBranch=%s" , branch );
863878 else {
864879 char * b = repo_default_branch_name (the_repository , 1 );
865- strbuf_addf ( & buf , "init.defaultBranch=%s" , b );
880+ strvec_pushf ( & init_argv , "init.defaultBranch=%s" , b );
866881 free (b );
867882 }
868883
869- if ((res = run_git ("-c" , buf .buf , "init" , "--" , dir , NULL )))
884+ strvec_push (& init_argv , "init" );
885+
886+ if (ref_format ) {
887+ strvec_push (& init_argv , "--ref-format" );
888+ strvec_push (& init_argv , ref_format );
889+ }
890+
891+ strvec_push (& init_argv , "--" );
892+ strvec_push (& init_argv , dir );
893+ if ((res = run_git_argv (& init_argv )))
870894 goto cleanup ;
871895
872896 if (chdir (dir ) < 0 ) {
@@ -1016,6 +1040,7 @@ static int cmd_clone(int argc, const char **argv)
10161040 free (enlistment );
10171041 free (dir );
10181042 strbuf_release (& buf );
1043+ strvec_clear (& init_argv );
10191044 free (default_cache_server_url );
10201045 free (local_cache_root_abs );
10211046 return res ;
0 commit comments