# HG changeset patch # User Marcin Kuzminski # Date 1335477333 -7200 # Node ID 19a6c23af14bf3d6460570739cc7279be00898c0 # Parent 954d8952ff2afdbaed99f2433dd936628598f048 Implemented pull command for remote repos for git - added mimic ui objects into GitRepos to better handle hooks logic diff -r 954d8952ff2a -r 19a6c23af14b rhodecode/lib/middleware/simplegit.py --- a/rhodecode/lib/middleware/simplegit.py Thu Apr 26 21:22:13 2012 +0200 +++ b/rhodecode/lib/middleware/simplegit.py Thu Apr 26 23:55:33 2012 +0200 @@ -194,8 +194,8 @@ log.debug('Repository path is %s' % repo_path) baseui = make_ui('db') - for k, v in extras.items(): - baseui.setconfig('rhodecode_extras', k, v) + self.__inject_extras(repo_path, baseui, extras) + try: # invalidate cache on push @@ -265,22 +265,36 @@ return op def _handle_githooks(self, action, baseui, environ): - from rhodecode.lib.hooks import log_pull_action, log_push_action service = environ['QUERY_STRING'].split('=') if len(service) < 2: return - class cont(object): - pass - - repo = cont() - setattr(repo, 'ui', baseui) + from rhodecode.model.db import Repository + _repo = Repository.get_by_repo_name(repo_name) + _repo = _repo.scm_instance + _repo._repo.ui = baseui push_hook = 'pretxnchangegroup.push_logger' pull_hook = 'preoutgoing.pull_logger' _hooks = dict(baseui.configitems('hooks')) or {} if action == 'push' and _hooks.get(push_hook): - log_push_action(ui=baseui, repo=repo) + log_push_action(ui=baseui, repo=repo._repo) elif action == 'pull' and _hooks.get(pull_hook): - log_pull_action(ui=baseui, repo=repo) + log_pull_action(ui=baseui, repo=repo._repo) + + def __inject_extras(self, repo_path, baseui, extras={}): + """ + Injects some extra params into baseui instance + + :param baseui: baseui instance + :param extras: dict with extra params to put into baseui + """ + + # make our hgweb quiet so it doesn't print output + baseui.setconfig('ui', 'quiet', 'true') + + #inject some additional parameters that will be available in ui + #for hooks + for k, v in extras.items(): + baseui.setconfig('rhodecode_extras', k, v) diff -r 954d8952ff2a -r 19a6c23af14b rhodecode/lib/vcs/backends/git/repository.py --- a/rhodecode/lib/vcs/backends/git/repository.py Thu Apr 26 21:22:13 2012 +0200 +++ b/rhodecode/lib/vcs/backends/git/repository.py Thu Apr 26 23:55:33 2012 +0200 @@ -47,6 +47,15 @@ self.path = abspath(repo_path) self._repo = self._get_repo(create, src_url, update_after_clone, bare) + #temporary set that to now at later we will move it to constructor + baseui = None + if baseui is None: + from mercurial.ui import ui + baseui = ui() + # patch the instance of GitRepo with an "FAKE" ui object to add + # compatibility layer with Mercurial + setattr(self._repo, 'ui', baseui) + try: self.head = self._repo.head() except KeyError: @@ -471,6 +480,17 @@ # If error occurs run_git_command raises RepositoryError already self.run_git_command(cmd) + def pull(self, url): + """ + Tries to pull changes from external location. + """ + url = self._get_url(url) + cmd = ['pull'] + cmd.append("--ff-only") + cmd = ' '.join(cmd) + # If error occurs run_git_command raises RepositoryError already + self.run_git_command(cmd) + @LazyProperty def workdir(self): """ diff -r 954d8952ff2a -r 19a6c23af14b rhodecode/model/scm.py --- a/rhodecode/model/scm.py Thu Apr 26 21:22:13 2012 +0200 +++ b/rhodecode/model/scm.py Thu Apr 26 23:55:33 2012 +0200 @@ -351,7 +351,7 @@ 'scm': repo.alias, } - #inject ui extra param to log this action via push logger + # inject ui extra param to log this action via push logger for k, v in extras.items(): repo._repo.ui.setconfig('rhodecode_extras', k, v)