Skip to content

Commit d9fcd77

Browse files
authored
Add method to analyze reverts: analyze_reverts_missing_from_branch (#6834)
Usage: ``` python github_analyze.py --analyze-missing-reverts-from-branch --repo-path ~/local/pytorch --remote upstream --branch release/2.8 Analyzing reverts in main branch not present in release/2.8 branch Total commits in main but not in release/2.8: 62 Total commits in release/2.8 but not in main: 1 Found 8 revert(s) in main branch not present in release/2.8 branch: ================================================================================ Commit Hash: 029e2b05c225588098d3eba445fd04189691f77d Author: PyTorch MergeBot <[email protected]> Date: 2025-06-25 06:05:40 Title: Revert "[Quant][CPU] fix fake_quantize_per_tensor_affine of inf values (#155109)" Reverted GitHub Commit: 19ffb5e6f7606436249742b0f3efc0bab244dc55 Body Preview: This reverts commit 19ffb5e6f7606436249742b0f3efc0bab244dc55. Reverted pytorch/pytorch#155109 on behalf of https://github.com/albanD due to The corresponding ... -------------------------------------------------------------------------------- Commit Hash: 3dd872e6d53560933d8d7fc11357617746d37168 Author: PyTorch MergeBot <[email protected]> Date: 2025-06-24 17:11:35 Title: Revert "Add DeviceAllocator as the base device allocator (#138222)" Reverted GitHub Commit: 92409b6c89fbfbd3caa79c81b1e3d9e7917d3bc7 Body Preview: This reverts commit 92409b6c89fbfbd3caa79c81b1e3d9e7917d3bc7. Reverted pytorch/pytorch#138222 on behalf of https://github.com/Camyll due to internal build fai... -------------------------------------------------------------------------------- Commit Hash: 6459a5c7a92e7a38db374780b91116cc958b6af9 Author: PyTorch MergeBot <[email protected]> Date: 2025-06-24 17:11:35 Title: Revert "Add unified memory APIs for torch.accelerator (#152932)" Reverted GitHub Commit: 35e44067c4d9cc9be2652c0b9098885c5a321029 Body Preview: This reverts commit 35e44067c4d9cc9be2652c0b9098885c5a321029. Reverted pytorch/pytorch#152932 on behalf of https://github.com/Camyll due to internal build fai... -------------------------------------------------------------------------------- Commit Hash: fd4bb29410c035b31ca55262c3012cadb1194aae Author: PyTorch MergeBot <[email protected]> Date: 2025-06-24 16:45:13 Title: Revert "[logging] dynamo_timed for CachingAutotuner.coordinate_descent_tuning (#156517)" Reverted GitHub Commit: fb75dea2c1b93c78dccf08d5fd5e20b362ecd405 Body Preview: This reverts commit fb75dea2c1b93c78dccf08d5fd5e20b362ecd405. Reverted pytorch/pytorch#156517 on behalf of https://github.com/Camyll due to internal reverted ... -------------------------------------------------------------------------------- Commit Hash: 4bd18e31e5a38d0e84ce915b1fa124058c6373fa Author: PyTorch MergeBot <[email protected]> Date: 2025-06-24 16:34:21 Title: Revert "Add fx_graph_runnable tests boilerplate (#156552)" Reverted GitHub Commit: 0a2ec7681d2af973d8daaf7905431a088739dc90 Body Preview: This reverts commit 0a2ec7681d2af973d8daaf7905431a088739dc90. Reverted pytorch/pytorch#156552 on behalf of https://github.com/Camyll due to breaking internal ... -------------------------------------------------------------------------------- Commit Hash: 1dc1eedd4369f6e6bb79d5315e3ffc1bdc59b709 Author: PyTorch MergeBot <[email protected]> Date: 2025-06-24 13:44:42 Title: Revert "[dynamo] Graph break on `torch.Tensor.data` assignment with mismatched dtype (#156623)" Reverted GitHub Commit: c1ad4b8e7a16f54c35a3908b56ed7d9f95eef586 Body Preview: This reverts commit c1ad4b8e7a16f54c35a3908b56ed7d9f95eef586. Reverted pytorch/pytorch#156623 on behalf of https://github.com/albanD due to Breaks Dynamo test... -------------------------------------------------------------------------------- Commit Hash: aa280ea19fb20923d048909fa98af092e18ca2fb Author: PyTorch MergeBot <[email protected]> Date: 2025-06-24 13:05:39 Title: Revert "Remove remaining CUDA 12.4 CI code (#155412)" Reverted GitHub Commit: 9fed2addedb42da86b657165fe14eadc911232cf Body Preview: This reverts commit 9fed2addedb42da86b657165fe14eadc911232cf. Reverted pytorch/pytorch#155412 on behalf of https://github.com/Camyll due to cuda 12.4 still ne... -------------------------------------------------------------------------------- Commit Hash: 19f851ce10b16f0ed11d18d937ca7b32746153b0 Author: PyTorch MergeBot <[email protected]> Date: 2025-06-24 13:02:07 Title: Revert "Simplify nvtx3 CMake handling, always use nvtx3 (#153784)" Reverted GitHub Commit: 099d0d6121125062ebc05771c8330cb7cd8d053a Body Preview: This reverts commit 099d0d6121125062ebc05771c8330cb7cd8d053a. Reverted pytorch/pytorch#153784 on behalf of https://github.com/Camyll due to breaking internal ... -------------------------------------------------------------------------------- ```
1 parent 4d667b7 commit d9fcd77

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

tools/analytics/github_analyze.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import enum
66
import json
77
import os
8+
import re
89
from datetime import datetime, timedelta
910
from typing import Any, Dict, Iterable, List, Optional, Union
1011
from urllib.error import HTTPError
@@ -542,6 +543,106 @@ def analyze_stacks(repo: GitRepo) -> None:
542543
)
543544

