diff options
| author | Simeon Simeonov | 2018-09-17 10:11:03 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2018-09-17 10:11:03 +0200 |
| commit | ab5918e6d962e2df945fcd0f2a2ba3e27ec8d18e (patch) | |
| tree | 7543123202408635f1183963e21dc8a74105a6c9 | |
| parent | 7c0dde7dca016177ba05c04632a470a06f1daccd (diff) | |
Optimize. Different types of modification for -m and for pyflake8
| -rwxr-xr-x | pygitchecker.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/pygitchecker.py b/pygitchecker.py index d826084..111610d 100755 --- a/pygitchecker.py +++ b/pygitchecker.py | |||
| @@ -9,6 +9,15 @@ import pygit2 | |||
| 9 | from flake8.api import legacy as flake8_legacy | 9 | from flake8.api import legacy as flake8_legacy |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | MODIFIED_STATUSES = (pygit2.GIT_STATUS_WT_MODIFIED, | ||
| 13 | pygit2.GIT_STATUS_INDEX_NEW, | ||
| 14 | pygit2.GIT_STATUS_INDEX_MODIFIED) | ||
| 15 | MODIFIED_STATUSES_FULL = (pygit2.GIT_STATUS_WT_MODIFIED, | ||
| 16 | pygit2.GIT_STATUS_WT_NEW, | ||
| 17 | pygit2.GIT_STATUS_INDEX_NEW, | ||
| 18 | pygit2.GIT_STATUS_INDEX_MODIFIED) | ||
| 19 | |||
| 20 | |||
| 12 | def is_git_repo(abspath): | 21 | def is_git_repo(abspath): |
| 13 | """ | 22 | """ |
| 14 | True of abspath points to a git repo, False otherwise | 23 | True of abspath points to a git repo, False otherwise |
| @@ -32,12 +41,7 @@ def modifications_exist(abspath): | |||
| 32 | repo = pygit2.Repository(abspath) | 41 | repo = pygit2.Repository(abspath) |
| 33 | status = repo.status() | 42 | status = repo.status() |
| 34 | for gfile, state in status.items(): | 43 | for gfile, state in status.items(): |
| 35 | if ( | 44 | if state in MODIFIED_STATUSES_FULL: |
| 36 | state in (pygit2.GIT_STATUS_WT_MODIFIED, | ||
| 37 | pygit2.GIT_STATUS_WT_NEW, | ||
| 38 | pygit2.GIT_STATUS_INDEX_NEW, | ||
| 39 | pygit2.GIT_STATUS_INDEX_MODIFIED) | ||
| 40 | ): | ||
| 41 | return True | 45 | return True |
| 42 | return False | 46 | return False |
| 43 | 47 | ||
| @@ -89,13 +93,7 @@ def fetch_git_files(args): | |||
| 89 | if not status: | 93 | if not status: |
| 90 | return git_files_list | 94 | return git_files_list |
| 91 | for gfile, state in status.items(): | 95 | for gfile, state in status.items(): |
| 92 | if ( | 96 | if state in MODIFIED_STATUSES and gfile.lower().endswith('.py'): |
| 93 | state in (pygit2.GIT_STATUS_WT_MODIFIED, | ||
| 94 | pygit2.GIT_STATUS_WT_NEW, | ||
| 95 | pygit2.GIT_STATUS_INDEX_NEW, | ||
| 96 | pygit2.GIT_STATUS_INDEX_MODIFIED) and | ||
| 97 | gfile.lower().endswith('.py') | ||
| 98 | ): | ||
| 99 | if args.verbose: | 97 | if args.verbose: |
| 100 | print(gfile) | 98 | print(gfile) |
| 101 | git_files_list.append(gfile) | 99 | git_files_list.append(gfile) |
