viirya commented on code in PR #56058:
URL: https://github.com/apache/spark/pull/56058#discussion_r3289107894


##########
dev/merge_spark_pr.py:
##########
@@ -506,6 +503,69 @@ def cherry_pick(pr_num, merge_hash, default_branch):
     return pick_ref
 
 
+def cherry_pick(pr_num, merge_hash, default_branch, branch_names, 
already_picked=()):
+    """Prompt for a target branch and cherry-pick `merge_hash` onto it.
+
+    Enforces the Upstream-First policy (see header comment): when the 
committer types a
+    branch-M.N target while branch-M.x is also a known release branch AND has 
not already
+    received this commit, prompt to confirm whether to pick into BOTH (the 
policy-compliant
+    default) or branch-M.N only (treated as a maintenance-only bugfix). 
Returns the list of
+    refs actually picked into, so the main loop can advance its 
remaining-branches list
+    correctly.
+    """
+    pick_ref = bold_input("Enter a branch name [%s]: " % default_branch)
+    if pick_ref == "":
+        pick_ref = default_branch
+
+    # Upstream-First check: if the committer typed branch-M.N and branch-M.x 
exists as a
+    # sibling release branch that has not yet received this commit, surface 
the policy and
+    # offer to pick both in one step. Skipping when sibling_x is the merge 
target or already
+    # in already_picked avoids a redundant prompt / failing re-cherry-pick.
+    sibling_x = None
+    m = re.match(r"^branch-(\d+)\.(\d+)$", pick_ref)
+    if m:
+        candidate = "branch-%s.x" % m.group(1)
+        if (
+            candidate in branch_names
+            and candidate != pick_ref
+            and candidate not in already_picked
+        ):
+            sibling_x = candidate
+
+    if sibling_x is not None:
+        print()
+        print("=" * 76)
+        print(
+            "Upstream-First policy: non-bugfix commits on %s should also land 
on %s."
+            % (pick_ref, sibling_x)
+        )
+        print("If this is a %s-only maintenance bugfix, you may pick %s alone."
+              % (pick_ref, pick_ref))
+        print("Otherwise, pick both (%s first, then %s)." % (sibling_x, 
pick_ref))
+        print("=" * 76)
+        choice = (
+            bold_input(
+                "Pick into [b]oth %s + %s / [o]nly %s / [a]bort (default: 
both): "
+                % (sibling_x, pick_ref, pick_ref)
+            )
+            .strip()
+            .lower()
+        )
+        if choice in ("", "b", "both"):
+            picked_x = _do_cherry_pick(pr_num, merge_hash, sibling_x)
+            picked_n = _do_cherry_pick(pr_num, merge_hash, pick_ref)
+            return [picked_x, picked_n]
+        elif choice in ("o", "only"):
+            return [_do_cherry_pick(pr_num, merge_hash, pick_ref)]
+        elif choice in ("a", "abort"):
+            clean_up()
+            fail("Aborted by user at Upstream-First policy prompt.")

Review Comment:
   Fixed — dropped the explicit `clean_up()` so the abort branch matches the 
`else: fail(...)` branch below. Both now rely on `fail()`'s own `clean_up()` 
call, no more double "Restoring head pointer to ..." print.



##########
dev/merge_spark_pr.py:
##########
@@ -506,6 +503,69 @@ def cherry_pick(pr_num, merge_hash, default_branch):
     return pick_ref
 
 
+def cherry_pick(pr_num, merge_hash, default_branch, branch_names, 
already_picked=()):
+    """Prompt for a target branch and cherry-pick `merge_hash` onto it.
+
+    Enforces the Upstream-First policy (see header comment): when the 
committer types a
+    branch-M.N target while branch-M.x is also a known release branch AND has 
not already
+    received this commit, prompt to confirm whether to pick into BOTH (the 
policy-compliant
+    default) or branch-M.N only (treated as a maintenance-only bugfix). 
Returns the list of
+    refs actually picked into, so the main loop can advance its 
remaining-branches list
+    correctly.
+    """
+    pick_ref = bold_input("Enter a branch name [%s]: " % default_branch)
+    if pick_ref == "":
+        pick_ref = default_branch
+
+    # Upstream-First check: if the committer typed branch-M.N and branch-M.x 
exists as a
+    # sibling release branch that has not yet received this commit, surface 
the policy and
+    # offer to pick both in one step. Skipping when sibling_x is the merge 
target or already
+    # in already_picked avoids a redundant prompt / failing re-cherry-pick.
+    sibling_x = None
+    m = re.match(r"^branch-(\d+)\.(\d+)$", pick_ref)
+    if m:
+        candidate = "branch-%s.x" % m.group(1)
+        if (
+            candidate in branch_names
+            and candidate != pick_ref
+            and candidate not in already_picked
+        ):
+            sibling_x = candidate
+
+    if sibling_x is not None:
+        print()
+        print("=" * 76)

Review Comment:
   Aligned both dividers to `"=" * 80` for consistency with the rest of the 
file.



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