Skip to content

Commit cc52244

Browse files
committed
kernelci/build.py: Add apply_patch_mbox method
Signed-off-by: Nikolay Yurin <[email protected]>
1 parent f15fa07 commit cc52244

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

kernelci/build.py

+32
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import re
2525
import shutil
2626
import tarfile
27+
import tempfile
2728
import time
2829
import urllib.parse
2930

@@ -321,6 +322,37 @@ def _download_file(url, dest_filename, chunk_size=1024):
321322
return False
322323

323324

325+
def apply_patch_mbox(
326+
kdir,
327+
mbox_url,
328+
git_username="kernelci-tsc",
329+
git_email="[email protected]"
330+
):
331+
"""Download patch mbox from URL and apply with 3-way merge
332+
333+
*kdir* is the path to a kernel source directory
334+
*mbox_url* is the URL to patch mbox content
335+
*git_username* is the username used to apply the patch
336+
*git_email* is the email used to apply the patch
337+
"""
338+
with tempfile.NamedTemporaryFile(prefix="kernel-patch-") as tmp_f:
339+
if not _download_file(mbox_url, tmp_f.name):
340+
raise FileNotFoundError(f"Error downloading patch mbox {mbox_url}")
341+
342+
shell_cmd("""
343+
set -e
344+
cd {kdir}
345+
git config user.name "{git_username}"
346+
git config user.email "{git_email}"
347+
git am --3way {mbox_file}
348+
""".format(
349+
kdir=kdir,
350+
mbox_file=tmp_f.name,
351+
git_username=git_username,
352+
git_email=git_email
353+
))
354+
355+
324356
def pull_tarball(kdir, url, dest_filename, retries, delete):
325357
if os.path.exists(kdir):
326358
shutil.rmtree(kdir)

0 commit comments

Comments
 (0)