summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--subcmds/sync.py101
1 files changed, 59 insertions, 42 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index d3c326ac..381e9e77 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -439,6 +439,63 @@ later is required to fix a server side protocol bug.
439 439
440 return (ret, fetched) 440 return (ret, fetched)
441 441
442 def _FetchMain(self, opt, args, all_projects, err_event, manifest_name,
443 load_local_manifests):
444 """The main network fetch loop.
445
446 Args:
447 opt: Program options returned from optparse. See _Options().
448 args: Command line args used to filter out projects.
449 all_projects: List of all projects that should be checked out.
450 err_event: Whether an error was hit while processing.
451 manifest_name: Manifest file to be reloaded.
452 load_local_manifests: Whether to load local manifests.
453 """
454 rp = self.manifest.repoProject
455
456 to_fetch = []
457 now = time.time()
458 if _ONE_DAY_S <= (now - rp.LastFetch):
459 to_fetch.append(rp)
460 to_fetch.extend(all_projects)
461 to_fetch.sort(key=self._fetch_times.Get, reverse=True)
462
463 success, fetched = self._Fetch(to_fetch, opt, err_event)
464 if not success:
465 err_event.set()
466
467 _PostRepoFetch(rp, opt.repo_verify)
468 if opt.network_only:
469 # bail out now; the rest touches the working tree
470 if err_event.is_set():
471 print('\nerror: Exited sync due to fetch errors.\n', file=sys.stderr)
472 sys.exit(1)
473 return
474
475 # Iteratively fetch missing and/or nested unregistered submodules
476 previously_missing_set = set()
477 while True:
478 self._ReloadManifest(manifest_name, load_local_manifests)
479 all_projects = self.GetProjects(args,
480 missing_ok=True,
481 submodules_ok=opt.fetch_submodules)
482 missing = []
483 for project in all_projects:
484 if project.gitdir not in fetched:
485 missing.append(project)
486 if not missing:
487 break
488 # Stop us from non-stopped fetching actually-missing repos: If set of
489 # missing repos has not been changed from last fetch, we break.
490 missing_set = set(p.name for p in missing)
491 if previously_missing_set == missing_set:
492 break
493 previously_missing_set = missing_set
494 success, new_fetched = self._Fetch(missing, opt, err_event)
495 if not success:
496 err_event.set()
497 fetched.update(new_fetched)
498
442 def _CheckoutOne(self, detach_head, force_sync, project): 499 def _CheckoutOne(self, detach_head, force_sync, project):
443 """Checkout work tree for one project 500 """Checkout work tree for one project
444 501
@@ -921,48 +978,8 @@ later is required to fix a server side protocol bug.
921 978
922 self._fetch_times = _FetchTimes(self.manifest) 979 self._fetch_times = _FetchTimes(self.manifest)
923 if not opt.local_only: 980 if not opt.local_only:
924 to_fetch = [] 981 self._FetchMain(opt, args, all_projects, err_event, manifest_name,
925 now = time.time() 982 load_local_manifests)
926 if _ONE_DAY_S <= (now - rp.LastFetch):
927 to_fetch.append(rp)
928 to_fetch.extend(all_projects)
929 to_fetch.sort(key=self._fetch_times.Get, reverse=True)
930
931 success, fetched = self._Fetch(to_fetch, opt, err_event)
932 if not success:
933 err_event.set()
934
935 _PostRepoFetch(rp, opt.repo_verify)
936 if opt.network_only:
937 # bail out now; the rest touches the working tree
938 if err_event.is_set():
939 print('\nerror: Exited sync due to fetch errors.\n', file=sys.stderr)
940 sys.exit(1)
941 return
942
943 # Iteratively fetch missing and/or nested unregistered submodules
944 previously_missing_set = set()
945 while True:
946 self._ReloadManifest(manifest_name, load_local_manifests)
947 all_projects = self.GetProjects(args,
948 missing_ok=True,
949 submodules_ok=opt.fetch_submodules)
950 missing = []
951 for project in all_projects:
952 if project.gitdir not in fetched:
953 missing.append(project)
954 if not missing:
955 break
956 # Stop us from non-stopped fetching actually-missing repos: If set of
957 # missing repos has not been changed from last fetch, we break.
958 missing_set = set(p.name for p in missing)
959 if previously_missing_set == missing_set:
960 break
961 previously_missing_set = missing_set
962 success, new_fetched = self._Fetch(missing, opt, err_event)
963 if not success:
964 err_event.set()
965 fetched.update(new_fetched)
966 983
967 # If we saw an error, exit with code 1 so that other scripts can check. 984 # If we saw an error, exit with code 1 so that other scripts can check.
968 if err_event.is_set(): 985 if err_event.is_set():