Skip to content

Commit

Permalink
Extend per-Source filter options to submodules.
Browse files Browse the repository at this point in the history
treeless="true" and blobless="true" Source filter settings will
apply to submodules if enableSubmodule="true" is also set on the Source.

Signed-off-by: Nathaniel Haller <[email protected]>
  • Loading branch information
ndhaller committed May 29, 2024
1 parent 627c31f commit a5d09be
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions project_utils/submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _deinit(repo, submodules=None, verbose=False):
return


def _update(repo, submodules=None, verbose=False, recursive=False, cache_path=None):
def _update(repo, submodules=None, verbose=False, recursive=False, cache_path=None, treeless=False, blobless=False):
"""
Performs the update of submodules. This includes the sync and update operations.
Expand All @@ -84,6 +84,10 @@ def _update(repo, submodules=None, verbose=False, recursive=False, cache_path=No
cmd.append('--recursive')
if cache_path is not None:
cmd.extend(['--reference', cache_path])
if treeless:
cmd.extend(['--filter=tree:0'])
elif blobless:
cmd.extend(['--filter=blob:none'])
output_data = repo.git.execute(cmd, with_extended_output=True, with_stdout=True)
ui_functions.display_git_output(output_data, verbose)
else:
Expand All @@ -104,6 +108,10 @@ def _update(repo, submodules=None, verbose=False, recursive=False, cache_path=No
if cache_path is not None:
cmd.extend(['--reference', cache_path])
cmd.extend(['--', sub.path])
if treeless:
cmd.extend(['--filter=tree:0'])
elif blobless:
cmd.extend(['--filter=blob:none'])
output_data = repo.git.execute(cmd, with_extended_output=True, with_stdout=True)
ui_functions.display_git_output(output_data, verbose)
return
Expand Down Expand Up @@ -148,6 +156,33 @@ def _get_submodule_enable(manifest, remote_name, combo):
return source.enable_submodule
return False

def _get_blobless_enable(manifest, remote_name, combo):
"""
Determines if blobless filter is enabled for the current repo and combo
manifest - Manifest object
remote_name - The name of the current remote being processed
combo - The current combo name being processed
"""
repo_sources = manifest.get_repo_sources(combo)
for source in repo_sources:
if source.remote_name == remote_name:
return source.blobless
return False

def _get_treeless_enable(manifest, remote_name, combo):
"""
Determines if treeless filter are enabled for the current repo and combo
manifest - Manifest object
remote_name - The name of the current remote being processed
combo - The current combo name being processed
"""
repo_sources = manifest.get_repo_sources(combo)
for source in repo_sources:
if source.remote_name == remote_name:
return source.treeless
return False

def _get_submodule_state(remote_name, start_manifest, start_combo, end_manifest=None, end_combo=None):
"""
Expand Down Expand Up @@ -219,7 +254,9 @@ def init_full(workspace, manifest, verbose=False):
if args.verbose:
print(strings.SUBMOD_EXCEPTION.format(repo_error))
continue
_update(repo, None, verbose, True)
treeless = _get_treeless_enable(manifest, source.remote_name, current_combo)
blobless = _get_blobless_enable(manifest, source.remote_name, current_combo)
_update(repo, None, verbose, True, treeless=treeless, blobless=blobless)


def deinit_submodules(workspace, start_manifest, start_combo,
Expand Down Expand Up @@ -307,10 +344,12 @@ def maintain_submodules(workspace, manifest, combo_name, verbose=False, cache_pa
_init(repo, repo_subs, verbose)

# Perform sync/update
treeless = _get_treeless_enable(manifest, source.remote_name, combo_name)
blobless = _get_blobless_enable(manifest, source.remote_name, combo_name)
if len(repo_subs) == 0:
_update(repo, None, verbose, cache_path=cache_path)
_update(repo, None, verbose, cache_path=cache_path, treeless=treeless, blobless=blobless)
else:
_update(repo, repo_subs, verbose, cache_path=cache_path)
_update(repo, repo_subs, verbose, cache_path=cache_path, treeless=treeless, blobless=blobless)


if __name__ == '__main__':
Expand Down

0 comments on commit a5d09be

Please sign in to comment.