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

Instead of applying patch in git, fetch it from the local Mercurial repository #1506

Closed
marco-c opened this issue Apr 21, 2020 · 11 comments · Fixed by #3743 or #3789
Closed

Instead of applying patch in git, fetch it from the local Mercurial repository #1506

marco-c opened this issue Apr 21, 2020 · 11 comments · Fixed by #3743 or #3789
Labels
enhancement New feature or request good-first-bug Good for newcomers

Comments

@marco-c
Copy link
Collaborator

marco-c commented Apr 21, 2020

Using git-cinnabar, we can replace

if self.git_repo_dir:
patch_proc = subprocess.Popen(
["patch", "-p1", "--no-backup-if-mismatch", "--force"],
stdin=subprocess.PIPE,
cwd=self.git_repo_dir,
)
patch_proc.communicate(patch.patch.encode("utf-8"))
assert patch_proc.returncode == 0, "Failed to apply patch"
subprocess.run(
[
"git",
"-c",
f"user.name={author_name}",
"-c",
f"user.email={author_email}",
"commit",
"-am",
message,
],
check=True,
cwd=self.git_repo_dir,
)
and just fetch the commit from the local Mercurial repository where we already applied the patch.

Then, we can stop installing patch in our Docker image:

apt-get install -y --no-install-recommends gcc g++ curl patch && \
.

@marco-c marco-c added enhancement New feature or request good-first-bug Good for newcomers labels Apr 21, 2020
@marco-c marco-c added this to To do in Regressor model via automation Apr 21, 2020
@DeepikaKaranji
Copy link

Hi @marco-c, I'd like to try and fix this issue! I hope that's okay :)

@marco-c
Copy link
Collaborator Author

marco-c commented May 7, 2020

Sure, feel free! Any issue is open for contribution by anyone. As a first step, read #1092.

@DeepikaKaranji
Copy link

May I know where the Mercurial repo for bugbug is?

@marco-c
Copy link
Collaborator Author

marco-c commented May 7, 2020

@DeepikaKaranji
Copy link

DeepikaKaranji commented May 8, 2020

So I was able to fetch the commit from my terminal like this:

$git cinnabar fetch hg::https://hg.mozilla.org/mozilla-central/ 50244579252a229131ae04a1d2c60682611e5702

I replaced lines 358-380 with:
bugbug1

But I am not sure how to test this file(bugbug/scripts/commit_classifier.py), without having to run trainer.py as mentioned in the README.

@marco-c
Copy link
Collaborator Author

marco-c commented May 8, 2020

You will need to fetch the commit that was just applied to the local mercurial repository, not a specific commit which already exists in https://hg.mozilla.org/mozilla-central/.

@DeepikaKaranji
Copy link

I think I've not understood what a "local mercurial repo" means.
If I clone the link https://hg.mozilla.org/mozilla-central/ ,is it referred to as a local .hg repo?
How or Where do I find the 'commit that was just applied to the local mercurial repository'?
I'm really sorry if its a silly question, I'm a complete beginner :P

@marco-c
Copy link
Collaborator Author

marco-c commented May 8, 2020

If you look at the code of the commit classifier script mentioned in the first comment, it is cloning a Mercurial repository, then cloning a git repository using git cinnabar. Then it applies a set of patches to the locally cloned Mercurial repository and tries to apply the same set of patches to the locally cloned git repository.
Instead of trying to apply the set of patches to the locally cloned git repository, we want to fetch the patches from the locally cloned Mercurial repository, since we just applied them there.

@KhadijaKamran
Copy link

Hi @marco-c ! I am an Outreachy applicant and I want to work on this issue. Can you confirm if the set of patches are applied to Mercurial from line 352-356?

@marco-c
Copy link
Collaborator Author

marco-c commented Mar 9, 2023

@KhadijaKamran the patch is applied to the Mercurial repo at

hg.import_(
patches=io.BytesIO(patch.patch.encode("utf-8")),
message=message.encode("utf-8"),
user=f"{author_name} <{author_email}>".encode("utf-8"),
)
, and then to the git repo at
patch_proc = subprocess.Popen(
["patch", "-p1", "--no-backup-if-mismatch", "--force"],
stdin=subprocess.PIPE,
cwd=self.git_repo_dir,
)
patch_proc.communicate(patch.patch.encode("utf-8"))
assert patch_proc.returncode == 0, "Failed to apply patch"
subprocess.run(
[
"git",
"-c",
f"user.name={author_name}",
"-c",
f"user.email={author_email}",
"commit",
"-am",
message,
],
check=True,
cwd=self.git_repo_dir,
)
.
What we want to change is the way to apply the patch to the git repo (see the previous comments in this issue).

@KhadijaKamran
Copy link

KhadijaKamran commented Mar 9, 2023

Hey @marco-c! Would the following command help:
git cinnabar hg2git changeset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment