Skip to content

Commit

Permalink
manifest_xml: Add Load and Unload methods
Browse files Browse the repository at this point in the history
- do not call the internal method from subcmds/sync.py.
- use the correct default groups for submanifests.
- only sync the superproject when we are told to.

Change-Id: I81e4025058f1ee564732b9e17aecc522f6b5f626
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/334639
Reviewed-by: Mike Frysinger <[email protected]>
Reviewed-by: Raman Tenneti <[email protected]>
Tested-by: LaMont Jones <[email protected]>
  • Loading branch information
lamontj committed Apr 8, 2022
1 parent 55ee304 commit a2ff20d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
19 changes: 15 additions & 4 deletions manifest_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def __init__(self, repodir, manifest_file, local_manifests=None,
if os.path.exists(mp.gitdir) and mp.use_worktree:
mp.use_git_worktrees = True

self._Unload()
self.Unload()

def Override(self, name, load_local_manifests=True):
"""Use a different manifest, just for the current instantiation.
Expand All @@ -399,7 +399,7 @@ def Override(self, name, load_local_manifests=True):
try:
self._load_local_manifests = load_local_manifests
self.manifestFile = path
self._Unload()
self.Unload()
self._Load()
finally:
self.manifestFile = old
Expand Down Expand Up @@ -970,7 +970,13 @@ def GetGroupsStr(self):
groups = self.GetDefaultGroupsStr()
return groups

def _Unload(self):
def Unload(self):
"""Unload the manifest.
If the manifest files have been changed since Load() was called, this will
cause the new/updated manifest to be used.
"""
self._loaded = False
self._projects = {}
self._paths = {}
Expand All @@ -984,6 +990,11 @@ def _Unload(self):
self.branch = None
self._manifest_server = None

def Load(self):
"""Read the manifest into memory."""
# Do not expose internal arguments.
self._Load()

def _Load(self, initial_client=None, submanifest_depth=0):
if submanifest_depth > MAX_SUBMANIFEST_DEPTH:
raise ManifestParseError('maximum submanifest depth %d exceeded.' %
Expand Down Expand Up @@ -1030,7 +1041,7 @@ def _Load(self, initial_client=None, submanifest_depth=0):
except ManifestParseError as e:
# There was a problem parsing, unload ourselves in case they catch
# this error and try again later, we will show the correct error
self._Unload()
self.Unload()
raise e

if self.IsMirror:
Expand Down
27 changes: 14 additions & 13 deletions project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3491,6 +3491,8 @@ def Sync(self, _kwargs_only=(), manifest_url='', manifest_branch=None,
"""
assert _kwargs_only == (), 'Sync only accepts keyword arguments.'

groups = groups or 'default'
platform = platform or 'auto'
git_event_log = git_event_log or EventLog()
if outer_manifest and self.manifest.is_submanifest:
# In a multi-manifest checkout, use the outer manifest unless we are told
Expand Down Expand Up @@ -3783,19 +3785,18 @@ def Sync(self, _kwargs_only=(), manifest_url='', manifest_branch=None,
)

# Lastly, clone the superproject(s).
if outer_manifest and not self.manifest.is_submanifest:
for m in self.manifest.all_manifests:
sync_result = Superproject(
m, m.repodir, git_event_log, quiet=not verbose).Sync()
if not sync_result.success:
print(f'warning: git update of superproject for {m.path_prefix} failed, '
'repo sync will not '
'use superproject to fetch source; while this error is not fatal, '
'and you can continue to run repo sync, please run repo init with '
'the --no-use-superproject option to stop seeing this warning',
file=sys.stderr)
if sync_result.fatal and use_superproject is not None:
return False
if self.manifest.manifestProject.use_superproject:
sync_result = Superproject(
self.manifest, self.manifest.repodir, git_event_log, quiet=not verbose).Sync()
if not sync_result.success:
print('warning: git update of superproject for '
f'{self.manifest.path_prefix} failed, repo sync will not use '
'superproject to fetch source; while this error is not fatal, '
'and you can continue to run repo sync, please run repo init '
'with the --no-use-superproject option to stop seeing this '
'warning', file=sys.stderr)
if sync_result.fatal and use_superproject is not None:
return False

return True

Expand Down
4 changes: 2 additions & 2 deletions subcmds/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,10 @@ def _ReloadManifest(self, manifest_name=None, load_local_manifests=True):
load_local_manifests: Whether to load local manifests.
"""
if manifest_name:
# Override calls _Unload already
# Override calls Unload already
self.manifest.Override(manifest_name, load_local_manifests=load_local_manifests)
else:
self.manifest._Unload()
self.manifest.Unload()

def UpdateProjectList(self, opt):
new_project_paths = []
Expand Down

0 comments on commit a2ff20d

Please sign in to comment.