holdenk commented on code in PR #60472:
URL: https://github.com/apache/spark/pull/60472#discussion_r4577185027
##########
dev/merge_spark_pr.py:
##########
@@ -1209,12 +2072,507 @@ def merge_pr(pr_num, target_ref, title, body,
pr_repo_desc, pr_author, co_author
return merge_hash
-def _do_cherry_pick(pr_num, merge_hash, pick_ref):
- """Cherry-pick `merge_hash` onto `pick_ref` and push.
+def _set_skip_trailer(skip):
+ """Amend HEAD so it carries the skip trailer exactly when `skip`; leave it
be otherwise,
+ so a retried push sends the same commit. Reads HEAD afresh, keeping any
amend made since.
+ """
+ current = git.run(["git", "log", "-1", "--format=%B"])
+ wanted = remove_inherited_post_merge_ci_skip(current)
+ if skip:
+ wanted = append_post_merge_ci_skip(wanted)
+ if wanted != current:
Review Comment:
Fixed in 927971fa8c5, taking the suggestion. The `sampled()` mock now
returns `%B` with git's extra newline, so the `[d][d]` case only passes with
one amend. Removing the `rstrip` fails it.
---
<sub>馃 Posted by an AI agent (Claude Code 路 skill `none`) on behalf of
@holdenk.</sub>
<!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk
-->
##########
dev/merge_spark_pr.py:
##########
@@ -3518,56 +5071,83 @@ def main():
print("title\t%s\nsource\t%s\ntarget\t%s\nurl\t%s" % (title, pr_repo_desc,
target_ref, url))
continue_maybe("Proceed with merging pull request #%s?" % pr_num)
- merged_refs = [target_ref]
-
merge_hash = merge_pr(pr_num, target_ref, title, body, pr_repo_desc,
pr_author, co_authors)
- # Ordered (branch, commit_hash) pairs for the merge comment: the merge
sink first,
- # then each cherry-pick target as it is picked.
- merged_commits = [(target_ref, merge_hash)]
-
- # merged_refs drives both the next prompt default and the already_picked
set passed to
- # cherry_pick, so each grows with every cherry-pick -- including branches
consumed by the
- # Upstream-First two-branch path inside cherry_pick (e.g. picking
branch-M.x + branch-M.N
- # in a single prompt). It starts with target_ref, the merge sink, never to
be re-picked.
+ # target_ref, the merge sink, is never to be re-picked. A merged backport
PR also inherits
+ # the original's branches, so [p] does not force-push over its other open
backport PRs.
+ if backport:
+ picks = _seed_picks(backport[0], target_ref, branch_names)
Review Comment:
Fixed in 927971fa8c5: the ledger starts as `_PickLedger([target_ref])`
before the `try`, and the backport seeding is the first statement inside it. A
new `main_ledgers` case raises `KeyboardInterrupt` from the fork lookup and
checks the PR is still closed, the merge line is still commented, and JIRA
still gets the merged branch. Moving the seeding back above the `try` fails it.
---
<sub>馃 Posted by an AI agent (Claude Code 路 skill `none`) on behalf of
@holdenk.</sub>
<!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk
-->
##########
dev/merge_spark_pr.py:
##########
@@ -1146,41 +1974,76 @@ def merge_pr(pr_num, target_ref, title, body,
pr_repo_desc, pr_author, co_author
continue_maybe(msg)
had_conflicts = True
- # Use PR author as the primary author for proper GitHub attribution
- primary_author = bold_input(
- 'Enter primary author in the format of "name <email>" [%s]: ' %
pr_author
- )
- if primary_author == "":
- primary_author = pr_author
-
- merge_message_flags = []
-
- merge_message_flags += ["-m", title]
- if body is not None:
- # We remove @ symbols from the body to avoid triggering e-mails
- # to people every time someone creates a public fork of Spark.
- merge_message_flags += ["-m", body.replace("@", "")]
+ backport = _backport_of(body, pr_repo_desc.split("/", 1)[-1], target_ref)
+ if backport:
+ # The footer already names the author; a different --author would
contradict it.
+ print("Backport of #%s: keeping its commit message and author." %
backport[0])
+ # Soft check: the marker and footer are plain PR text, so confirm they
are some
+ # commit's message on the branch, as _land_via_fork leaves them.
+ commits = git.run(["git", "log", "--format=%b%x00", "HEAD..%s" %
pr_branch_name])
+ if backport[1] not in [_pick_message(c) for c in commits.split("\0")]:
+ continue_maybe(
+ "The Backport-of message in the PR body matches none of its
commits, so the "
+ "author and footer below are only as good as that text. Merge
it anyway?"
+ )
+ primary_author = backport[2]
+ else:
+ # Use PR author as the primary author for proper GitHub attribution
+ primary_author = bold_input(
+ 'Enter primary author in the format of "name <email>" [%s]: ' %
pr_author
+ )
+ if primary_author == "":
+ primary_author = pr_author
committer_name = git.run("git config --get user.name").strip()
committer_email = git.run("git config --get user.email").strip()
+ signoff = "Signed-off-by: %s <%s>" % (committer_name, committer_email)
+ conflicts = "This patch had conflicts when merged, resolved by\nCommitter:
%s <%s>" % (
+ committer_name,
+ committer_email,
+ )
- if had_conflicts:
- message = "This patch had conflicts when merged, resolved
by\nCommitter: %s <%s>" % (
- committer_name,
- committer_email,
+ merge_message_flags = ["-m", title]
+ if backport:
+ # The original message already ends with #N's footer and authors (its
@s were stripped
+ # at the original merge). No "Closes #<this PR>": that would become
the last footer and
+ # hide the branch from #N's merge status. main() closes this PR
through the API.
+ # git reads trailers from the last paragraph only, so the conflicts
note goes first
+ # and ours join the original's.
+ if had_conflicts:
+ merge_message_flags += ["-m", conflicts]
+ # Deduplicate original authors by email; sign-offs do not credit fixup
authors.
+ credited = re.findall(
+ r"^(?:Lead-authored-by|Authored-by|Co-authored-by): (.+)$",
+ backport[1].rsplit("\n\n", 1)[-1],
Review Comment:
Fixed in 927971fa8c5: credited authors are read from the original's last
`Closes #N from` footer onward, so the pick's own paragraph after it no longer
hides them. Author lines quoted before that footer still don't count. New
`merge_pr` case: a pick whose `(cherry picked...)` and sign-off stand in their
own paragraph, with its author among the commit authors, adds no
`Co-authored-by` for that author.
---
<sub>馃 Posted by an AI agent (Claude Code 路 skill `none`) on behalf of
@holdenk.</sub>
<!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk
-->
##########
dev/merge_spark_pr.py:
##########
@@ -1010,19 +1247,137 @@ class SkipCherryPick(Exception):
"""
-def continue_maybe(prompt, cherry=False):
+def continue_maybe(prompt: str, cherry: bool = False) -> None:
+ """Prompt to continue; on "no" either skip this cherry-pick (`cherry`) or
exit the script.
+
+ `cherry` is the decline semantics, not a statement that a cherry-pick is
mid-flight: the
+ pre-push checks run after the pick is committed, and declining there must
still skip only
+ that branch. So the abort is attempted only when git says one is actually
in progress.
+
+ >>> from contextlib import redirect_stdout
+ >>> from io import StringIO
+ >>> from unittest.mock import call, patch
+
+ Declining with `cherry` while a pick is mid-flight aborts the pick before
skipping --
+ the first git call is the probe, the second the abort:
+
+ >>> with (
+ ... patch("builtins.input", return_value=""),
+ ... patch.object(git, "run", side_effect=["", ""]) as run,
+ ... redirect_stdout(StringIO()),
+ ... ):
+ ... try:
+ ... continue_maybe("Resolved?", cherry=True)
+ ... skipped = False
+ ... except SkipCherryPick:
+ ... skipped = True
+ >>> skipped
+ True
+ >>> run.call_args_list[0]
+ call(['git', 'rev-parse', '--verify', '--quiet', 'CHERRY_PICK_HEAD'])
+ >>> run.call_args_list[1]
+ call('git cherry-pick --abort')
+ >>> run.call_count
+ 2
+
+ After the pick is committed there is nothing to abort. A checkout git
refuses over
+ uncommitted edits waits for the committer to stash them, then the branch
is skipped:
+
+ >>> refused = subprocess.CalledProcessError(1, "git checkout")
+ >>> with (
+ ... patch("builtins.input", side_effect=["", ""]) as inp,
+ ... patch.object(git, "run", side_effect=[refused, refused, ""]) as
run,
+ ... patch.dict(continue_maybe.__globals__, original_head="master"),
+ ... patch.object(sys.modules[__name__], "clean_up") as clean,
+ ... redirect_stdout(StringIO()),
+ ... ):
+ ... try:
+ ... continue_maybe("Push anyway?", cherry=True)
+ ... skipped = False
+ ... except SkipCherryPick:
+ ... skipped = True
+ >>> skipped
+ True
+ >>> [c.args[0] for c in run.call_args_list[1:]]
+ [['git', 'checkout', 'master'], ['git', 'checkout', 'master']]
+ >>> inp.call_count, clean.call_count
+ (2, 1)
+
+ A checkout git keeps refusing, e.g. over a stale index.lock, can be given
up on:
+
+ >>> with (
+ ... patch("builtins.input", side_effect=["", "a"]),
+ ... patch.object(git, "run", side_effect=[refused, refused]),
+ ... patch.dict(continue_maybe.__globals__, original_head="master"),
+ ... redirect_stdout(StringIO()),
+ ... ):
+ ... try:
+ ... continue_maybe("Push anyway?", cherry=True)
+ ... exited = False
+ ... except SystemExit:
+ ... exited = True
+ >>> exited
+ True
+ """
if get_input(f"{prompt} (y/N): ", ["y", "n", ""]) != "y":
if cherry:
- try:
- git.run("git cherry-pick --abort")
- except Exception:
- print_error("Unable to abort and get back to the state before
cherry-pick")
+ if _cherry_pick_in_progress():
+ try:
+ git.run("git cherry-pick --abort")
+ except Exception:
+ print_error("Unable to abort and get back to the state
before cherry-pick")
+ else:
+ _restore_original_head()
print("Skipping this cherry-pick; the merge continues.")
clean_up()
raise SkipCherryPick()
fail("Okay, exiting")
+def _cherry_pick_in_progress() -> bool:
+ """True if the repo is mid-cherry-pick. With --quiet, exit 1 is git's "no
such ref" answer,
+ i.e. no pick in progress. Any other trouble answers "yes", so the caller
still attempts
+ the abort, as if a pick were in progress.
+
+ >>> from unittest.mock import patch
+ >>> answers = []
+ >>> for failure in (None, subprocess.CalledProcessError(1, "g"),
+ ... subprocess.CalledProcessError(128, "g"), OSError("no
git")):
+ ... with patch.object(git, "run", side_effect=failure):
+ ... answers.append(_cherry_pick_in_progress())
+ >>> answers
+ [True, False, True, True]
+ """
+ try:
+ git.run(["git", "rev-parse", "--verify", "--quiet",
"CHERRY_PICK_HEAD"])
+ return True
+ except subprocess.CalledProcessError as e:
+ return e.returncode != 1
+ except Exception:
+ return True
+
+
+def _restore_original_head():
+ """Check out original_head, waiting for the committer while git refuses
over local edits.
+
+ The committed pick is discarded by clean_up() afterwards; the edits are
theirs to keep, and
+ any git carries over to original_head are listed."""
+ if "original_head" not in globals():
+ return
+ while True:
+ try:
+ carried = git.run(["git", "checkout", original_head]).strip()
Review Comment:
Fixed by merging #60471 (75b224294b0), which already had this: the restore
runs `git checkout --quiet` and lists carried edits from `git status
--porcelain --untracked-files=no`.
---
<sub>馃 Posted by an AI agent (Claude Code 路 skill `none`) on behalf of
@holdenk.</sub>
<!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk
-->
##########
dev/merge_spark_pr.py:
##########
@@ -3518,56 +5071,83 @@ def main():
print("title\t%s\nsource\t%s\ntarget\t%s\nurl\t%s" % (title, pr_repo_desc,
target_ref, url))
continue_maybe("Proceed with merging pull request #%s?" % pr_num)
- merged_refs = [target_ref]
-
merge_hash = merge_pr(pr_num, target_ref, title, body, pr_repo_desc,
pr_author, co_authors)
- # Ordered (branch, commit_hash) pairs for the merge comment: the merge
sink first,
- # then each cherry-pick target as it is picked.
- merged_commits = [(target_ref, merge_hash)]
-
- # merged_refs drives both the next prompt default and the already_picked
set passed to
- # cherry_pick, so each grows with every cherry-pick -- including branches
consumed by the
- # Upstream-First two-branch path inside cherry_pick (e.g. picking
branch-M.x + branch-M.N
- # in a single prompt). It starts with target_ref, the merge sink, never to
be re-picked.
+ # target_ref, the merge sink, is never to be re-picked. A merged backport
PR also inherits
+ # the original's branches, so [p] does not force-push over its other open
backport PRs.
Review Comment:
Fixed in 927971fa8c5. The comment now says the seeding keeps those branches
out of the default, and that `[p]` on a typed pending branch updates its PR.
---
<sub>馃 Posted by an AI agent (Claude Code 路 skill `none`) on behalf of
@holdenk.</sub>
<!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk
-->
##########
dev/merge_spark_pr.py:
##########
@@ -3438,43 +4992,42 @@ def main():
if merge_hash is not None:
# The change is already on target_ref and on any branch a previous run
backported it
# to, so exclude all of them: defaulting to one would cherry-pick an
empty commit.
- picked_refs = [target_ref] + [
- b for b in branches_with_merge_footer(pr_num, branch_names) if b
!= target_ref
- ]
- if len(picked_refs) > 1:
- print("Already backported to: %s" % ", ".join(picked_refs[1:]))
+ # For a merged backport PR, "it" is the original PR, whose footer the
commit carries
+ # and whose number _land_via_fork names its branches after.
+ picks = _seed_picks(merge_footer_pr(message) or pr_num, target_ref,
branch_names)
# Loop so one invocation can reach several maintenance branches, as
the merge path does.
- picked_commits = []
try:
while True:
- default = default_pick_branch(branch_names, tuple(picked_refs))
+ default = default_pick_branch(branch_names, picks.seen())
Review Comment:
Fixed in 927971fa8c5: `default_pick_branch`'s docstring describes
`already_picked` as the branches kept out of the default, landed or with an
open backport PR. Both loops now print 'Every release branch has #N or a
backport PR of it; nothing to pick.'
---
<sub>馃 Posted by an AI agent (Claude Code 路 skill `none`) on behalf of
@holdenk.</sub>
<!-- agent-attribution v1: agent=claude-code; skill=none; operator=holdenk
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]