From cc52244a9bd40e97c05937fdc8a25c1d9228119c Mon Sep 17 00:00:00 2001 From: Nikolay Yurin Date: Mon, 31 Jul 2023 17:01:11 -0700 Subject: [PATCH] kernelci/build.py: Add apply_patch_mbox method Signed-off-by: Nikolay Yurin --- kernelci/build.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/kernelci/build.py b/kernelci/build.py index e4ee20ac0c..bdf4a25980 100644 --- a/kernelci/build.py +++ b/kernelci/build.py @@ -24,6 +24,7 @@ import re import shutil import tarfile +import tempfile import time import urllib.parse @@ -321,6 +322,37 @@ def _download_file(url, dest_filename, chunk_size=1024): return False +def apply_patch_mbox( + kdir, + mbox_url, + git_username="kernelci-tsc", + git_email="kernelci-tsc@groups.io" +): + """Download patch mbox from URL and apply with 3-way merge + + *kdir* is the path to a kernel source directory + *mbox_url* is the URL to patch mbox content + *git_username* is the username used to apply the patch + *git_email* is the email used to apply the patch + """ + with tempfile.NamedTemporaryFile(prefix="kernel-patch-") as tmp_f: + if not _download_file(mbox_url, tmp_f.name): + raise FileNotFoundError(f"Error downloading patch mbox {mbox_url}") + + shell_cmd(""" +set -e +cd {kdir} +git config user.name "{git_username}" +git config user.email "{git_email}" +git am --3way {mbox_file} +""".format( + kdir=kdir, + mbox_file=tmp_f.name, + git_username=git_username, + git_email=git_email + )) + + def pull_tarball(kdir, url, dest_filename, retries, delete): if os.path.exists(kdir): shutil.rmtree(kdir)