From ab5918e6d962e2df945fcd0f2a2ba3e27ec8d18e Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Mon, 17 Sep 2018 10:11:03 +0200 Subject: Optimize. Different types of modification for -m and for pyflake8 --- pygitchecker.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'pygitchecker.py') diff --git a/pygitchecker.py b/pygitchecker.py index d826084..111610d 100755 --- a/pygitchecker.py +++ b/pygitchecker.py @@ -9,6 +9,15 @@ import pygit2 from flake8.api import legacy as flake8_legacy +MODIFIED_STATUSES = (pygit2.GIT_STATUS_WT_MODIFIED, + pygit2.GIT_STATUS_INDEX_NEW, + pygit2.GIT_STATUS_INDEX_MODIFIED) +MODIFIED_STATUSES_FULL = (pygit2.GIT_STATUS_WT_MODIFIED, + pygit2.GIT_STATUS_WT_NEW, + pygit2.GIT_STATUS_INDEX_NEW, + pygit2.GIT_STATUS_INDEX_MODIFIED) + + def is_git_repo(abspath): """ True of abspath points to a git repo, False otherwise @@ -32,12 +41,7 @@ def modifications_exist(abspath): repo = pygit2.Repository(abspath) status = repo.status() for gfile, state in status.items(): - if ( - state in (pygit2.GIT_STATUS_WT_MODIFIED, - pygit2.GIT_STATUS_WT_NEW, - pygit2.GIT_STATUS_INDEX_NEW, - pygit2.GIT_STATUS_INDEX_MODIFIED) - ): + if state in MODIFIED_STATUSES_FULL: return True return False @@ -89,13 +93,7 @@ def fetch_git_files(args): if not status: return git_files_list for gfile, state in status.items(): - if ( - state in (pygit2.GIT_STATUS_WT_MODIFIED, - pygit2.GIT_STATUS_WT_NEW, - pygit2.GIT_STATUS_INDEX_NEW, - pygit2.GIT_STATUS_INDEX_MODIFIED) and - gfile.lower().endswith('.py') - ): + if state in MODIFIED_STATUSES and gfile.lower().endswith('.py'): if args.verbose: print(gfile) git_files_list.append(gfile) -- cgit v1.3