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 | |
| parent | f7a3f99dc9e92556f3a0c588633b651439b5f7db (diff) | |
| download | git-repo-df3c4017f9a81e268b23728c273e1c8cd8957434.tar.gz | |
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>
| -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 b848d137..3d4ab75c 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -26,7 +26,7 @@ from pathlib import Path | |||
| 26 | import sys | 26 | import sys |
| 27 | import tempfile | 27 | import tempfile |
| 28 | import time | 28 | import time |
| 29 | from typing import List, NamedTuple, Optional, Set, Union | 29 | from typing import List, NamedTuple, Optional, Set, Tuple, Union |
| 30 | import urllib.error | 30 | import urllib.error |
| 31 | import urllib.parse | 31 | import urllib.parse |
| 32 | import urllib.request | 32 | import urllib.request |
| @@ -2006,6 +2006,54 @@ later is required to fix a server side protocol bug. | |||
| 2006 | 2006 | ||
| 2007 | return _threading.Thread(target=_monitor_loop, daemon=True) | 2007 | return _threading.Thread(target=_monitor_loop, daemon=True) |
| 2008 | 2008 | ||
| 2009 | def _UpdateManifestLists( | ||
| 2010 | self, | ||
| 2011 | opt: optparse.Values, | ||
| 2012 | err_event: multiprocessing.Event, | ||
| 2013 | errors: List[Exception], | ||
| 2014 | ) -> Tuple[bool, bool]: | ||
| 2015 | """Updates project lists and copy/link files for all manifests. | ||
| 2016 | |||
| 2017 | Args: | ||
| 2018 | opt: Program options from optparse. | ||
| 2019 | err_event: An event to set if any error occurs. | ||
| 2020 | errors: A list to append any encountered exceptions to. | ||
| 2021 | |||
| 2022 | Returns: | ||
| 2023 | A tuple (err_update_projects, err_update_linkfiles) indicating | ||
| 2024 | an error for each task. | ||
| 2025 | """ | ||
| 2026 | err_update_projects = False | ||
| 2027 | err_update_linkfiles = False | ||
| 2028 | for m in self.ManifestList(opt): | ||
| 2029 | if m.IsMirror or m.IsArchive: | ||
| 2030 | continue | ||
| 2031 | |||
| 2032 | try: | ||
| 2033 | self.UpdateProjectList(opt, m) | ||
| 2034 | except Exception as e: | ||
| 2035 | err_event.set() | ||
| 2036 | err_update_projects = True | ||
| 2037 | errors.append(e) | ||
| 2038 | if isinstance(e, DeleteWorktreeError): | ||
| 2039 | errors.extend(e.aggregate_errors) | ||
| 2040 | if opt.fail_fast: | ||
| 2041 | logger.error("error: Local checkouts *not* updated.") | ||
| 2042 | raise SyncFailFastError(aggregate_errors=errors) | ||
| 2043 | |||
| 2044 | try: | ||
| 2045 | self.UpdateCopyLinkfileList(m) | ||
| 2046 | except Exception as e: | ||
| 2047 | err_event.set() | ||
| 2048 | err_update_linkfiles = True | ||
| 2049 | errors.append(e) | ||
| 2050 | if opt.fail_fast: | ||
| 2051 | logger.error( | ||
| 2052 | "error: Local update copyfile or linkfile failed." | ||
| 2053 | ) | ||
| 2054 | raise SyncFailFastError(aggregate_errors=errors) | ||
| 2055 | return err_update_projects, err_update_linkfiles | ||
| 2056 | |||
| 2009 | def _SyncPhased( | 2057 | def _SyncPhased( |
| 2010 | self, | 2058 | self, |
| 2011 | opt, | 2059 | opt, |
| @@ -2064,34 +2112,11 @@ later is required to fix a server side protocol bug. | |||
| 2064 | ) | 2112 | ) |
| 2065 | raise SyncFailFastError(aggregate_errors=errors) | 2113 | raise SyncFailFastError(aggregate_errors=errors) |
| 2066 | 2114 | ||
| 2067 | for m in self.ManifestList(opt): | 2115 | err_update_projects, err_update_linkfiles = self._UpdateManifestLists( |
| 2068 | if m.IsMirror or m.IsArchive: | 2116 | opt, |
| 2069 | # Bail out now, we have no working tree. | 2117 | err_event, |
| 2070 | continue | 2118 | errors, |
| 2071 | 2119 | ) | |
| 2072 | try: | ||
| 2073 | self.UpdateProjectList(opt, m) | ||
| 2074 | except Exception as e: | ||
| 2075 | err_event.set() | ||
| 2076 | err_update_projects = True | ||
| 2077 | errors.append(e) | ||
| 2078 | if isinstance(e, DeleteWorktreeError): | ||
| 2079 | errors.extend(e.aggregate_errors) | ||
| 2080 | if opt.fail_fast: | ||
| 2081 | logger.error("error: Local checkouts *not* updated.") | ||
| 2082 | raise SyncFailFastError(aggregate_errors=errors) | ||
| 2083 | |||
| 2084 | try: | ||
| 2085 | self.UpdateCopyLinkfileList(m) | ||
| 2086 | except Exception as e: | ||
| 2087 | err_update_linkfiles = True | ||
| 2088 | errors.append(e) | ||
| 2089 | err_event.set() | ||
| 2090 | if opt.fail_fast: | ||
| 2091 | logger.error( | ||
| 2092 | "error: Local update copyfile or linkfile failed." | ||
| 2093 | ) | ||
| 2094 | raise SyncFailFastError(aggregate_errors=errors) | ||
| 2095 | 2120 | ||
| 2096 | err_results = [] | 2121 | err_results = [] |
| 2097 | # NB: We don't exit here because this is the last step. | 2122 | # 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. | |||
| 2495 | 2520 | ||
| 2496 | pm.end() | 2521 | pm.end() |
| 2497 | 2522 | ||
| 2498 | # TODO(b/421935613): Add the manifest loop block from PhasedSync. | 2523 | self._UpdateManifestLists(opt, err_event, errors) |
| 2499 | if not self.outer_client.manifest.IsArchive: | 2524 | if not self.outer_client.manifest.IsArchive: |
| 2500 | self._GCProjects(project_list, opt, err_event) | 2525 | self._GCProjects(project_list, opt, err_event) |
| 2501 | 2526 | ||
