Changeset - 1f4d4b8d72f5
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2012-07-30 22:45:43
marcin@python-works.com
switched git_command to subprocession for non-blocking Popen.
2 files changed with 25 insertions and 13 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/subprocessio.py
Show inline comments
 
@@ -338,6 +338,9 @@ class SubprocessIOChunker(object):
 
            input_streamer.start()
 
            inputstream = input_streamer.output
 

	
 
        if isinstance(cmd, (list, tuple)):
 
            cmd = ' '.join(cmd)
 

	
 
        _p = subprocess.Popen(cmd,
 
            bufsize=-1,
 
            shell=True,
 
@@ -367,8 +370,8 @@ class SubprocessIOChunker(object):
 
                pass
 
            bg_out.stop()
 
            bg_err.stop()
 
            err = '%r' % ''.join(bg_err)
 
            raise EnvironmentError("Subprocess exited due to an error.\n" + err)
 
            err = '%s' % ''.join(bg_err)
 
            raise EnvironmentError("Subprocess exited due to an error:\n" + err)
 

	
 
        self.process = _p
 
        self.output = bg_out
 
@@ -379,7 +382,7 @@ class SubprocessIOChunker(object):
 

	
 
    def next(self):
 
        if self.process.poll():
 
            err = '%r' % ''.join(self.error)
 
            err = '%s' % ''.join(self.error)
 
            raise EnvironmentError("Subprocess exited due to an error:\n" + err)
 
        return self.output.next()
 

	
rhodecode/lib/vcs/backends/git/repository.py
Show inline comments
 
@@ -13,6 +13,8 @@ import os
 
import re
 
import time
 
import posixpath
 
import logging
 
import traceback
 
from dulwich.repo import Repo, NotGitRepository
 
#from dulwich.config import ConfigFile
 
from string import Template
 
@@ -33,6 +35,10 @@ from .workdir import GitWorkdir
 
from .changeset import GitChangeset
 
from .inmemory import GitInMemoryChangeset
 
from .config import ConfigFile
 
from rhodecode.lib import subprocessio
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class GitRepository(BaseRepository):
 
@@ -106,22 +112,18 @@ class GitRepository(BaseRepository):
 
            cmd = ' '.join(cmd)
 
        try:
 
            opts = dict(
 
                shell=isinstance(cmd, basestring),
 
                stdout=PIPE,
 
                stderr=PIPE,
 
                env=gitenv,
 
            )
 
            if os.path.isdir(self.path):
 
                opts['cwd'] = self.path
 
            p = Popen(cmd, **opts)
 
        except OSError, err:
 
            p = subprocessio.SubprocessIOChunker(cmd, **opts)
 
        except (EnvironmentError, OSError), err:
 
            log.error(traceback.format_exc())
 
            raise RepositoryError("Couldn't run git command (%s).\n"
 
                "Original error was:%s" % (cmd, err))
 
        so, se = p.communicate()
 
        if not se.startswith("fatal: bad default revision 'HEAD'") and \
 
            p.returncode != 0:
 
            raise RepositoryError("Couldn't run git command (%s).\n"
 
                "stderr:\n%s" % (cmd, se))
 

	
 
        so = ''.join(p)
 
        se = None
 
        return so, se
 

	
 
    def _check_url(self, url):
 
@@ -161,6 +163,13 @@ class GitRepository(BaseRepository):
 
            raise RepositoryError(err)
 

	
 
    def _get_all_revisions(self):
 
        # we must check if this repo is not empty, since later command
 
        # fails if it is. And it's cheaper to ask than throw the subprocess
 
        # errors
 
        try:
 
            self._repo.head()
 
        except KeyError:
 
            return []
 
        cmd = 'rev-list --all --reverse --date-order'
 
        try:
 
            so, se = self.run_git_command(cmd)
0 comments (0 inline, 0 general)