@@ -46,6 +46,11 @@ def __contains__(self, item: Any) -> bool:
46
46
47
47
def get_revert_revision (commit : GitCommit ) -> Optional [str ]:
48
48
import re
49
+ body_rc = re .search ("Original Phabricator Diff: (D\\ d+)" , commit .body )
50
+
51
+ if commit .title .startswith ("Back out \" " ) and body_rc is not None :
52
+ return body_rc .group (1 )
53
+
49
54
rc = re .match ("Revert (D\\ d+):" , commit .title )
50
55
if rc is None :
51
56
return None
@@ -60,8 +65,20 @@ def get_diff_revision(commit: GitCommit) -> Optional[str]:
60
65
return rc .group (1 )
61
66
62
67
68
+ def get_ghf_revert_revision (commit : GitCommit ) -> Optional [str ]:
69
+ import re
70
+ rc = re .search ("\\ s*This reverts commit ([0-9a-f]+)." , commit .body )
71
+ if all ([
72
+ commit .title .startswith ("Revert" ),
73
+ commit .
author == "PyTorch MergeBot <[email protected] >" ,
74
+ rc is not None
75
+ ]):
76
+ return rc .group (1 )
77
+ return None
78
+
79
+
63
80
def is_revert (commit : GitCommit ) -> bool :
64
- return get_revert_revision (commit ) is not None
81
+ return get_revert_revision (commit ) is not None or get_ghf_revert_revision ( commit ) is not None
65
82
66
83
67
84
def parse_medium_format (lines : Union [str , List [str ]]) -> GitCommit :
@@ -267,6 +284,13 @@ def print_monthly_stats(commits: List[GitCommit]) -> None:
267
284
print (f"{ y } -{ m :02d} : commits { total } ({ commits_growth :+.1f} %) reverts { reverts } ({ reverts_ratio :.1f} %) authors { authors } " )
268
285
269
286
287
+ def print_reverts (commits : List [GitCommit ]) -> None :
288
+ for commit in commits :
289
+ if not is_revert (commit ):
290
+ continue
291
+ print (f"{ commit .commit_date } { commit .title } { commit .commit_hash } " )
292
+
293
+
270
294
def analyze_reverts (commits : List [GitCommit ]):
271
295
for idx , commit in enumerate (commits ):
272
296
revert_id = get_revert_revision (commit )
@@ -348,6 +372,7 @@ def parse_arguments():
348
372
help = "Remote to base off of" ,
349
373
default = "" )
350
374
parser .add_argument ("--analyze-reverts" , action = "store_true" )
375
+ parser .add_argument ("--print-reverts" , action = "store_true" )
351
376
parser .add_argument ("--contributor-stats" , action = "store_true" )
352
377
parser .add_argument ("--missing-in-branch" , action = "store_true" )
353
378
return parser .parse_args ()
@@ -395,6 +420,8 @@ def main():
395
420
analyze_reverts (x )
396
421
elif args .contributor_stats :
397
422
print_contributor_stats (x )
423
+ elif args .print_reverts :
424
+ print_reverts (x [:2 ** 9 ])
398
425
else :
399
426
print_monthly_stats (x )
400
427
0 commit comments