Skip to content

Commit d6c7fc8

Browse files
Support for multiple exclude files
1 parent 71030fb commit d6c7fc8

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

bin/git-bc-show-eligible

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import re
1111
import typing
1212
import os
1313

14-
EXCLUDES_PATH = os.path.join(os.path.expanduser("~"), '.excludes_show_eligible')
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+
1519

1620
def find_toplevel():
1721
try:
@@ -22,6 +26,7 @@ def find_toplevel():
2226
except subprocess.CalledProcessError:
2327
return None
2428

29+
2530
def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
2631
base_id = repo.merge_base(from_commit.id, to_commit.id)
2732

@@ -55,21 +60,27 @@ def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
5560
if since_commit and commit.id == since_commit.id:
5661
break
5762

63+
5864
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()
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+
6373

6474
def add_exclude_hash(excludes: typing.List[str], commit: str) -> None:
6575
if commit in excludes:
66-
print(f'Commit {commit} already in the exclude list ({EXCLUDES_PATH}).')
76+
print(f'Commit {commit} already in some exclude list ({EXCLUDES_PATHS}).')
6777
sys.exit(1)
68-
with open(EXCLUDES_PATH, 'at') as f:
78+
with open(EXCLUDES_PATHS[0], 'at') as f:
6979
f.write(commit + '\n')
70-
print(f'Hash {commit} added successfully.')
80+
print(f'Hash {commit} added successfully to {EXCLUDES_PATHS[0]}.')
7181
exit(0)
7282

83+
7384
def main():
7485
parser = argparse.ArgumentParser(description='Show commits, eligible for cherry-picking')
7586
parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against',
@@ -79,7 +90,7 @@ def main():
7990
parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit')
8091
parser.add_argument('--all', action='store_true', help='Show commits from all users')
8192
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}".')
93+
f'and its children, no longer are displayed in the output. This is saved in "{EXCLUDES_PATHS[0]}".')
8394

8495
top = find_toplevel()
8596
excludes = read_excludes()
@@ -167,4 +178,4 @@ def main():
167178

168179

169180
if __name__ == '__main__':
170-
main()
181+
main()

0 commit comments

Comments
 (0)