comparison rhodecode/lib/middleware/simplegit.py @ 2209:19a6c23af14b beta

Implemented pull command for remote repos for git - added mimic ui objects into GitRepos to better handle hooks logic
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 26 Apr 2012 23:55:33 +0200
parents 17ff5693566b
children 37c143aa8616
comparison
equal deleted inserted replaced
2208:954d8952ff2a 2209:19a6c23af14b
192 #=================================================================== 192 #===================================================================
193 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))
194 log.debug('Repository path is %s' % repo_path) 194 log.debug('Repository path is %s' % repo_path)
195 195
196 baseui = make_ui('db') 196 baseui = make_ui('db')
197 for k, v in extras.items(): 197 self.__inject_extras(repo_path, baseui, extras)
198 baseui.setconfig('rhodecode_extras', k, v) 198
199 199
200 try: 200 try:
201 # invalidate cache on push 201 # invalidate cache on push
202 if action == 'push': 202 if action == 'push':
203 self._invalidate_cache(repo_name) 203 self._invalidate_cache(repo_name)
263 # operation is pull/push 263 # operation is pull/push
264 op = getattr(self, '_git_stored_op', 'pull') 264 op = getattr(self, '_git_stored_op', 'pull')
265 return op 265 return op
266 266
267 def _handle_githooks(self, action, baseui, environ): 267 def _handle_githooks(self, action, baseui, environ):
268
269 from rhodecode.lib.hooks import log_pull_action, log_push_action 268 from rhodecode.lib.hooks import log_pull_action, log_push_action
270 service = environ['QUERY_STRING'].split('=') 269 service = environ['QUERY_STRING'].split('=')
271 if len(service) < 2: 270 if len(service) < 2:
272 return 271 return
273 272
274 class cont(object): 273 from rhodecode.model.db import Repository
275 pass 274 _repo = Repository.get_by_repo_name(repo_name)
276 275 _repo = _repo.scm_instance
277 repo = cont() 276 _repo._repo.ui = baseui
278 setattr(repo, 'ui', baseui)
279 277
280 push_hook = 'pretxnchangegroup.push_logger' 278 push_hook = 'pretxnchangegroup.push_logger'
281 pull_hook = 'preoutgoing.pull_logger' 279 pull_hook = 'preoutgoing.pull_logger'
282 _hooks = dict(baseui.configitems('hooks')) or {} 280 _hooks = dict(baseui.configitems('hooks')) or {}
283 if action == 'push' and _hooks.get(push_hook): 281 if action == 'push' and _hooks.get(push_hook):
284 log_push_action(ui=baseui, repo=repo) 282 log_push_action(ui=baseui, repo=repo._repo)
285 elif action == 'pull' and _hooks.get(pull_hook): 283 elif action == 'pull' and _hooks.get(pull_hook):
286 log_pull_action(ui=baseui, repo=repo) 284 log_pull_action(ui=baseui, repo=repo._repo)
285
286 def __inject_extras(self, repo_path, baseui, extras={}):
287 """
288 Injects some extra params into baseui instance
289
290 :param baseui: baseui instance
291 :param extras: dict with extra params to put into baseui
292 """
293
294 # make our hgweb quiet so it doesn't print output
295 baseui.setconfig('ui', 'quiet', 'true')
296
297 #inject some additional parameters that will be available in ui
298 #for hooks
299 for k, v in extras.items():
300 baseui.setconfig('rhodecode_extras', k, v)