@@ -368,7 +368,7 @@ def update_all_repositories(args, config, scheme_name, scheme_map, cross_repos_p
368
368
369
369
def obtain_additional_swift_sources (pool_args ):
370
370
(args , repo_name , repo_info , repo_branch , remote , with_ssh , scheme_name ,
371
- skip_history , skip_tags , skip_repository_list ) = pool_args
371
+ skip_history , skip_tags , skip_repository_list , use_submodules ) = pool_args
372
372
373
373
env = dict (os .environ )
374
374
env .update ({'GIT_TERMINAL_PROMPT' : '0' })
@@ -383,6 +383,11 @@ def obtain_additional_swift_sources(pool_args):
383
383
(['--no-tags' ] if skip_tags else []),
384
384
env = env ,
385
385
echo = True )
386
+ elif use_submodules :
387
+ shell .run (['git' , 'submodule' , 'add' , remote , repo_name ] +
388
+ (['--no-tags' ] if skip_tags else []),
389
+ env = env ,
390
+ echo = True )
386
391
else :
387
392
shell .run (['git' , 'clone' , '--recursive' , remote , repo_name ] +
388
393
(['--no-tags' ] if skip_tags else []),
@@ -406,7 +411,7 @@ def obtain_additional_swift_sources(pool_args):
406
411
407
412
def obtain_all_additional_swift_sources (args , config , with_ssh , scheme_name ,
408
413
skip_history , skip_tags ,
409
- skip_repository_list ):
414
+ skip_repository_list , use_submodules ):
410
415
411
416
pool_args = []
412
417
with shell .pushd (args .source_root , dry_run = False , echo = False ):
@@ -416,7 +421,20 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
416
421
"user" )
417
422
continue
418
423
419
- if os .path .isdir (os .path .join (repo_name , ".git" )):
424
+ if use_submodules :
425
+ repo_exists = False
426
+ submodules_status = shell .capture (['git' , 'submodule' , 'status' ],
427
+ echo = False )
428
+ if submodules_status :
429
+ for line in submodules_status .splitlines ():
430
+ if line [0 ].endswith (repo_name ):
431
+ repo_exists = True
432
+ break
433
+
434
+ else :
435
+ repo_exists = os .path .isdir (os .path .join (repo_name , ".git" ))
436
+
437
+ if repo_exists :
420
438
print ("Skipping clone of '" + repo_name + "', directory "
421
439
"already exists" )
422
440
continue
@@ -450,16 +468,25 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
450
468
if repo_not_in_scheme :
451
469
continue
452
470
453
- pool_args .append ([args , repo_name , repo_info , repo_branch , remote ,
471
+
472
+ new_args = [args , repo_name , repo_info , repo_branch , remote ,
454
473
with_ssh , scheme_name , skip_history , skip_tags ,
455
- skip_repository_list ])
474
+ skip_repository_list , use_submodules ]
456
475
457
- if not pool_args :
458
- print ("Not cloning any repositories." )
459
- return
476
+ if use_submodules :
477
+ obtain_additional_swift_sources (new_args )
478
+ else :
479
+ pool_args .append (new_args )
460
480
461
- return run_parallel (
462
- obtain_additional_swift_sources , pool_args , args .n_processes )
481
+ # Only use `run_parallel` when submodules are not used, since `.git` dir
482
+ # can't be accessed concurrently.
483
+ if not use_submodules :
484
+ if not pool_args :
485
+ print ("Not cloning any repositories." )
486
+ return
487
+
488
+ return run_parallel (
489
+ obtain_additional_swift_sources , pool_args , args .n_processes )
463
490
464
491
465
492
def dump_repo_hashes (args , config , branch_scheme_name = 'repro' ):
@@ -672,6 +699,10 @@ def main():
672
699
help = "The root directory to checkout repositories" ,
673
700
default = SWIFT_SOURCE_ROOT ,
674
701
dest = 'source_root' )
702
+ parser .add_argument (
703
+ "--use-submodules" ,
704
+ help = "Checkout repositories as git submodules." ,
705
+ action = 'store_true' )
675
706
args = parser .parse_args ()
676
707
677
708
if not args .scheme :
@@ -693,6 +724,7 @@ def main():
693
724
scheme_name = args .scheme
694
725
github_comment = args .github_comment
695
726
all_repos = args .all_repositories
727
+ use_submodules = args .use_submodules
696
728
697
729
with open (args .config ) as f :
698
730
config = json .load (f )
@@ -726,7 +758,8 @@ def main():
726
758
scheme_name ,
727
759
skip_history ,
728
760
skip_tags ,
729
- skip_repo_list )
761
+ skip_repo_list ,
762
+ use_submodules )
730
763
731
764
swift_repo_path = os .path .join (args .source_root , 'swift' )
732
765
if 'swift' not in skip_repo_list and os .path .exists (swift_repo_path ):
0 commit comments