Show More
@@ -724,6 +724,16 b' class GitRemote(object):' | |||
|
724 | 724 | repo = self._factory.repo(wire) |
|
725 | 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 | 738 | def str_to_dulwich(value): |
|
729 | 739 | """ |
@@ -27,6 +27,7 b' from mercurial import commands' | |||
|
27 | 27 | from mercurial import unionrepo |
|
28 | 28 | from mercurial import verify |
|
29 | 29 | |
|
30 | import vcsserver | |
|
30 | 31 | from vcsserver import exceptions |
|
31 | 32 | from vcsserver.base import RepoFactory, obfuscate_qs, raise_from_original |
|
32 | 33 | from vcsserver.hgcompat import ( |
@@ -793,3 +794,10 b' class HgRemote(object):' | |||
|
793 | 794 | def install_hooks(self, wire, force=False): |
|
794 | 795 | # we don't need any special hooks for Mercurial |
|
795 | 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 b' import vcsserver' | |||
|
29 | 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 | 40 | def install_git_hooks(repo_path, bare, executable=None, force_create=False): |
|
33 | 41 | """ |
|
34 | 42 | Creates a RhodeCode hook inside a git repository |
@@ -38,9 +46,8 b' def install_git_hooks(repo_path, bare, e' | |||
|
38 | 46 | :param force_create: Create even if same name hook exists |
|
39 | 47 | """ |
|
40 | 48 | executable = executable or sys.executable |
|
41 |
hooks_path = |
|
|
42 | if not bare: | |
|
43 | hooks_path = os.path.join(repo_path, '.git', 'hooks') | |
|
49 | hooks_path = get_git_hooks_path(repo_path, bare) | |
|
50 | ||
|
44 | 51 | if not os.path.isdir(hooks_path): |
|
45 | 52 | os.makedirs(hooks_path, mode=0o777) |
|
46 | 53 | |
@@ -78,6 +85,12 b' def install_git_hooks(repo_path, bare, e' | |||
|
78 | 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 | 94 | def install_svn_hooks(repo_path, executable=None, force_create=False): |
|
82 | 95 | """ |
|
83 | 96 | Creates RhodeCode hooks inside a svn repository |
@@ -87,7 +100,7 b' def install_svn_hooks(repo_path, executa' | |||
|
87 | 100 | :param force_create: Create even if same name hook exists |
|
88 | 101 | """ |
|
89 | 102 | executable = executable or sys.executable |
|
90 |
hooks_path = |
|
|
103 | hooks_path = get_svn_hooks_path(repo_path) | |
|
91 | 104 | if not os.path.isdir(hooks_path): |
|
92 | 105 | os.makedirs(hooks_path, mode=0o777) |
|
93 | 106 | |
@@ -127,6 +140,19 b' def install_svn_hooks(repo_path, executa' | |||
|
127 | 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 | 156 | def check_rhodecode_hook(hook_path): |
|
131 | 157 | """ |
|
132 | 158 | Check if the hook was created by RhodeCode |
@@ -134,16 +160,11 b' def check_rhodecode_hook(hook_path):' | |||
|
134 | 160 | if not os.path.exists(hook_path): |
|
135 | 161 | return True |
|
136 | 162 | |
|
137 |
log.debug('hook exists, checking if it is from |
|
|
138 | hook_content = read_hook_content(hook_path) | |
|
139 | matches = re.search(r'(?:RC_HOOK_VER)\s*=\s*(.*)', hook_content) | |
|
140 |
if |
|
|
141 |
|
|
|
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.") | |
|
163 | log.debug('hook exists, checking if it is from RhodeCode') | |
|
164 | ||
|
165 | version = get_version_from_hook(hook_path) | |
|
166 | if version: | |
|
167 | return True | |
|
147 | 168 | |
|
148 | 169 | return False |
|
149 | 170 | |
@@ -152,3 +173,31 b' def read_hook_content(hook_path):' | |||
|
152 | 173 | with open(hook_path, 'rb') as f: |
|
153 | 174 | content = f.read() |
|
154 | 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 b' class SvnRemote(object):' | |||
|
458 | 458 | return install_svn_hooks( |
|
459 | 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 | 472 | class SvnDiffer(object): |
|
463 | 473 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now