From: Zbigniew Jędrzejewski-Szmek Date: Wed, 3 Jul 2024 14:01:03 +0000 (+0200) Subject: tools/update-distro-hash: rename, fetch the repository if appropriate X-Git-Tag: v257-rc1~850^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=82c459f910c3036b22c9f41472b622ef4bfdab1d;p=thirdparty%2Fsystemd.git tools/update-distro-hash: rename, fetch the repository if appropriate Let's rename the tool to tools/fetch-distro. It's useful to be able to fetch the distro directly. But when that functionality is added, the old name is confusing. Now --update/-u must be specified to update the commits. --reference-if-able is used to speed up the clone of debian. It saves about 75% of the download. --- diff --git a/tools/update-distro-hash.py b/tools/fetch-distro.py similarity index 70% rename from tools/update-distro-hash.py rename to tools/fetch-distro.py index 6f2d37f72e6..dacaf28bcaf 100755 --- a/tools/update-distro-hash.py +++ b/tools/fetch-distro.py @@ -2,7 +2,8 @@ # SPDX-License-Identifier: LGPL-2.1-or-later """ -Fetch commits for pkg/{distribution} and, if changed, commit the latest hash. +Check out pkg/{distribution}. +With -u, fetch commits, and if changed, commit the latest hash. """ import argparse @@ -25,6 +26,11 @@ def parse_args(): action='store_false', default=True, ) + p.add_argument( + '--update', '-u', + action='store_true', + default=False, + ) return p.parse_args() def read_config(distro: str): @@ -46,12 +52,33 @@ def commit_file(distro: str, file: Path, commit: str, changes: str): print(f"+ {shlex.join(cmd)}") subprocess.check_call(cmd) -def update_distro(args, distro: str): - cmd = ['git', '-C', f'pkg/{distro}', 'fetch'] +def checkout_distro(args, distro: str, config: dict): + dest = Path(f'pkg/{distro}') + if dest.exists(): + print(f'{dest} already exists.') + return + + url = config['Environment']['GIT_URL'] + branch = config['Environment']['GIT_BRANCH'] + + # Only debian uses source-git for now… + reference = [f'--reference-if-able=.'] if distro == 'debian' else [] + + cmd = [ + 'git', 'clone', url, + f'--branch={branch}', + dest.as_posix(), + *reference, + ] print(f"+ {shlex.join(cmd)}") subprocess.check_call(cmd) - config = read_config(distro) + args.fetch = False # no need to fetch if we just cloned + +def update_distro(args, distro: str, config: dict): + cmd = ['git', '-C', f'pkg/{distro}', 'fetch'] + print(f"+ {shlex.join(cmd)}") + subprocess.check_call(cmd) branch = config['Environment']['GIT_BRANCH'] old_commit = config['Environment']['GIT_COMMIT'] @@ -86,5 +113,9 @@ def update_distro(args, distro: str): if __name__ == '__main__': args = parse_args() + for distro in args.distribution: - update_distro(args, distro) + config = read_config(distro) + checkout_distro(args, distro, config) + if args.update: + update_distro(args, distro, config)