From 8ced8641c88d37891a46d42ac1805e380ef6c377 Mon Sep 17 00:00:00 2001 From: Doug Anderson Date: Mon, 10 Jan 2011 14:16:30 -0800 Subject: [PATCH] Renamed 'repo_hooks' function to '_ProjectHooks'. This renaming was done for two reasons: 1. The hooks are actually project-level hooks, not repo-level hooks. Since we are talking about adding repo-level hooks, It keeps things less confusing if we name the existing hooks to be "ProjectHooks" 2. The function is a private function in project.py and so should have capitalization to match. I also added a docstring describing this function. Change-Id: I1d30f5de08e8f9f99f78146e68c76f906782d97e --- project.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/project.py b/project.py index ca092b89..125fb48c 100644 --- a/project.py +++ b/project.py @@ -54,14 +54,25 @@ def not_rev(r): def sq(r): return "'" + r.replace("'", "'\''") + "'" -hook_list = None -def repo_hooks(): - global hook_list - if hook_list is None: +_project_hook_list = None +def _ProjectHooks(): + """List the hooks present in the 'hooks' directory. + + These hooks are project hooks and are copied to the '.git/hooks' directory + of all subprojects. + + This function caches the list of hooks (based on the contents of the + 'repo/hooks' directory) on the first call. + + Returns: + A list of absolute paths to all of the files in the hooks directory. + """ + global _project_hook_list + if _project_hook_list is None: d = os.path.abspath(os.path.dirname(__file__)) d = os.path.join(d , 'hooks') - hook_list = map(lambda x: os.path.join(d, x), os.listdir(d)) - return hook_list + _project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d)) + return _project_hook_list def relpath(dst, src): src = os.path.dirname(src) @@ -1192,7 +1203,7 @@ class Project(object): hooks = self._gitdir_path('hooks') if not os.path.exists(hooks): os.makedirs(hooks) - for stock_hook in repo_hooks(): + for stock_hook in _ProjectHooks(): name = os.path.basename(stock_hook) if name in ('commit-msg',) and not self.remote.review: