From 7b6407df8125cb12e46c1c2abb65754363b1fb04 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Tue, 17 Apr 2018 15:46:40 +0200 Subject: [PATCH] Technically we only need os.walk() on forks The other namespace won't have sub-folders Signed-off-by: Pierre-Yves Chibon --- roles/git/checks/files/distgit_check_hook.py | 32 +++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/roles/git/checks/files/distgit_check_hook.py b/roles/git/checks/files/distgit_check_hook.py index 9d21482755..e24a7287f9 100644 --- a/roles/git/checks/files/distgit_check_hook.py +++ b/roles/git/checks/files/distgit_check_hook.py @@ -57,7 +57,7 @@ def is_valid_hook(hook, target_link): return output -def process_namespace(namespace, check): +def process_namespace(namespace, check, walk=False): """ Process all the git repo in a specified namespace. """ target_link = _target_link if namespace == 'forks': @@ -68,12 +68,22 @@ def process_namespace(namespace, check): if not os.path.isdir(path): return - for dirpath, dirnames, filenames in os.walk(path): - # Don't go down the .git repos - if '.git' in dirpath: - continue + if walk: + for dirpath, dirnames, filenames in os.walk(path): + # Don't go down the .git repos + if '.git' in dirpath: + continue - for repo in dirnames: + for repo in dirnames: + repo_path = os.path.join(dirpath, repo) + if not repo_path.endswith('.git'): + continue + + hook = os.path.join(repo_path, 'hooks', 'post-receive') + if not is_valid_hook(hook, target_link) and not check: + fix_link(hook, target_link) + else: + for repo in os.listdir(path): repo_path = os.path.join(dirpath, repo) if not repo_path.endswith('.git'): continue @@ -111,11 +121,17 @@ def main(): fix_link(hook, target_link) elif args.namespace: - process_namespace(args.namespace, args.check) + walk = False + if namespace == 'forks': + walk = true + process_namespace(args.namespace, args.check, walk=walk) else: # Check all repos for namespace in namespaces: - process_namespace(namespace, args.check) + walk = False + if namespace == 'forks': + walk = true + process_namespace(namespace, args.check, walk=walk) if __name__ == '__main__':