@@ -39,13 +39,23 @@ static const char * const builtin_clone_usage[] = {
39
39
40
40
static int option_no_checkout , option_bare , option_mirror ;
41
41
static int option_local , option_no_hardlinks , option_shared , option_recursive ;
42
- static char * option_template , * option_reference , * option_depth ;
42
+ static char * option_template , * option_depth ;
43
43
static char * option_origin = NULL ;
44
44
static char * option_branch = NULL ;
45
45
static const char * real_git_dir ;
46
46
static char * option_upload_pack = "git-upload-pack" ;
47
47
static int option_verbosity ;
48
48
static int option_progress ;
49
+ static struct string_list option_reference ;
50
+
51
+ static int opt_parse_reference (const struct option * opt , const char * arg , int unset )
52
+ {
53
+ struct string_list * option_reference = opt -> value ;
54
+ if (!arg )
55
+ return -1 ;
56
+ string_list_append (option_reference , arg );
57
+ return 0 ;
58
+ }
49
59
50
60
static struct option builtin_clone_options [] = {
51
61
OPT__VERBOSITY (& option_verbosity ),
@@ -71,8 +81,8 @@ static struct option builtin_clone_options[] = {
71
81
"initialize submodules in the clone" ),
72
82
OPT_STRING (0 , "template" , & option_template , "template-directory" ,
73
83
"directory from which templates will be used" ),
74
- OPT_STRING ( 0 , "reference" , & option_reference , "repo" ,
75
- "reference repository" ),
84
+ OPT_CALLBACK ( 0 , "reference" , & option_reference , "repo" ,
85
+ "reference repository" , & opt_parse_reference ),
76
86
OPT_STRING ('o' , "origin" , & option_origin , "branch" ,
77
87
"use <branch> instead of 'origin' to track upstream" ),
78
88
OPT_STRING ('b' , "branch" , & option_branch , "branch" ,
@@ -197,7 +207,7 @@ static void strip_trailing_slashes(char *dir)
197
207
* end = '\0' ;
198
208
}
199
209
200
- static void setup_reference ( const char * repo )
210
+ static int add_one_reference ( struct string_list_item * item , void * cb_data )
201
211
{
202
212
const char * ref_git ;
203
213
char * ref_git_copy ;
@@ -206,13 +216,13 @@ static void setup_reference(const char *repo)
206
216
struct transport * transport ;
207
217
const struct ref * extra ;
208
218
209
- ref_git = real_path (option_reference );
219
+ ref_git = real_path (item -> string );
210
220
211
221
if (is_directory (mkpath ("%s/.git/objects" , ref_git )))
212
222
ref_git = mkpath ("%s/.git" , ref_git );
213
223
else if (!is_directory (mkpath ("%s/objects" , ref_git )))
214
224
die (_ ("reference repository '%s' is not a local directory." ),
215
- option_reference );
225
+ item -> string );
216
226
217
227
ref_git_copy = xstrdup (ref_git );
218
228
@@ -227,6 +237,12 @@ static void setup_reference(const char *repo)
227
237
transport_disconnect (transport );
228
238
229
239
free (ref_git_copy );
240
+ return 0 ;
241
+ }
242
+
243
+ static void setup_reference (void )
244
+ {
245
+ for_each_string_list (& option_reference , add_one_reference , NULL );
230
246
}
231
247
232
248
static void copy_or_link_directory (struct strbuf * src , struct strbuf * dest )
@@ -521,8 +537,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
521
537
git_config_set (key .buf , repo );
522
538
strbuf_reset (& key );
523
539
524
- if (option_reference )
525
- setup_reference (git_dir );
540
+ if (option_reference . nr )
541
+ setup_reference ();
526
542
527
543
fetch_pattern = value .buf ;
528
544
refspec = parse_fetch_refspec (1 , & fetch_pattern );
0 commit comments