holdenk commented on code in PR #60472:
URL: https://github.com/apache/spark/pull/60472#discussion_r4621001940


##########
dev/merge_spark_pr.py:
##########
@@ -4177,56 +5305,53 @@ def record(pair):
     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.
-    def record(pair):
-        merged_refs.append(pair[0])
-        merged_commits.append(pair)
-
+    # target_ref, the merge sink, is never to be re-picked.
+    picks = _PickLedger([target_ref])
     pick_prompt = "Would you like to pick %s into another branch?" % merge_hash
     # Always record the merge summary for what actually landed, even if a later
     # cherry-pick is aborted or cancelled: the merge into the target branch has
     # already been pushed, so cancelling a backport must not drop that line.
     try:
+        # Seeded inside the try: the fork lookups can stall, and the merge is 
already pushed.
+        # A merged backport PR inherits the original's branches: the default 
skips them, and
+        # [p] on a typed pending one updates its PR.
+        if backport:
+            picks = _seed_picks(backport[0], target_ref, branch_names)
         while get_input(f"\n{pick_prompt} (y/N): ", ["y", "n", ""]) == "y":
-            default = default_pick_branch(branch_names, tuple(merged_refs))
+            default = default_pick_branch(branch_names, picks.seen())
             if default is None:
-                print("Every known release branch already contains #%s; 
nothing to pick." % pr_num)
+                print(
+                    "Every release branch has #%s or a backport PR of it; 
nothing to pick." % pr_num
+                )
                 break
             cherry_pick(
                 pr_num,
                 merge_hash,
                 default,
                 branch_names,
                 target_ref,
-                already_picked=tuple(merged_refs),
-                record=record,
+                already_picked=tuple(picks.landed),
+                title=title,
+                pending=picks.pending,
+                record=lambda pair: picks.record([pair]),
             )
     finally:
-        if merged_commits:
-            # The "Closes #N" keyword in the commit message only auto-closes 
the PR when the
-            # commit lands on the default branch. For merges into other 
branches (e.g.
-            # branch-X.Y backport PRs), GitHub leaves the PR open, so close it 
through the API.
-            pr_state = get_json("%s/pulls/%s" % (GITHUB_API_BASE, 
pr_num)).get("state")
-            if pr_state != "closed":
-                close_message = "PR #%s is still open after push; closing it 
explicitly." % pr_num
-                print("\n%s\n" % bold(close_message))
-                github.close_pr(pr_num)
-            # Record every branch that successfully received the change on the 
PR.
-            post_merge_comment(pr_num, merged_commits)
+        # The "Closes #N" keyword in the commit message only auto-closes the 
PR when the
+        # commit lands on the default branch. For merges into other branches 
(e.g.
+        # branch-X.Y backport PRs), GitHub leaves the PR open, so close it 
through the API.
+        pr_state = get_json("%s/pulls/%s" % (GITHUB_API_BASE, 
pr_num)).get("state")
+        if pr_state != "closed":
+            close_message = "PR #%s is still open after push; closing it 
explicitly." % pr_num
+            print("\n%s\n" % bold(close_message))
+            github.close_pr(pr_num)
+        # Record every branch that received the change, or has a backport PR, 
on the PR:
+        # the merge sink first, then each cherry-pick as it was picked.
+        post_merge_comment(pr_num, [(target_ref, merge_hash)] + picks.commits)

Review Comment:
   Sure seems like a good improvement



-- 
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]

Reply via email to