diff options
| author | Gavin Mak <gavinmak@google.com> | 2025-06-17 19:40:06 -0700 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2025-06-23 09:17:05 -0700 |
| commit | df3c4017f9a81e268b23728c273e1c8cd8957434 (patch) | |
| tree | b723bb3e3bfa3ca4b04acacc3bd588ab908728e7 /subcmds/sync.py | |
| parent | f7a3f99dc9e92556f3a0c588633b651439b5f7db (diff) | |
| download | git-repo-df3c4017f9a81e268b23728c273e1c8cd8957434.tar.gz git-repo-df3c4017f9a81e268b23728c273e1c8cd8957434.zip | |
sync: Share manifest list update logic between sync modes
Extract the manifest update loop from _SyncPhased into a new
_UpdateManifestLists method and use it in both sync types.
Bug: 421935613
Change-Id: If499a3ce4a0bbb3c4641dba52ca5c1c82b11f16f
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/484341
Reviewed-by: Scott Lee <ddoman@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'subcmds/sync.py')
| -rw-r--r-- | subcmds/sync.py | 85 |
1 files changed, 55 insertions, 30 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index b848d1374..3d4ab75c6 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -26,7 +26,7 @@ from pathlib import Path import sys import tempfile import time -from typing import List, NamedTuple, Optional, Set, Union +from typing import List, NamedTuple, Optional, Set, Tuple, Union import urllib.error import urllib.parse import urllib.request @@ -2006,6 +2006,54 @@ later is required to fix a server side protocol bug. return _threading.Thread(target=_monitor_loop, daemon=True) + def _UpdateManifestLists( + self, + opt: optparse.Values, + err_event: multiprocessing.Event, + errors: List[Exception], + ) -> Tuple[bool, bool]: + """Updates project lists and copy/link files for all manifests. + + Args: + opt: Program options from optparse. + err_event: An event to set if any error occurs. + errors: A list to append any encountered exceptions to. + + Returns: + A tuple (err_update_projects, err_update_linkfiles) indicating + an error for each task. + """ + err_update_projects = False + err_update_linkfiles = False + for m in self.ManifestList(opt): + if m.IsMirror or m.IsArchive: + continue + + try: + self.UpdateProjectList(opt, m) + except Exception as e: + err_event.set() + err_update_projects = True + errors.append(e) + if isinstance(e, DeleteWorktreeError): + errors.extend(e.aggregate_errors) + if opt.fail_fast: + logger.error("error: Local checkouts *not* updated.") + raise SyncFailFastError(aggregate_errors=errors) + + try: + self.UpdateCopyLinkfileList(m) + except Exception as e: + err_event.set() + err_update_linkfiles = True + errors.append(e) + if opt.fail_fast: + logger.error( + "error: Local update copyfile or linkfile failed." + ) + raise SyncFailFastError(aggregate_errors=errors) + return err_update_projects, err_update_linkfiles + def _SyncPhased( self, opt, @@ -2064,34 +2112,11 @@ later is required to fix a server side protocol bug. ) raise SyncFailFastError(aggregate_errors=errors) - for m in self.ManifestList(opt): - if m.IsMirror or m.IsArchive: - # Bail out now, we have no working tree. - continue - - try: - self.UpdateProjectList(opt, m) - except Exception as e: - err_event.set() - err_update_projects = True - errors.append(e) - if isinstance(e, DeleteWorktreeError): - errors.extend(e.aggregate_errors) - if opt.fail_fast: - logger.error("error: Local checkouts *not* updated.") - raise SyncFailFastError(aggregate_errors=errors) - - try: - self.UpdateCopyLinkfileList(m) - except Exception as e: - err_update_linkfiles = True - errors.append(e) - err_event.set() - if opt.fail_fast: - logger.error( - "error: Local update copyfile or linkfile failed." - ) - raise SyncFailFastError(aggregate_errors=errors) + err_update_projects, err_update_linkfiles = self._UpdateManifestLists( + opt, + err_event, + errors, + ) err_results = [] # NB: We don't exit here because this is the last step. @@ -2495,7 +2520,7 @@ later is required to fix a server side protocol bug. pm.end() - # TODO(b/421935613): Add the manifest loop block from PhasedSync. + self._UpdateManifestLists(opt, err_event, errors) if not self.outer_client.manifest.IsArchive: self._GCProjects(project_list, opt, err_event) |
