Changeset - 19a6c23af14b
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 14 years ago 2012-04-26 23:55:33
marcin@python-works.com
Implemented pull command for remote repos for git
- added mimic ui objects into GitRepos to better handle hooks logic
3 files changed with 45 insertions and 11 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/middleware/simplegit.py
Show inline comments
 
@@ -194,8 +194,8 @@ class SimpleGit(BaseVCSController):
 
        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 @@ class SimpleGit(BaseVCSController):
 
        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)
rhodecode/lib/vcs/backends/git/repository.py
Show inline comments
 
@@ -47,6 +47,15 @@ class GitRepository(BaseRepository):
 

	
 
        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 @@ class GitRepository(BaseRepository):
 
        # 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):
 
        """
rhodecode/model/scm.py
Show inline comments
 
@@ -351,7 +351,7 @@ class ScmModel(BaseModel):
 
                '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)
 

	
0 comments (0 inline, 0 general)