Show More
@@ -87,7 +87,7 b' def get_token():' | |||
|
87 | 87 | if not token_key in session: |
|
88 | 88 | try: |
|
89 | 89 | token = hashlib.sha1(str(random.getrandbits(128))).hexdigest() |
|
90 | except AttributeError: # Python < 2.4 | |
|
90 | except AttributeError: # Python < 2.4 | |
|
91 | 91 | token = hashlib.sha1(str(random.randrange(2 ** 128))).hexdigest() |
|
92 | 92 | session[token_key] = token |
|
93 | 93 | if hasattr(session, 'save'): |
@@ -454,11 +454,14 b' def action_parser(user_log, feed=False):' | |||
|
454 | 454 | revision=rev.raw_id), |
|
455 | 455 | title=tooltip(message(rev)), class_='tooltip') |
|
456 | 456 | ) |
|
457 | # get only max revs_top_limit of changeset for performance/ui reasons | |
|
458 | revs = [ | |
|
459 | x for x in repo.get_changesets(revs_ids[0], | |
|
460 | revs_ids[:revs_top_limit][-1]) | |
|
461 | ] | |
|
457 | ||
|
458 | revs = [] | |
|
459 | if len(filter(lambda v: v != '', revs_ids)) > 0: | |
|
460 | # get only max revs_top_limit of changeset for performance/ui reasons | |
|
461 | revs = [ | |
|
462 | x for x in repo.get_changesets(revs_ids[0], | |
|
463 | revs_ids[:revs_top_limit][-1]) | |
|
464 | ] | |
|
462 | 465 | |
|
463 | 466 | cs_links = [] |
|
464 | 467 | cs_links.append(" " + ', '.join( |
@@ -92,6 +92,7 b' def log_pull_action(ui, repo, **kwargs):' | |||
|
92 | 92 | extras = dict(repo.ui.configitems('rhodecode_extras')) |
|
93 | 93 | username = extras['username'] |
|
94 | 94 | repository = extras['repository'] |
|
95 | scm = extras['scm'] | |
|
95 | 96 | action = 'pull' |
|
96 | 97 | |
|
97 | 98 | action_logger(username, action, repository, extras['ip'], commit=True) |
@@ -117,21 +118,26 b' def log_push_action(ui, repo, **kwargs):' | |||
|
117 | 118 | username = extras['username'] |
|
118 | 119 | repository = extras['repository'] |
|
119 | 120 | action = extras['action'] + ':%s' |
|
120 | node = kwargs['node'] | |
|
121 | scm = extras['scm'] | |
|
121 | 122 | |
|
122 | def get_revs(repo, rev_opt): | |
|
123 | if rev_opt: | |
|
124 | revs = revrange(repo, rev_opt) | |
|
123 | if scm == 'hg': | |
|
124 | node = kwargs['node'] | |
|
125 | ||
|
126 | def get_revs(repo, rev_opt): | |
|
127 | if rev_opt: | |
|
128 | revs = revrange(repo, rev_opt) | |
|
125 | 129 | |
|
126 | if len(revs) == 0: | |
|
127 | return (nullrev, nullrev) | |
|
128 | return (max(revs), min(revs)) | |
|
129 | else: | |
|
130 | return (len(repo) - 1, 0) | |
|
130 | if len(revs) == 0: | |
|
131 | return (nullrev, nullrev) | |
|
132 | return (max(revs), min(revs)) | |
|
133 | else: | |
|
134 | return (len(repo) - 1, 0) | |
|
131 | 135 | |
|
132 | stop, start = get_revs(repo, [node + ':']) | |
|
136 | stop, start = get_revs(repo, [node + ':']) | |
|
133 | 137 | |
|
134 | revs = (str(repo[r]) for r in xrange(start, stop + 1)) | |
|
138 | revs = (str(repo[r]) for r in xrange(start, stop + 1)) | |
|
139 | elif scm == 'git': | |
|
140 | revs = [] | |
|
135 | 141 | |
|
136 | 142 | action = action % ','.join(revs) |
|
137 | 143 |
@@ -74,7 +74,7 b' from paste.httpheaders import REMOTE_USE' | |||
|
74 | 74 | from rhodecode.lib.utils2 import safe_str |
|
75 | 75 | from rhodecode.lib.base import BaseVCSController |
|
76 | 76 | from rhodecode.lib.auth import get_container_username |
|
77 | from rhodecode.lib.utils import is_valid_repo | |
|
77 | from rhodecode.lib.utils import is_valid_repo, make_ui | |
|
78 | 78 | from rhodecode.model.db import User |
|
79 | 79 | |
|
80 | 80 | from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
@@ -103,6 +103,7 b' class SimpleGit(BaseVCSController):' | |||
|
103 | 103 | |
|
104 | 104 | ipaddr = self._get_ip_addr(environ) |
|
105 | 105 | username = None |
|
106 | self._git_first_op = False | |
|
106 | 107 | # skip passing error to error controller |
|
107 | 108 | environ['pylons.status_code_redirect'] = True |
|
108 | 109 | |
@@ -178,6 +179,13 b' class SimpleGit(BaseVCSController):' | |||
|
178 | 179 | perm = self._check_permission(action, user, repo_name) |
|
179 | 180 | if perm is not True: |
|
180 | 181 | return HTTPForbidden()(environ, start_response) |
|
182 | extras = { | |
|
183 | 'ip': ipaddr, | |
|
184 | 'username': username, | |
|
185 | 'action': action, | |
|
186 | 'repository': repo_name, | |
|
187 | 'scm': 'git', | |
|
188 | } | |
|
181 | 189 | |
|
182 | 190 | #=================================================================== |
|
183 | 191 | # GIT REQUEST HANDLING |
@@ -185,10 +193,16 b' class SimpleGit(BaseVCSController):' | |||
|
185 | 193 | repo_path = os.path.join(safe_str(self.basepath), safe_str(repo_name)) |
|
186 | 194 | log.debug('Repository path is %s' % repo_path) |
|
187 | 195 | |
|
196 | baseui = make_ui('db') | |
|
197 | for k, v in extras.items(): | |
|
198 | baseui.setconfig('rhodecode_extras', k, v) | |
|
199 | ||
|
188 | 200 | try: |
|
189 | #invalidate cache on push | |
|
201 | # invalidate cache on push | |
|
190 | 202 | if action == 'push': |
|
191 | 203 | self._invalidate_cache(repo_name) |
|
204 | self._handle_githooks(action, baseui, environ) | |
|
205 | ||
|
192 | 206 | log.info('%s action on GIT repo "%s"' % (action, repo_name)) |
|
193 | 207 | app = self.__make_app(repo_name, repo_path) |
|
194 | 208 | return app(environ, start_response) |
@@ -249,3 +263,25 b' class SimpleGit(BaseVCSController):' | |||
|
249 | 263 | # operation is pull/push |
|
250 | 264 | op = getattr(self, '_git_stored_op', 'pull') |
|
251 | 265 | return op |
|
266 | ||
|
267 | def _handle_githooks(self, action, baseui, environ): | |
|
268 | ||
|
269 | from rhodecode.lib.hooks import log_pull_action, log_push_action | |
|
270 | service = environ['QUERY_STRING'].split('=') | |
|
271 | if len(service) < 2: | |
|
272 | return | |
|
273 | ||
|
274 | class cont(object): | |
|
275 | pass | |
|
276 | ||
|
277 | repo = cont() | |
|
278 | setattr(repo, 'ui', baseui) | |
|
279 | ||
|
280 | push_hook = 'pretxnchangegroup.push_logger' | |
|
281 | pull_hook = 'preoutgoing.pull_logger' | |
|
282 | _hooks = dict(baseui.configitems('hooks')) or {} | |
|
283 | if action == 'push' and _hooks.get(push_hook): | |
|
284 | log_push_action(ui=baseui, repo=repo) | |
|
285 | elif action == 'pull' and _hooks.get(pull_hook): | |
|
286 | log_pull_action(ui=baseui, repo=repo) | |
|
287 |
@@ -153,7 +153,8 b' class SimpleHg(BaseVCSController):' | |||
|
153 | 153 | 'ip': ipaddr, |
|
154 | 154 | 'username': username, |
|
155 | 155 | 'action': action, |
|
156 | 'repository': repo_name | |
|
156 | 'repository': repo_name, | |
|
157 | 'scm': 'hg', | |
|
157 | 158 | } |
|
158 | 159 | |
|
159 | 160 | #====================================================================== |
General Comments 0
You need to be logged in to leave comments.
Login now