544545

546+
def extract_commit_hash_from_revert(text):
547+
"""
548+
Extract commit hash from a revert commit message.
549+
550+
Args:
551+
text (str): The revert commit message
552+
553+
Returns:
554+
str or None: The extracted commit hash, or None if not found
555+
"""
556+
# Pattern to match "This reverts commit <hash>."
557+
pattern = r"This reverts commit ([0-9a-f]+)\."
558+
559+
match = re.search(pattern, text)
560+
if match:
561+
return match.group(1)
562+
return None
563+
564+
565+
def analyze_reverts_missing_from_branch(repo: GitRepo, branch: str) -> None:
566+
"""
567+
Analyze reverts applied to main branch but not applied to specified branch.
568+
This identifies potential missing revert commits that may need to be cherry-picked
569+
to the release branch. Also detects if reverted commits from main were cherry-picked
570+
to the branch.
571+
"""
572+
# Get commits from main that are not in the specified branch
573+
main_only_commits = build_commit_dict(repo.get_commit_list(branch, "main"))
574+
575+
# Get commits from the specified branch that are not in main
576+
branch_only_commits = build_commit_dict(repo.get_commit_list("main", branch))
577+
branch_only_reverts = set()
578+
579+
print(f"Analyzing reverts in main branch not present in {branch} branch")
580+
print(f"Total commits in main but not in {branch}: {len(main_only_commits)}")
581+
print(f"Total commits in {branch} but not in main: {len(branch_only_commits)}")
582+
print()
583+
584+
for commit_hash, commit in branch_only_commits.items():
585+
revert_hash = extract_commit_hash_from_revert(commit.body)
586+
if revert_hash != None:
587+
branch_only_reverts.add(revert_hash)
588+
if is_revert(commit):
589+
branch_only_reverts.add(commit_hash)
590+
591+
# Find reverts in main that are not in the specified branch
592+
reverts_missing_from_branch = []
593+
594+
for commit_hash, commit in main_only_commits.items():
595+
if is_revert(commit):
596+
reverts_missing_from_branch.append(commit)
597+
598+
if not reverts_missing_from_branch:
599+
print(f"No reverts found in main branch that are missing from {branch} branch.")
600+
return
601+
602+
print(
603+
f"Found {len(reverts_missing_from_branch)} revert(s) in main branch not present in {branch} branch:"
604+
)
605+
print("=" * 80)
606+
607+
for commit in reverts_missing_from_branch:
608+
# Try to identify what was reverted
609+
revert_revision = get_revert_revision(commit)
610+
ghf_revert_revision = get_ghf_revert_revision(commit)
611+
612+
reverted_commit_hash = None
613+
if revert_revision:
614+
print(f"Reverted Phabricator Diff: {revert_revision}")
615+
elif ghf_revert_revision:
616+
print(f"Reverted GitHub Commit: {ghf_revert_revision}")
617+
reverted_commit_hash = ghf_revert_revision
618+
619+
# Check if the reverted commit was cherry-picked to the branch
620+
cherry_picked_to_branch = False
621+
if reverted_commit_hash:
622+
if reverted_commit_hash in branch_only_reverts:
623+
cherry_picked_to_branch = True
624+
print(
625+
f"✅ DETECTED: The reverted commit {reverted_commit_hash} was cherry-picked to {branch}"
626+
)
627+
628+
print(f"Commit Hash: {commit.commit_hash}")
629+
print(f"Author: {commit.author}")
630+
print(f"Date: {commit.commit_date or commit.author_date}")
631+
print(f"Title: {commit.title}")
632+
if commit.pr_url:
633+
print(f"PR URL: {commit.pr_url}")
634+
635+
if not cherry_picked_to_branch:
636+
print(
637+
f"⚠️ STATUS: The reverted commit does not appear to be in {branch}, so this revert may not be needed."
638+
)
639+
640+
print(
641+
f"Body Preview: {commit.body[:200]}{'...' if len(commit.body) > 200 else ''}"
642+
)
643+
print("-" * 80)
644+
645+
545646
def parse_arguments():
546647
from argparse import ArgumentParser
547648

@@ -562,6 +663,11 @@ def parse_arguments():
562663
parser.add_argument("--missing-in-branch", action="store_true")
563664
parser.add_argument("--missing-in-release", action="store_true")
564665
parser.add_argument("--analyze-stacks", action="store_true")
666+
parser.add_argument(
667+
"--analyze-missing-reverts-from-branch",
668+
action="store_true",
669+
help="Analyze reverts applied to main branch but not applied to specified branch",
670+
)
565671
parser.add_argument("--date", type=lambda d: datetime.strptime(d, "%Y-%m-%d"))
566672
parser.add_argument("--issue-num", type=int)
567673
return parser.parse_args()
@@ -586,6 +692,15 @@ def main():
586692
analyze_stacks(repo)
587693
return
588694

695+
if args.analyze_missing_reverts_from_branch:
696+
if not args.branch:
697+
print(
698+
"Error: --branch argument is required for --analyze-missing-reverts-from-branch"
699+
)
700+
return
701+
analyze_reverts_missing_from_branch(repo, args.branch)
702+
return
703+
589704
# Use milestone idx or search it along milestone titles
590705
try:
591706
milestone_idx = int(args.milestone_id)

0 commit comments

Comments
 (0)