summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
Diffstat (limited to 'project.py')
-rw-r--r--project.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/project.py b/project.py
index 2b57a5fb..0da2118b 100644
--- a/project.py
+++ b/project.py
@@ -26,6 +26,7 @@ import sys
26import tarfile 26import tarfile
27import tempfile 27import tempfile
28import time 28import time
29from typing import NamedTuple
29import urllib.parse 30import urllib.parse
30 31
31from color import Coloring 32from color import Coloring
@@ -45,6 +46,14 @@ from repo_trace import IsTrace, Trace
45from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M 46from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M
46 47
47 48
49class SyncNetworkHalfResult(NamedTuple):
50 """Sync_NetworkHalf return value."""
51 # True if successful.
52 success: bool
53 # Did we query the remote? False when optimized_fetch is True and we have the
54 # commit already present.
55 remote_fetched: bool
56
48# Maximum sleep time allowed during retries. 57# Maximum sleep time allowed during retries.
49MAXIMUM_RETRY_SLEEP_SEC = 3600.0 58MAXIMUM_RETRY_SLEEP_SEC = 3600.0
50# +-10% random jitter is added to each Fetches retry sleep duration. 59# +-10% random jitter is added to each Fetches retry sleep duration.
@@ -1133,7 +1142,7 @@ class Project(object):
1133 if archive and not isinstance(self, MetaProject): 1142 if archive and not isinstance(self, MetaProject):
1134 if self.remote.url.startswith(('http://', 'https://')): 1143 if self.remote.url.startswith(('http://', 'https://')):
1135 _error("%s: Cannot fetch archives from http/https remotes.", self.name) 1144 _error("%s: Cannot fetch archives from http/https remotes.", self.name)
1136 return False 1145 return SyncNetworkHalfResult(False, False)
1137 1146
1138 name = self.relpath.replace('\\', '/') 1147 name = self.relpath.replace('\\', '/')
1139 name = name.replace('/', '_') 1148 name = name.replace('/', '_')
@@ -1144,19 +1153,19 @@ class Project(object):
1144 self._FetchArchive(tarpath, cwd=topdir) 1153 self._FetchArchive(tarpath, cwd=topdir)
1145 except GitError as e: 1154 except GitError as e:
1146 _error('%s', e) 1155 _error('%s', e)
1147 return False 1156 return SyncNetworkHalfResult(False, False)
1148 1157
1149 # From now on, we only need absolute tarpath 1158 # From now on, we only need absolute tarpath
1150 tarpath = os.path.join(topdir, tarpath) 1159 tarpath = os.path.join(topdir, tarpath)
1151 1160
1152 if not self._ExtractArchive(tarpath, path=topdir): 1161 if not self._ExtractArchive(tarpath, path=topdir):
1153 return False 1162 return SyncNetworkHalfResult(False, True)
1154 try: 1163 try:
1155 platform_utils.remove(tarpath) 1164 platform_utils.remove(tarpath)
1156 except OSError as e: 1165 except OSError as e:
1157 _warn("Cannot remove archive %s: %s", tarpath, str(e)) 1166 _warn("Cannot remove archive %s: %s", tarpath, str(e))
1158 self._CopyAndLinkFiles() 1167 self._CopyAndLinkFiles()
1159 return True 1168 return SyncNetworkHalfResult(True, True)
1160 1169
1161 # If the shared object dir already exists, don't try to rebootstrap with a 1170 # If the shared object dir already exists, don't try to rebootstrap with a
1162 # clone bundle download. We should have the majority of objects already. 1171 # clone bundle download. We should have the majority of objects already.
@@ -1220,9 +1229,11 @@ class Project(object):
1220 depth = self.manifest.manifestProject.depth 1229 depth = self.manifest.manifestProject.depth
1221 1230
1222 # See if we can skip the network fetch entirely. 1231 # See if we can skip the network fetch entirely.
1232 remote_fetched = False
1223 if not (optimized_fetch and 1233 if not (optimized_fetch and
1224 (ID_RE.match(self.revisionExpr) and 1234 (ID_RE.match(self.revisionExpr) and
1225 self._CheckForImmutableRevision())): 1235 self._CheckForImmutableRevision())):
1236 remote_fetched = True
1226 if not self._RemoteFetch( 1237 if not self._RemoteFetch(
1227 initial=is_new, 1238 initial=is_new,
1228 quiet=quiet, verbose=verbose, output_redir=output_redir, 1239 quiet=quiet, verbose=verbose, output_redir=output_redir,
@@ -1231,7 +1242,7 @@ class Project(object):
1231 submodules=submodules, force_sync=force_sync, 1242 submodules=submodules, force_sync=force_sync,
1232 ssh_proxy=ssh_proxy, 1243 ssh_proxy=ssh_proxy,
1233 clone_filter=clone_filter, retry_fetches=retry_fetches): 1244 clone_filter=clone_filter, retry_fetches=retry_fetches):
1234 return False 1245 return SyncNetworkHalfResult(False, remote_fetched)
1235 1246
1236 mp = self.manifest.manifestProject 1247 mp = self.manifest.manifestProject
1237 dissociate = mp.dissociate 1248 dissociate = mp.dissociate
@@ -1244,7 +1255,7 @@ class Project(object):
1244 if p.stdout and output_redir: 1255 if p.stdout and output_redir:
1245 output_redir.write(p.stdout) 1256 output_redir.write(p.stdout)
1246 if p.Wait() != 0: 1257 if p.Wait() != 0:
1247 return False 1258 return SyncNetworkHalfResult(False, remote_fetched)
1248 platform_utils.remove(alternates_file) 1259 platform_utils.remove(alternates_file)
1249 1260
1250 if self.worktree: 1261 if self.worktree:
@@ -1253,7 +1264,7 @@ class Project(object):
1253 self._InitMirrorHead() 1264 self._InitMirrorHead()
1254 platform_utils.remove(os.path.join(self.gitdir, 'FETCH_HEAD'), 1265 platform_utils.remove(os.path.join(self.gitdir, 'FETCH_HEAD'),
1255 missing_ok=True) 1266 missing_ok=True)
1256 return True 1267 return SyncNetworkHalfResult(True, remote_fetched)
1257 1268
1258 def PostRepoUpgrade(self): 1269 def PostRepoUpgrade(self):
1259 self._InitHooks() 1270 self._InitHooks()
@@ -3836,7 +3847,7 @@ class ManifestProject(MetaProject):
3836 is_new=is_new, quiet=not verbose, verbose=verbose, 3847 is_new=is_new, quiet=not verbose, verbose=verbose,
3837 clone_bundle=clone_bundle, current_branch_only=current_branch_only, 3848 clone_bundle=clone_bundle, current_branch_only=current_branch_only,
3838 tags=tags, submodules=submodules, clone_filter=clone_filter, 3849 tags=tags, submodules=submodules, clone_filter=clone_filter,
3839 partial_clone_exclude=self.manifest.PartialCloneExclude): 3850 partial_clone_exclude=self.manifest.PartialCloneExclude).success:
3840 r = self.GetRemote() 3851 r = self.GetRemote()
3841 print('fatal: cannot obtain manifest %s' % r.url, file=sys.stderr) 3852 print('fatal: cannot obtain manifest %s' % r.url, file=sys.stderr)
3842 3853