Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernelci/build.py: Add apply_patch_mbox method #2041

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
yurinnick marked this conversation as resolved.
Show resolved Hide resolved
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}"
Comment on lines +345 to +346
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I mean, I think we should actually remove these lines. Say, if you're doing this over your working kernel source tree and you don't specify command line arguments with your current user name and email then it will replace it. And then next time you make a commit in the kernel source tree it'll be with the [email protected] email.

So it should be left to the user to manage this outside of kci_build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean it should be part of KernelCI config files or something? Sorry, I am not quite following what do you mean. Git won't allow to apply patches without name and email being set though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be part of the user's Git config, yes. Or we could maybe have a separate command to set the user name and email explicitly if some CI systems need to do that, as a handy wrapper.

Git won't allow to apply patches without name and email being set though.

Yes and that's fine. If there's no user name and email configured then git will fail and the issue will be on the user to solve it. Just like running any other invalid command (say, if kdir is not a Git repo etc.).

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