diff options
author | Antonio Alvarez Feijoo <antonio.feijoo@suse.com> | 2025-01-15 12:01:22 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2025-01-15 16:33:00 +0100 |
commit | 49879a32b603ddc1dbbbc39ca07d328c0318bd67 (patch) | |
tree | bfb2f264846758b09925e9633f0f9d8a9e60bf9e /tools/fetch-distro.py | |
parent | ci: Stop archiving packages (diff) | |
download | systemd-49879a32b603ddc1dbbbc39ca07d328c0318bd67.tar.xz systemd-49879a32b603ddc1dbbbc39ca07d328c0318bd67.zip |
tools/fetch-distro: support the case where the sources are in a subdirectory
If the GIT_SUBDIR environment variable is set, do not checkout the full sources
of the git repository, but perform a sparse checkout of the directory containing
the package. In this case, check only the commit history in this subdirectory.
Diffstat (limited to '')
-rwxr-xr-x | tools/fetch-distro.py | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/tools/fetch-distro.py b/tools/fetch-distro.py index 1da1b8486e..1d9f10005e 100755 --- a/tools/fetch-distro.py +++ b/tools/fetch-distro.py @@ -60,35 +60,57 @@ def checkout_distro(args, distro: str, config: dict): url = config['Environment']['GIT_URL'] branch = config['Environment']['GIT_BRANCH'] + subdir = config['Environment'].get('GIT_SUBDIR') + + # Do not checkout the full sources if the package is in a subdirectory, + # a sparse checkout will be done after + sparse = ['--no-checkout', '--filter=blob:none'] if subdir is not None else [] # Only debian uses source-git for now… - reference = [f'--reference-if-able=.'] if distro == 'debian' else [] + reference = ['--reference-if-able=.'] if distro == 'debian' else [] cmd = [ 'git', 'clone', url, f'--branch={branch}', + *sparse, dest.as_posix(), *reference, ] print(f"+ {shlex.join(cmd)}") subprocess.check_call(cmd) + # Sparse checkout if the package is in a subdirectory + if subdir is not None: + cmd = ['git', '-C', f'pkg/{distro}', 'sparse-checkout', 'set', + '--no-cone', f'{subdir}'] + print(f"+ {shlex.join(cmd)}") + subprocess.check_call(cmd) + + cmd = ['git', '-C', f'pkg/{distro}', 'checkout', 'HEAD'] + print(f"+ {shlex.join(cmd)}") + subprocess.check_call(cmd) + args.fetch = False # no need to fetch if we just cloned def update_distro(args, distro: str, config: dict): branch = config['Environment']['GIT_BRANCH'] + subdir = config['Environment'].get('GIT_SUBDIR') old_commit = config['Environment']['GIT_COMMIT'] cmd = ['git', '-C', f'pkg/{distro}', 'switch', branch] print(f"+ {shlex.join(cmd)}") subprocess.check_call(cmd) - cmd = ['git', '-C', f'pkg/{distro}', 'fetch', 'origin', '-v', - f'{branch}:remotes/origin/{branch}'] - print(f"+ {shlex.join(cmd)}") - subprocess.check_call(cmd) + if args.fetch: + cmd = ['git', '-C', f'pkg/{distro}', 'fetch', 'origin', '-v', + f'{branch}:remotes/origin/{branch}'] + print(f"+ {shlex.join(cmd)}") + subprocess.check_call(cmd) - cmd = ['git', '-C', f'pkg/{distro}', 'rev-parse', f'refs/remotes/origin/{branch}'] + cmd = ['git', '-C', f'pkg/{distro}', 'log', '-n1', '--format=%H', + f'refs/remotes/origin/{branch}'] + if subdir is not None: + cmd += [f'{subdir}'] print(f"+ {shlex.join(cmd)}") new_commit = subprocess.check_output(cmd, text=True).strip() @@ -99,6 +121,8 @@ def update_distro(args, distro: str, config: dict): cmd = ['git', '-C', f'pkg/{distro}', 'log', '--graph', '--first-parent', '--pretty=oneline', '--no-decorate', '--abbrev-commit', '--abbrev=10', f'{old_commit}..{new_commit}'] + if subdir is not None: + cmd += [f'{subdir}'] print(f"+ {shlex.join(cmd)}") changes = subprocess.check_output(cmd, text=True).strip() |