Skip to content

Commit 21812c5

Browse files
Merge pull request #6 from kirawrath/CM-37347-add-exclude-list
CM-37347 - Add option --add-to-exclude-list
2 parents f499b5d + 050d1e5 commit 21812c5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

bin/git-bc-show-eligible

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import argparse
88
import pygit2
99
import sys
1010
import re
11+
import typing
12+
import os
13+
14+
EXCLUDES_PATH = os.path.join(os.path.expanduser("~"), '.excludes_show_eligible')
1115

1216
def find_toplevel():
1317
try:
@@ -51,6 +55,21 @@ def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
5155
if since_commit and commit.id == since_commit.id:
5256
break
5357

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+
5473
def main():
5574
parser = argparse.ArgumentParser(description='Show commits, eligible for cherry-picking')
5675
parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against',
@@ -59,8 +78,11 @@ def main():
5978
default='HEAD', nargs='?')
6079
parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit')
6180
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}".')
6283

6384
top = find_toplevel()
85+
excludes = read_excludes()
6486

6587
if not top:
6688
print('The current folder is not a valid git repository')
@@ -69,6 +91,9 @@ def main():
6991
args = parser.parse_args()
7092
repo = pygit2.Repository(top)
7193

94+
if args.add_to_exclude_list:
95+
add_exclude_hash(excludes, args.add_to_exclude_list)
96+
7297
try:
7398
from_commit = repo.revparse_single(args.branch)
7499
except:
@@ -129,6 +154,9 @@ def main():
129154
child_commits = group[1:-1]
130155
last_child_commit = group[-1] if len(group) > 1 else ''
131156

157+
if [e for e in excludes if e in merge]:
158+
continue
159+
132160
print(merge)
133161

134162
for child in child_commits:

0 commit comments

Comments
 (0)