1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-18 10:04:04 +03:00

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.
This commit is contained in:
Antonio Alvarez Feijoo 2025-01-15 12:01:22 +01:00 committed by Luca Boccassi
parent e9b9fc080f
commit 49879a32b6

View File

@ -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()