Show More
@@ -87,7 +87,7 b' def get_token():' | |||||
87 | if not token_key in session: |
|
87 | if not token_key in session: | |
88 | try: |
|
88 | try: | |
89 | token = hashlib.sha1(str(random.getrandbits(128))).hexdigest() |
|
89 | token = hashlib.sha1(str(random.getrandbits(128))).hexdigest() | |
90 | except AttributeError: # Python < 2.4 |
|
90 | except AttributeError: # Python < 2.4 | |
91 | token = hashlib.sha1(str(random.randrange(2 ** 128))).hexdigest() |
|
91 | token = hashlib.sha1(str(random.randrange(2 ** 128))).hexdigest() | |
92 | session[token_key] = token |
|
92 | session[token_key] = token | |
93 | if hasattr(session, 'save'): |
|
93 | if hasattr(session, 'save'): | |
@@ -454,11 +454,14 b' def action_parser(user_log, feed=False):' | |||||
454 | revision=rev.raw_id), |
|
454 | revision=rev.raw_id), | |
455 | title=tooltip(message(rev)), class_='tooltip') |
|
455 | title=tooltip(message(rev)), class_='tooltip') | |
456 | ) |
|
456 | ) | |
457 | # get only max revs_top_limit of changeset for performance/ui reasons |
|
457 | ||
458 | revs = [ |
|
458 | revs = [] | |
459 | x for x in repo.get_changesets(revs_ids[0], |
|
459 | if len(filter(lambda v: v != '', revs_ids)) > 0: | |
460 | revs_ids[:revs_top_limit][-1]) |
|
460 | # get only max revs_top_limit of changeset for performance/ui reasons | |
461 | ] |
|
461 | revs = [ | |
|
462 | x for x in repo.get_changesets(revs_ids[0], | |||
|
463 | revs_ids[:revs_top_limit][-1]) | |||
|
464 | ] | |||
462 |
|
465 | |||
463 | cs_links = [] |
|
466 | cs_links = [] | |
464 | cs_links.append(" " + ', '.join( |
|
467 | cs_links.append(" " + ', '.join( |
@@ -92,6 +92,7 b' def log_pull_action(ui, repo, **kwargs):' | |||||
92 | extras = dict(repo.ui.configitems('rhodecode_extras')) |
|
92 | extras = dict(repo.ui.configitems('rhodecode_extras')) | |
93 | username = extras['username'] |
|
93 | username = extras['username'] | |
94 | repository = extras['repository'] |
|
94 | repository = extras['repository'] | |
|
95 | scm = extras['scm'] | |||
95 | action = 'pull' |
|
96 | action = 'pull' | |
96 |
|
97 | |||
97 | action_logger(username, action, repository, extras['ip'], commit=True) |
|
98 | action_logger(username, action, repository, extras['ip'], commit=True) | |
@@ -117,21 +118,26 b' def log_push_action(ui, repo, **kwargs):' | |||||
117 | username = extras['username'] |
|
118 | username = extras['username'] | |
118 | repository = extras['repository'] |
|
119 | repository = extras['repository'] | |
119 | action = extras['action'] + ':%s' |
|
120 | action = extras['action'] + ':%s' | |
120 | node = kwargs['node'] |
|
121 | scm = extras['scm'] | |
121 |
|
122 | |||
122 | def get_revs(repo, rev_opt): |
|
123 | if scm == 'hg': | |
123 | if rev_opt: |
|
124 | node = kwargs['node'] | |
124 | revs = revrange(repo, rev_opt) |
|
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: |
|
130 | if len(revs) == 0: | |
127 | return (nullrev, nullrev) |
|
131 | return (nullrev, nullrev) | |
128 | return (max(revs), min(revs)) |
|
132 | return (max(revs), min(revs)) | |
129 | else: |
|
133 | else: | |
130 | return (len(repo) - 1, 0) |
|
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 | action = action % ','.join(revs) |
|
142 | action = action % ','.join(revs) | |
137 |
|
143 |
@@ -74,7 +74,7 b' from paste.httpheaders import REMOTE_USE' | |||||
74 | from rhodecode.lib.utils2 import safe_str |
|
74 | from rhodecode.lib.utils2 import safe_str | |
75 | from rhodecode.lib.base import BaseVCSController |
|
75 | from rhodecode.lib.base import BaseVCSController | |
76 | from rhodecode.lib.auth import get_container_username |
|
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 | from rhodecode.model.db import User |
|
78 | from rhodecode.model.db import User | |
79 |
|
79 | |||
80 | from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
|
80 | from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError | |
@@ -103,6 +103,7 b' class SimpleGit(BaseVCSController):' | |||||
103 |
|
103 | |||
104 | ipaddr = self._get_ip_addr(environ) |
|
104 | ipaddr = self._get_ip_addr(environ) | |
105 | username = None |
|
105 | username = None | |
|
106 | self._git_first_op = False | |||
106 | # skip passing error to error controller |
|
107 | # skip passing error to error controller | |
107 | environ['pylons.status_code_redirect'] = True |
|
108 | environ['pylons.status_code_redirect'] = True | |
108 |
|
109 | |||
@@ -178,6 +179,13 b' class SimpleGit(BaseVCSController):' | |||||
178 | perm = self._check_permission(action, user, repo_name) |
|
179 | perm = self._check_permission(action, user, repo_name) | |
179 | if perm is not True: |
|
180 | if perm is not True: | |
180 | return HTTPForbidden()(environ, start_response) |
|
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 | # GIT REQUEST HANDLING |
|
191 | # GIT REQUEST HANDLING | |
@@ -185,10 +193,16 b' class SimpleGit(BaseVCSController):' | |||||
185 | repo_path = os.path.join(safe_str(self.basepath), safe_str(repo_name)) |
|
193 | repo_path = os.path.join(safe_str(self.basepath), safe_str(repo_name)) | |
186 | log.debug('Repository path is %s' % repo_path) |
|
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 | try: |
|
200 | try: | |
189 | #invalidate cache on push |
|
201 | # invalidate cache on push | |
190 | if action == 'push': |
|
202 | if action == 'push': | |
191 | self._invalidate_cache(repo_name) |
|
203 | self._invalidate_cache(repo_name) | |
|
204 | self._handle_githooks(action, baseui, environ) | |||
|
205 | ||||
192 | log.info('%s action on GIT repo "%s"' % (action, repo_name)) |
|
206 | log.info('%s action on GIT repo "%s"' % (action, repo_name)) | |
193 | app = self.__make_app(repo_name, repo_path) |
|
207 | app = self.__make_app(repo_name, repo_path) | |
194 | return app(environ, start_response) |
|
208 | return app(environ, start_response) | |
@@ -249,3 +263,25 b' class SimpleGit(BaseVCSController):' | |||||
249 | # operation is pull/push |
|
263 | # operation is pull/push | |
250 | op = getattr(self, '_git_stored_op', 'pull') |
|
264 | op = getattr(self, '_git_stored_op', 'pull') | |
251 | return op |
|
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 | 'ip': ipaddr, |
|
153 | 'ip': ipaddr, | |
154 | 'username': username, |
|
154 | 'username': username, | |
155 | 'action': action, |
|
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