##// END OF EJS Templates
hooks: expose logic to fetch hook file information.
marcink -
r623:0f0a8ed3 default
parent child
Show More
@@ -724,6 +724,16 class GitRemote(object):
724 repo = self._factory.repo(wire)
724 repo = self._factory.repo(wire)
725 return install_git_hooks(repo.path, repo.bare, force_create=force)
725 return install_git_hooks(repo.path, repo.bare, force_create=force)
726
726
727 @reraise_safe_exceptions
728 def get_hooks_info(self, wire):
729 from vcsserver.hook_utils import (
730 get_git_pre_hook_version, get_git_post_hook_version)
731 repo = self._factory.repo(wire)
732 return {
733 'pre_version': get_git_pre_hook_version(repo.path, repo.bare),
734 'post_version': get_git_post_hook_version(repo.path, repo.bare),
735 }
736
727
737
728 def str_to_dulwich(value):
738 def str_to_dulwich(value):
729 """
739 """
@@ -27,6 +27,7 from mercurial import commands
27 from mercurial import unionrepo
27 from mercurial import unionrepo
28 from mercurial import verify
28 from mercurial import verify
29
29
30 import vcsserver
30 from vcsserver import exceptions
31 from vcsserver import exceptions
31 from vcsserver.base import RepoFactory, obfuscate_qs, raise_from_original
32 from vcsserver.base import RepoFactory, obfuscate_qs, raise_from_original
32 from vcsserver.hgcompat import (
33 from vcsserver.hgcompat import (
@@ -793,3 +794,10 class HgRemote(object):
793 def install_hooks(self, wire, force=False):
794 def install_hooks(self, wire, force=False):
794 # we don't need any special hooks for Mercurial
795 # we don't need any special hooks for Mercurial
795 pass
796 pass
797
798 @reraise_safe_exceptions
799 def get_hooks_info(self, wire):
800 return {
801 'pre_version': vcsserver.__version__,
802 'post_version': vcsserver.__version__,
803 }
@@ -29,6 +29,14 import vcsserver
29 log = logging.getLogger(__name__)
29 log = logging.getLogger(__name__)
30
30
31
31
32 def get_git_hooks_path(repo_path, bare):
33 hooks_path = os.path.join(repo_path, 'hooks')
34 if not bare:
35 hooks_path = os.path.join(repo_path, '.git', 'hooks')
36
37 return hooks_path
38
39
32 def install_git_hooks(repo_path, bare, executable=None, force_create=False):
40 def install_git_hooks(repo_path, bare, executable=None, force_create=False):
33 """
41 """
34 Creates a RhodeCode hook inside a git repository
42 Creates a RhodeCode hook inside a git repository
@@ -38,9 +46,8 def install_git_hooks(repo_path, bare, e
38 :param force_create: Create even if same name hook exists
46 :param force_create: Create even if same name hook exists
39 """
47 """
40 executable = executable or sys.executable
48 executable = executable or sys.executable
41 hooks_path = os.path.join(repo_path, 'hooks')
49 hooks_path = get_git_hooks_path(repo_path, bare)
42 if not bare:
50
43 hooks_path = os.path.join(repo_path, '.git', 'hooks')
44 if not os.path.isdir(hooks_path):
51 if not os.path.isdir(hooks_path):
45 os.makedirs(hooks_path, mode=0o777)
52 os.makedirs(hooks_path, mode=0o777)
46
53
@@ -78,6 +85,12 def install_git_hooks(repo_path, bare, e
78 return True
85 return True
79
86
80
87
88 def get_svn_hooks_path(repo_path):
89 hooks_path = os.path.join(repo_path, 'hooks')
90
91 return hooks_path
92
93
81 def install_svn_hooks(repo_path, executable=None, force_create=False):
94 def install_svn_hooks(repo_path, executable=None, force_create=False):
82 """
95 """
83 Creates RhodeCode hooks inside a svn repository
96 Creates RhodeCode hooks inside a svn repository
@@ -87,7 +100,7 def install_svn_hooks(repo_path, executa
87 :param force_create: Create even if same name hook exists
100 :param force_create: Create even if same name hook exists
88 """
101 """
89 executable = executable or sys.executable
102 executable = executable or sys.executable
90 hooks_path = os.path.join(repo_path, 'hooks')
103 hooks_path = get_svn_hooks_path(repo_path)
91 if not os.path.isdir(hooks_path):
104 if not os.path.isdir(hooks_path):
92 os.makedirs(hooks_path, mode=0o777)
105 os.makedirs(hooks_path, mode=0o777)
93
106
@@ -127,6 +140,19 def install_svn_hooks(repo_path, executa
127 return True
140 return True
128
141
129
142
143 def get_version_from_hook(hook_path):
144 version = ''
145 hook_content = read_hook_content(hook_path)
146 matches = re.search(r'(?:RC_HOOK_VER)\s*=\s*(.*)', hook_content)
147 if matches:
148 try:
149 version = matches.groups()[0]
150 log.debug('got version %s from hooks.', version)
151 except Exception:
152 log.exception("Exception while reading the hook version.")
153 return version.replace("'", "")
154
155
130 def check_rhodecode_hook(hook_path):
156 def check_rhodecode_hook(hook_path):
131 """
157 """
132 Check if the hook was created by RhodeCode
158 Check if the hook was created by RhodeCode
@@ -134,16 +160,11 def check_rhodecode_hook(hook_path):
134 if not os.path.exists(hook_path):
160 if not os.path.exists(hook_path):
135 return True
161 return True
136
162
137 log.debug('hook exists, checking if it is from rhodecode')
163 log.debug('hook exists, checking if it is from RhodeCode')
138 hook_content = read_hook_content(hook_path)
164
139 matches = re.search(r'(?:RC_HOOK_VER)\s*=\s*(.*)', hook_content)
165 version = get_version_from_hook(hook_path)
140 if matches:
166 if version:
141 try:
167 return True
142 version = matches.groups()[0]
143 log.debug('got version %s from hooks.', version)
144 return True
145 except Exception:
146 log.exception("Exception while reading the hook version.")
147
168
148 return False
169 return False
149
170
@@ -152,3 +173,31 def read_hook_content(hook_path):
152 with open(hook_path, 'rb') as f:
173 with open(hook_path, 'rb') as f:
153 content = f.read()
174 content = f.read()
154 return content
175 return content
176
177
178 def get_git_pre_hook_version(repo_path, bare):
179 hooks_path = get_git_hooks_path(repo_path, bare)
180 _hook_file = os.path.join(hooks_path, 'pre-receive')
181 version = get_version_from_hook(_hook_file)
182 return version
183
184
185 def get_git_post_hook_version(repo_path, bare):
186 hooks_path = get_git_hooks_path(repo_path, bare)
187 _hook_file = os.path.join(hooks_path, 'post-receive')
188 version = get_version_from_hook(_hook_file)
189 return version
190
191
192 def get_svn_pre_hook_version(repo_path):
193 hooks_path = get_svn_hooks_path(repo_path)
194 _hook_file = os.path.join(hooks_path, 'pre-commit')
195 version = get_version_from_hook(_hook_file)
196 return version
197
198
199 def get_svn_post_hook_version(repo_path):
200 hooks_path = get_svn_hooks_path(repo_path)
201 _hook_file = os.path.join(hooks_path, 'post-commit')
202 version = get_version_from_hook(_hook_file)
203 return version
@@ -458,6 +458,16 class SvnRemote(object):
458 return install_svn_hooks(
458 return install_svn_hooks(
459 repo_path, executable=executable, force_create=force)
459 repo_path, executable=executable, force_create=force)
460
460
461 @reraise_safe_exceptions
462 def get_hooks_info(self, wire):
463 from vcsserver.hook_utils import (
464 get_svn_pre_hook_version, get_svn_post_hook_version)
465 repo_path = wire['path']
466 return {
467 'pre_version': get_svn_pre_hook_version(repo_path),
468 'post_version': get_svn_post_hook_version(repo_path),
469 }
470
461
471
462 class SvnDiffer(object):
472 class SvnDiffer(object):
463 """
473 """
General Comments 0
You need to be logged in to leave comments. Login now