1
0
Fork 0

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
This commit is contained in:
Gavin Mak 2025-06-17 18:26:30 -07:00
parent 7b15ee210d
commit 2cfdfe4655

View file

@ -26,7 +26,7 @@ from pathlib import Path
import sys import sys
import tempfile import tempfile
import time import time
from typing import List, NamedTuple, Optional, Set, Union from typing import List, NamedTuple, Optional, Set, Tuple, Union
import urllib.error import urllib.error
import urllib.parse import urllib.parse
import urllib.request import urllib.request
@ -2005,6 +2005,54 @@ later is required to fix a server side protocol bug.
return _threading.Thread(target=_monitor_loop, daemon=True) return _threading.Thread(target=_monitor_loop, daemon=True)
def _UpdateManifestLists(
self,
opt: optparse.Values,
errors: List[Exception],
err_event: multiprocessing.Event,
) -> Tuple[bool, bool]:
"""Updates project, copy, and linkfile lists for all manifests.
Args:
opt: Program options from optparse.
errors: A list to append any encountered exceptions to.
err_event: An event to set if any error occurs.
Returns:
A tuple (projects_ok, copylink_ok) indicating success for each task.
"""
projects_ok = True
copylink_ok = True
for m in self.ManifestList(opt):
if m.IsMirror or m.IsArchive:
# No working tree to update.
continue
try:
self.UpdateProjectList(opt, m)
except Exception as e:
projects_ok = False
err_event.set()
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:
copylink_ok = False
err_event.set()
errors.append(e)
if opt.fail_fast:
logger.error(
"error: Local update copyfile or linkfile failed."
)
raise SyncFailFastError(aggregate_errors=errors)
return projects_ok, copylink_ok
def _SyncPhased( def _SyncPhased(
self, self,
opt, opt,
@ -2063,35 +2111,13 @@ later is required to fix a server side protocol bug.
) )
raise SyncFailFastError(aggregate_errors=errors) raise SyncFailFastError(aggregate_errors=errors)
for m in self.ManifestList(opt): projects_ok, copylink_ok = self._UpdateManifestLists(
if m.IsMirror or m.IsArchive: opt, errors, err_event
# Bail out now, we have no working tree. )
continue if not projects_ok:
err_update_projects = True
try: if not copylink_ok:
self.UpdateProjectList(opt, m) err_update_linkfiles = True
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_results = [] err_results = []
# NB: We don't exit here because this is the last step. # NB: We don't exit here because this is the last step.
err_checkout = not self._Checkout( err_checkout = not self._Checkout(
@ -2166,7 +2192,8 @@ later is required to fix a server side protocol bug.
) )
fetch_success = sync_result.success fetch_success = sync_result.success
remote_fetched = sync_result.remote_fetched remote_fetched = sync_result.remote_fetched
fetch_error = sync_result.error if sync_result.error:
fetch_error = sync_result.error
except KeyboardInterrupt: except KeyboardInterrupt:
logger.error( logger.error(
"Keyboard interrupt while processing %s", project.name "Keyboard interrupt while processing %s", project.name
@ -2494,7 +2521,7 @@ later is required to fix a server side protocol bug.
pm.end() pm.end()
# TODO(b/421935613): Add the manifest loop block from PhasedSync. self._UpdateManifestLists(opt, errors, err_event)
if not self.outer_client.manifest.IsArchive: if not self.outer_client.manifest.IsArchive:
self._GCProjects(project_list, opt, err_event) self._GCProjects(project_list, opt, err_event)