@@ -97,6 +97,21 @@ def find_rev_by_timestamp(timestamp, repo_name, refspec):
97
97
98
98
def get_branch_for_repo (config , repo_name , scheme_name , scheme_map ,
99
99
cross_repos_pr ):
100
+ """Infer, fetch, and return a branch corresponding to a given PR, otherwise
101
+ return a branch found in the config for this repository name.
102
+
103
+ Args:
104
+ config (Dict[str, Any]): deserialized `update-checkout-config.json`
105
+ repo_name (str): name of the repository for checking out the branch
106
+ scheme_name (str): name of the scheme to look up in the config
107
+ scheme_map (Dict[str, str]): map of repo names to branches to check out
108
+ cross_repos_pr (Dict[str, str]): map of repo ids to PRs to check out
109
+
110
+ Returns:
111
+ Tuple[str, bool]: a pair of a checked out branch and a boolean
112
+ indicating whether this repo matched any `cross_repos_pr`.
113
+ """
114
+
100
115
cross_repo = False
101
116
repo_branch = scheme_name
102
117
if scheme_map :
@@ -249,17 +264,30 @@ def get_timestamp_to_match(args):
249
264
echo = False ).strip ()
250
265
251
266
252
- def update_all_repositories (args , config , scheme_name , cross_repos_pr ):
253
- scheme_map = None
267
+ def get_scheme_map (config , scheme_name ):
268
+ """Find a mapping from repository IDs to branches in the config.
269
+
270
+ Args:
271
+ config (Dict[str, Any]): deserialized `update-checkout-config.json`
272
+ scheme_name (str): name of the scheme to look up in `config`
273
+
274
+ Returns:
275
+ Dict[str, str]: a mapping from repos to branches for the given scheme.
276
+ """
277
+
254
278
if scheme_name :
255
279
# This loop is only correct, since we know that each alias set has
256
280
# unique contents. This is checked by validate_config. Thus the first
257
281
# branch scheme data that has scheme_name as one of its aliases is
258
282
# the only possible correct answer.
259
283
for v in config ['branch-schemes' ].values ():
260
284
if scheme_name in v ['aliases' ]:
261
- scheme_map = v ['repos' ]
262
- break
285
+ return v ['repos' ]
286
+
287
+ return None
288
+
289
+
290
+ def update_all_repositories (args , config , scheme_name , scheme_map , cross_repos_pr ):
263
291
pool_args = []
264
292
timestamp = get_timestamp_to_match (args )
265
293
for repo_name in config ['repos' ].keys ():
@@ -598,22 +626,14 @@ def main():
598
626
clone_with_ssh = args .clone_with_ssh
599
627
skip_history = args .skip_history
600
628
skip_tags = args .skip_tags
601
- scheme = args .scheme
629
+ scheme_name = args .scheme
602
630
github_comment = args .github_comment
603
631
all_repos = args .all_repositories
604
632
605
633
with open (args .config ) as f :
606
634
config = json .load (f )
607
635
validate_config (config )
608
636
609
- if args .dump_hashes :
610
- dump_repo_hashes (args , config )
611
- return (None , None )
612
-
613
- if args .dump_hashes_config :
614
- dump_repo_hashes (args , config , args .dump_hashes_config )
615
- return (None , None )
616
-
617
637
cross_repos_pr = {}
618
638
if github_comment :
619
639
regex_pr = r'(apple/[-a-zA-Z0-9_]+/pull/\d+|apple/[-a-zA-Z0-9_]+#\d+)'
@@ -622,18 +642,46 @@ def main():
622
642
repos_with_pr = [pr .replace ('/pull/' , '#' ) for pr in repos_with_pr ]
623
643
cross_repos_pr = dict (pr .split ('#' ) for pr in repos_with_pr )
624
644
645
+ # If branch is None, default to using the default branch alias
646
+ # specified by our configuration file.
647
+ if scheme_name is None :
648
+ scheme_name = config ['default-branch-scheme' ]
649
+
650
+ scheme_map = get_scheme_map (config , scheme_name )
651
+
652
+ swift_repo_path = os .path .join (args .source_root , 'swift' )
653
+ if os .path .exists (swift_repo_path ):
654
+ with shell .pushd (swift_repo_path , dry_run = False , echo = True ):
655
+ # Check if `swift` repo itself needs to switch to a cross-repo branch.
656
+ branch_name , cross_repo = get_branch_for_repo (config , 'swift' ,
657
+ scheme_name ,
658
+ scheme_map ,
659
+ cross_repos_pr )
660
+
661
+ if cross_repo :
662
+ shell .run (['git' , 'checkout' , branch_name ], echo = True ,
663
+ prefix = "[swift] " )
664
+
665
+ # Re-read the config after checkout.
666
+ with open (args .config ) as f :
667
+ config = json .load (f )
668
+ validate_config (config )
669
+
670
+ if args .dump_hashes :
671
+ dump_repo_hashes (args , config )
672
+ return (None , None )
673
+
674
+ if args .dump_hashes_config :
675
+ dump_repo_hashes (args , config , args .dump_hashes_config )
676
+ return (None , None )
677
+
625
678
clone_results = None
626
679
if clone or clone_with_ssh :
627
- # If branch is None, default to using the default branch alias
628
- # specified by our configuration file.
629
- if scheme is None :
630
- scheme = config ['default-branch-scheme' ]
631
-
632
680
skip_repo_list = skip_list_for_platform (config , all_repos )
633
681
skip_repo_list .extend (args .skip_repository_list )
634
682
clone_results = obtain_all_additional_swift_sources (args , config ,
635
683
clone_with_ssh ,
636
- scheme ,
684
+ scheme_name ,
637
685
skip_history ,
638
686
skip_tags ,
639
687
skip_repo_list )
@@ -646,8 +694,8 @@ def main():
646
694
print ("You don't have all swift sources. "
647
695
"Call this script with --clone to get them." )
648
696
649
- update_results = update_all_repositories (args , config , scheme ,
650
- cross_repos_pr )
697
+ update_results = update_all_repositories (args , config , scheme_name ,
698
+ scheme_map , cross_repos_pr )
651
699
fail_count = 0
652
700
fail_count += check_parallel_results (clone_results , "CLONE" )
653
701
fail_count += check_parallel_results (update_results , "UPDATE" )
0 commit comments