Improve performance on pre-commit -r pyflakes by 40%

This commit is contained in:
Anthony Sottile
2014-03-13 23:48:17 -07:00
parent 356e4ba13b
commit da8c435e9c
3 changed files with 59 additions and 5 deletions

View File

@@ -1,14 +1,16 @@
import os
import pkg_resources
from plumbum import local
from pre_commit.util import memoize_by_cwd
# TODO: optimization: memoize based on local.cwd.getpath()
@memoize_by_cwd
def get_root():
return local['git']['rev-parse', '--show-toplevel']().strip()
@memoize_by_cwd
def get_pre_commit_path():
return os.path.join(get_root(), '.git/hooks/pre-commit')
@@ -25,4 +27,4 @@ def remove_pre_commit():
def get_head_sha(git_repo_path):
with local.cwd(git_repo_path):
return (local['git']['rev-parse', 'HEAD'])().strip()
return (local['git']['rev-parse', 'HEAD'])().strip()