From a5d09be06ace7a91f5d6dc21063c01b4759e6f92 Mon Sep 17 00:00:00 2001 From: Nathaniel Haller Date: Tue, 28 May 2024 18:33:14 -0700 Subject: [PATCH] Extend per-Source filter options to submodules. 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 --- project_utils/submodule.py | 47 ++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/project_utils/submodule.py b/project_utils/submodule.py index 8094a96..51c21f8 100644 --- a/project_utils/submodule.py +++ b/project_utils/submodule.py @@ -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. @@ -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: @@ -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 @@ -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): """ @@ -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, @@ -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__':