changeset 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 954d8952ff2a
children 7b458dd6f40d
files rhodecode/lib/middleware/simplegit.py rhodecode/lib/vcs/backends/git/repository.py rhodecode/model/scm.py
diffstat 3 files changed, 45 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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):
         """
--- 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)