def install_hook_envs(hooks: Sequence[Hook], store: Store) -> None: def _need_installed() -> List[Hook]: seen: Set[Tuple[Prefix, str, str, Tuple[str, ...]]] = set() ret = [] for hook in hooks: if hook.install_key not in seen and not _hook_installed(hook): ret.append(hook) seen.add(hook.install_key) return ret if not _need_installed(): return with store.exclusive_lock(): # Another process may have already completed this work for hook in _need_installed(): _hook_install(hook)
def main( argv: Argv = None, *, pre_commit_config_yaml: Path = None, hook_entry_func: Callable[[Hook], str] = None, tmp_path_func: Callable[[Path], None] = None, ) -> int: if argv is None: argv = sys.argv[1:] if not argv: return usage() with hook_context(argv) as ctx: hook_name, extra_args, tmp_path = ctx if hook_name.startswith("-"): return usage() pre_commit_args = get_pre_commit_args(hook_name, config=pre_commit_config_yaml) with error_handler(), logging_handler(pre_commit_args.color): git.check_for_cygwin_mismatch() store = Store() with store.exclusive_lock(): store.mark_config_used(pre_commit_args.config) hook = find_hook(pre_commit_args, store) retcode, out = run_hook( patch_hook( hook, extra_args=extra_args, entry=hook_entry_func(hook) if hook_entry_func else None, ), pre_commit_args.color, ) if tmp_path and tmp_path_func: tmp_path_func(tmp_path) sys.stdout.buffer.write(out) sys.stdout.buffer.flush() return retcode
def gc(store: Store) -> int: with store.exclusive_lock(): repos_removed = _gc_repos(store) output.write_line(f'{repos_removed} repo(s) removed.') return 0