Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple exclude files #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions bin/git-bc-show-eligible
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import re
import typing
import os

EXCLUDES_PATH = os.path.join(os.path.expanduser("~"), '.excludes_show_eligible')
EXCLUDES_PATHS = [
os.path.join(os.path.expanduser("~"), '.excludes_show_eligible'),
os.path.join(os.path.expanduser("~"), '.excludes_show_eligible_manuals'),
]

def find_toplevel():
try:
Expand All @@ -22,6 +25,7 @@ def find_toplevel():
except subprocess.CalledProcessError:
return None


def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
base_id = repo.merge_base(from_commit.id, to_commit.id)

Expand Down Expand Up @@ -55,21 +59,27 @@ def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
if since_commit and commit.id == since_commit.id:
break


def read_excludes() -> typing.List[str]:
if not os.path.isfile(EXCLUDES_PATH):
return []
with open(EXCLUDES_PATH, 'r') as f:
return f.read().splitlines()
excludes = []
for file in EXCLUDES_PATHS:
if not os.path.isfile(file):
continue
with open(file, 'r') as f:
excludes.extend(f.read().splitlines())
return excludes


def add_exclude_hash(excludes: typing.List[str], commit: str) -> None:
if commit in excludes:
print(f'Commit {commit} already in the exclude list ({EXCLUDES_PATH}).')
print(f'Commit {commit} already in some exclude list ({EXCLUDES_PATHS}).')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(f'Commit {commit} already in some exclude list ({EXCLUDES_PATHS}).')
print(f'Commit {commit} already in one of exclude lists in ({EXCLUDES_PATHS}).')

sys.exit(1)
with open(EXCLUDES_PATH, 'at') as f:
with open(EXCLUDES_PATHS[0], 'at') as f:
f.write(commit + '\n')
print(f'Hash {commit} added successfully.')
print(f'Hash {commit} added successfully to {EXCLUDES_PATHS[0]}.')
exit(0)


def main():
parser = argparse.ArgumentParser(description='Show commits, eligible for cherry-picking')
parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against',
Expand All @@ -79,7 +89,7 @@ def main():
parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit')
parser.add_argument('--all', action='store_true', help='Show commits from all users')
parser.add_argument('--add-to-exclude-list', metavar='COMMIT', help='Add a merge commit hash so it, '
f'and its children, no longer are displayed in the output. This is saved in "{EXCLUDES_PATH}".')
f'and its children, no longer are displayed in the output. This is saved in "{EXCLUDES_PATHS[0]}".')

top = find_toplevel()
excludes = read_excludes()
Expand Down Expand Up @@ -167,4 +177,4 @@ def main():


if __name__ == '__main__':
main()
main()