1818logger = logging .getLogger ('pre_commit' )
1919
2020
21- class HookExecutor (object ):
22- def __init__ (self , hook , invoker ):
23- self .hook = hook
24- self ._invoker = invoker
25-
26- def invoke (self , filenames ):
27- return self ._invoker (self .hook , filenames )
28-
29-
3021def _get_skips (environ ):
3122 skips = environ .get ('SKIP' , '' )
3223 return set (skip .strip () for skip in skips .split (',' ) if skip .strip ())
@@ -80,8 +71,7 @@ def get_filenames(args, include_expr, exclude_expr):
8071 return getter (include_expr , exclude_expr )
8172
8273
83- def _run_single_hook (hook_executor , args , write , skips = frozenset ()):
84- hook = hook_executor .hook
74+ def _run_single_hook (hook , repo , args , write , skips = frozenset ()):
8575 filenames = get_filenames (args , hook ['files' ], hook ['exclude' ])
8676 if hook ['id' ] in skips :
8777 _print_user_skipped (hook , write , args )
@@ -95,7 +85,7 @@ def _run_single_hook(hook_executor, args, write, skips=frozenset()):
9585 write (get_hook_message (_hook_msg_start (hook , args .verbose ), end_len = 6 ))
9686 sys .stdout .flush ()
9787
98- retcode , stdout , stderr = hook_executor . invoke ( filenames )
88+ retcode , stdout , stderr = repo . run_hook ( hook , filenames )
9989
10090 if retcode != hook ['expected_return_value' ]:
10191 retcode = 1
@@ -119,19 +109,19 @@ def _run_single_hook(hook_executor, args, write, skips=frozenset()):
119109 return retcode
120110
121111
122- def _run_hooks (hook_executors , args , write , environ ):
112+ def _run_hooks (repo_hooks , args , write , environ ):
123113 """Actually run the hooks."""
124114 skips = _get_skips (environ )
125115 retval = 0
126- for hook_executor in hook_executors :
127- retval |= _run_single_hook (hook_executor , args , write , skips )
116+ for repo , hook in repo_hooks :
117+ retval |= _run_single_hook (hook , repo , args , write , skips )
128118 return retval
129119
130120
131- def get_hook_executors (runner ):
121+ def get_repo_hooks (runner ):
132122 for repo in runner .repositories :
133- for _ , repo_hook in repo .hooks :
134- yield HookExecutor ( repo_hook , repo . run_hook )
123+ for _ , hook in repo .hooks :
124+ yield ( repo , hook )
135125
136126
137127def _has_unmerged_paths (runner ):
@@ -159,13 +149,13 @@ def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
159149 ctx = staged_files_only (runner .cmd_runner )
160150
161151 with ctx :
162- hook_executors = list (get_hook_executors (runner ))
152+ repo_hooks = list (get_repo_hooks (runner ))
163153 if args .hook :
164- hook_executors = [
165- he for he in hook_executors
166- if he . hook ['id' ] == args .hook
154+ repo_hooks = [
155+ ( repo , hook ) for repo , hook in repo_hooks
156+ if hook ['id' ] == args .hook
167157 ]
168- if not hook_executors :
158+ if not repo_hooks :
169159 write ('No hook with id `{0}`\n ' .format (args .hook ))
170160 return 1
171- return _run_hooks (hook_executors , args , write , environ )
161+ return _run_hooks (repo_hooks , args , write , environ )
0 commit comments