1
- #!/usr/bin/env python
1
+ #!/usr/bin/env python3
2
2
# coding=utf-8
3
3
4
4
from __future__ import unicode_literals
@@ -8,6 +8,14 @@ import argparse
8
8
import pygit2
9
9
import sys
10
10
import re
11
+ import typing
12
+ import os
13
+
14
+ EXCLUDES_PATHS = [
15
+ os .path .join (os .path .expanduser ("~" ), '.excludes_show_eligible' ),
16
+ os .path .join (os .path .expanduser ("~" ), '.excludes_show_eligible_manuals' ),
17
+ ]
18
+
11
19
12
20
def find_toplevel ():
13
21
try :
@@ -18,6 +26,7 @@ def find_toplevel():
18
26
except subprocess .CalledProcessError :
19
27
return None
20
28
29
+
21
30
def find_unpicked (repo , from_commit , to_commit , since_commit , show_all ):
22
31
base_id = repo .merge_base (from_commit .id , to_commit .id )
23
32
@@ -51,6 +60,27 @@ def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
51
60
if since_commit and commit .id == since_commit .id :
52
61
break
53
62
63
+
64
+ def read_excludes () -> typing .List [str ]:
65
+ excludes = []
66
+ for file in EXCLUDES_PATHS :
67
+ if not os .path .isfile (file ):
68
+ continue
69
+ with open (file , 'r' ) as f :
70
+ excludes .extend (f .read ().splitlines ())
71
+ return excludes
72
+
73
+
74
+ def add_exclude_hash (excludes : typing .List [str ], commit : str ) -> None :
75
+ if commit in excludes :
76
+ print (f'Commit { commit } already in some exclude list ({ EXCLUDES_PATHS } ).' )
77
+ sys .exit (1 )
78
+ with open (EXCLUDES_PATHS [0 ], 'at' ) as f :
79
+ f .write (commit + '\n ' )
80
+ print (f'Hash { commit } added successfully to { EXCLUDES_PATHS [0 ]} .' )
81
+ exit (0 )
82
+
83
+
54
84
def main ():
55
85
parser = argparse .ArgumentParser (description = 'Show commits, eligible for cherry-picking' )
56
86
parser .add_argument ('branch' , metavar = 'BRANCH' , help = 'Name for the branch to check against' ,
@@ -59,8 +89,11 @@ def main():
59
89
default = 'HEAD' , nargs = '?' )
60
90
parser .add_argument ('--since' , metavar = 'COMMIT' , help = 'Start checking since specified commit' )
61
91
parser .add_argument ('--all' , action = 'store_true' , help = 'Show commits from all users' )
92
+ parser .add_argument ('--add-to-exclude-list' , metavar = 'COMMIT' , help = 'Add a merge commit hash so it, '
93
+ f'and its children, no longer are displayed in the output. This is saved in "{ EXCLUDES_PATHS [0 ]} ".' )
62
94
63
95
top = find_toplevel ()
96
+ excludes = read_excludes ()
64
97
65
98
if not top :
66
99
print ('The current folder is not a valid git repository' )
@@ -69,6 +102,9 @@ def main():
69
102
args = parser .parse_args ()
70
103
repo = pygit2 .Repository (top )
71
104
105
+ if args .add_to_exclude_list :
106
+ add_exclude_hash (excludes , args .add_to_exclude_list )
107
+
72
108
try :
73
109
from_commit = repo .revparse_single (args .branch )
74
110
except :
@@ -129,6 +165,9 @@ def main():
129
165
child_commits = group [1 :- 1 ]
130
166
last_child_commit = group [- 1 ] if len (group ) > 1 else ''
131
167
168
+ if [e for e in excludes if e in merge ]:
169
+ continue
170
+
132
171
print (merge )
133
172
134
173
for child in child_commits :
@@ -139,4 +178,4 @@ def main():
139
178
140
179
141
180
if __name__ == '__main__' :
142
- main ()
181
+ main ()
0 commit comments