@@ -8,6 +8,10 @@ import argparse
8
8
import pygit2
9
9
import sys
10
10
import re
11
+ import typing
12
+ import os
13
+
14
+ EXCLUDES_PATH = os .path .join (os .path .expanduser ("~" ), '.excludes_show_eligible' )
11
15
12
16
def find_toplevel ():
13
17
try :
@@ -51,6 +55,21 @@ def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
51
55
if since_commit and commit .id == since_commit .id :
52
56
break
53
57
58
+ def read_excludes () -> typing .List [str ]:
59
+ if not os .path .isfile (EXCLUDES_PATH ):
60
+ return []
61
+ with open (EXCLUDES_PATH , 'r' ) as f :
62
+ return f .read ().splitlines ()
63
+
64
+ def add_exclude_hash (excludes : typing .List [str ], commit : str ) -> None :
65
+ if commit in excludes :
66
+ print (f'Commit { commit } already in the exclude list ({ EXCLUDES_PATH } ).' )
67
+ sys .exit (1 )
68
+ with open (EXCLUDES_PATH , 'at' ) as f :
69
+ f .write (commit + '\n ' )
70
+ print (f'Hash { commit } added successfully.' )
71
+ exit (0 )
72
+
54
73
def main ():
55
74
parser = argparse .ArgumentParser (description = 'Show commits, eligible for cherry-picking' )
56
75
parser .add_argument ('branch' , metavar = 'BRANCH' , help = 'Name for the branch to check against' ,
@@ -59,8 +78,11 @@ def main():
59
78
default = 'HEAD' , nargs = '?' )
60
79
parser .add_argument ('--since' , metavar = 'COMMIT' , help = 'Start checking since specified commit' )
61
80
parser .add_argument ('--all' , action = 'store_true' , help = 'Show commits from all users' )
81
+ parser .add_argument ('--add-to-exclude-list' , metavar = 'COMMIT' , help = 'Add a merge commit hash so it, '
82
+ f'and its children, no longer are displayed in the output. This is saved in "{ EXCLUDES_PATH } ".' )
62
83
63
84
top = find_toplevel ()
85
+ excludes = read_excludes ()
64
86
65
87
if not top :
66
88
print ('The current folder is not a valid git repository' )
@@ -69,6 +91,9 @@ def main():
69
91
args = parser .parse_args ()
70
92
repo = pygit2 .Repository (top )
71
93
94
+ if args .add_to_exclude_list :
95
+ add_exclude_hash (excludes , args .add_to_exclude_list )
96
+
72
97
try :
73
98
from_commit = repo .revparse_single (args .branch )
74
99
except :
@@ -129,6 +154,9 @@ def main():
129
154
child_commits = group [1 :- 1 ]
130
155
last_child_commit = group [- 1 ] if len (group ) > 1 else ''
131
156
157
+ if [e for e in excludes if e in merge ]:
158
+ continue
159
+
132
160
print (merge )
133
161
134
162
for child in child_commits :
0 commit comments