Skip to content

Commit

Permalink
kernelci/build.py: Add apply_patch_mbox method
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Yurin <[email protected]>
  • Loading branch information
yurinnick committed Aug 21, 2023
1 parent f5a0a7d commit 51aedc8
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions kernelci/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import re
import shutil
import tarfile
import tempfile
import time
import urllib.parse

Expand Down Expand Up @@ -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="[email protected]"
):
"""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)
Expand Down

0 comments on commit 51aedc8

Please sign in to comment.