##// END OF EJS Templates
switched git_command to subprocession for non-blocking Popen.
marcink -
r2676:1f4d4b8d beta
parent child Browse files
Show More
@@ -338,6 +338,9 b' class SubprocessIOChunker(object):'
338 input_streamer.start()
338 input_streamer.start()
339 inputstream = input_streamer.output
339 inputstream = input_streamer.output
340
340
341 if isinstance(cmd, (list, tuple)):
342 cmd = ' '.join(cmd)
343
341 _p = subprocess.Popen(cmd,
344 _p = subprocess.Popen(cmd,
342 bufsize=-1,
345 bufsize=-1,
343 shell=True,
346 shell=True,
@@ -367,8 +370,8 b' class SubprocessIOChunker(object):'
367 pass
370 pass
368 bg_out.stop()
371 bg_out.stop()
369 bg_err.stop()
372 bg_err.stop()
370 err = '%r' % ''.join(bg_err)
373 err = '%s' % ''.join(bg_err)
371 raise EnvironmentError("Subprocess exited due to an error.\n" + err)
374 raise EnvironmentError("Subprocess exited due to an error:\n" + err)
372
375
373 self.process = _p
376 self.process = _p
374 self.output = bg_out
377 self.output = bg_out
@@ -379,7 +382,7 b' class SubprocessIOChunker(object):'
379
382
380 def next(self):
383 def next(self):
381 if self.process.poll():
384 if self.process.poll():
382 err = '%r' % ''.join(self.error)
385 err = '%s' % ''.join(self.error)
383 raise EnvironmentError("Subprocess exited due to an error:\n" + err)
386 raise EnvironmentError("Subprocess exited due to an error:\n" + err)
384 return self.output.next()
387 return self.output.next()
385
388
@@ -13,6 +13,8 b' import os'
13 import re
13 import re
14 import time
14 import time
15 import posixpath
15 import posixpath
16 import logging
17 import traceback
16 from dulwich.repo import Repo, NotGitRepository
18 from dulwich.repo import Repo, NotGitRepository
17 #from dulwich.config import ConfigFile
19 #from dulwich.config import ConfigFile
18 from string import Template
20 from string import Template
@@ -33,6 +35,10 b' from .workdir import GitWorkdir'
33 from .changeset import GitChangeset
35 from .changeset import GitChangeset
34 from .inmemory import GitInMemoryChangeset
36 from .inmemory import GitInMemoryChangeset
35 from .config import ConfigFile
37 from .config import ConfigFile
38 from rhodecode.lib import subprocessio
39
40
41 log = logging.getLogger(__name__)
36
42
37
43
38 class GitRepository(BaseRepository):
44 class GitRepository(BaseRepository):
@@ -106,22 +112,18 b' class GitRepository(BaseRepository):'
106 cmd = ' '.join(cmd)
112 cmd = ' '.join(cmd)
107 try:
113 try:
108 opts = dict(
114 opts = dict(
109 shell=isinstance(cmd, basestring),
110 stdout=PIPE,
111 stderr=PIPE,
112 env=gitenv,
115 env=gitenv,
113 )
116 )
114 if os.path.isdir(self.path):
117 if os.path.isdir(self.path):
115 opts['cwd'] = self.path
118 opts['cwd'] = self.path
116 p = Popen(cmd, **opts)
119 p = subprocessio.SubprocessIOChunker(cmd, **opts)
117 except OSError, err:
120 except (EnvironmentError, OSError), err:
121 log.error(traceback.format_exc())
118 raise RepositoryError("Couldn't run git command (%s).\n"
122 raise RepositoryError("Couldn't run git command (%s).\n"
119 "Original error was:%s" % (cmd, err))
123 "Original error was:%s" % (cmd, err))
120 so, se = p.communicate()
124
121 if not se.startswith("fatal: bad default revision 'HEAD'") and \
125 so = ''.join(p)
122 p.returncode != 0:
126 se = None
123 raise RepositoryError("Couldn't run git command (%s).\n"
124 "stderr:\n%s" % (cmd, se))
125 return so, se
127 return so, se
126
128
127 def _check_url(self, url):
129 def _check_url(self, url):
@@ -161,6 +163,13 b' class GitRepository(BaseRepository):'
161 raise RepositoryError(err)
163 raise RepositoryError(err)
162
164
163 def _get_all_revisions(self):
165 def _get_all_revisions(self):
166 # we must check if this repo is not empty, since later command
167 # fails if it is. And it's cheaper to ask than throw the subprocess
168 # errors
169 try:
170 self._repo.head()
171 except KeyError:
172 return []
164 cmd = 'rev-list --all --reverse --date-order'
173 cmd = 'rev-list --all --reverse --date-order'
165 try:
174 try:
166 so, se = self.run_git_command(cmd)
175 so, se = self.run_git_command(cmd)
General Comments 0
You need to be logged in to leave comments. Login now