From: Antonio Alvarez Feijoo Date: Wed, 15 Jan 2025 11:01:22 +0000 (+0100) Subject: tools/fetch-distro: support the case where the sources are in a subdirectory X-Git-Tag: v258-rc1~1601 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49879a32b603ddc1dbbbc39ca07d328c0318bd67;p=thirdparty%2Fsystemd.git 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. --- diff --git a/tools/fetch-distro.py b/tools/fetch-distro.py index 1da1b8486e2..1d9f10005ea 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()