Skip to content

Commit 5620ef3

Browse files
Multiple exclude files
1 parent f499b5d commit 5620ef3

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

bin/git-bc-show-eligible

100755100644
Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# coding=utf-8
33

44
from __future__ import unicode_literals
@@ -8,6 +8,14 @@ import argparse
88
import pygit2
99
import sys
1010
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+
1119

1220
def find_toplevel():
1321
try:
@@ -18,6 +26,7 @@ def find_toplevel():
1826
except subprocess.CalledProcessError:
1927
return None
2028

29+
2130
def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
2231
base_id = repo.merge_base(from_commit.id, to_commit.id)
2332

@@ -51,6 +60,27 @@ def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
5160
if since_commit and commit.id == since_commit.id:
5261
break
5362

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+
5484
def main():
5585
parser = argparse.ArgumentParser(description='Show commits, eligible for cherry-picking')
5686
parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against',
@@ -59,8 +89,11 @@ def main():
5989
default='HEAD', nargs='?')
6090
parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit')
6191
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]}".')
6294

6395
top = find_toplevel()
96+
excludes = read_excludes()
6497

6598
if not top:
6699
print('The current folder is not a valid git repository')
@@ -69,6 +102,9 @@ def main():
69102
args = parser.parse_args()
70103
repo = pygit2.Repository(top)
71104

105+
if args.add_to_exclude_list:
106+
add_exclude_hash(excludes, args.add_to_exclude_list)
107+
72108
try:
73109
from_commit = repo.revparse_single(args.branch)
74110
except:
@@ -129,6 +165,9 @@ def main():
129165
child_commits = group[1:-1]
130166
last_child_commit = group[-1] if len(group) > 1 else ''
131167

168+
if [e for e in excludes if e in merge]:
169+
continue
170+
132171
print(merge)
133172

134173
for child in child_commits:
@@ -139,4 +178,4 @@ def main():
139178

140179

141180
if __name__ == '__main__':
142-
main()
181+
main()

0 commit comments

Comments
 (0)