Commit 7e1c2ed9 authored by Julien Muchembled's avatar Julien Muchembled

run_test_suite: add support for pure Git working copy

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44180 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 288b5520
......@@ -30,24 +30,25 @@ def format_command(*args, **kw):
cmdline.append(v)
return ' '.join(cmdline)
def subprocess_capture(p):
def subprocess_capture(p, quiet=False):
def readerthread(input, output, buffer):
while True:
data = input.readline()
if not data:
break
output.write(data)
output(data)
buffer.append(data)
if p.stdout:
stdout = []
output = quiet and (lambda data: None) or sys.stdout.write
stdout_thread = threading.Thread(target=readerthread,
args=(p.stdout, sys.stdout, stdout))
args=(p.stdout, output, stdout))
stdout_thread.setDaemon(True)
stdout_thread.start()
if p.stderr:
stderr = []
stderr_thread = threading.Thread(target=readerthread,
args=(p.stderr, sys.stderr, stderr))
args=(p.stderr, sys.stderr.write, stderr))
stderr_thread.setDaemon(True)
stderr_thread.start()
if p.stdout:
......@@ -106,7 +107,7 @@ class SubprocessError(EnvironmentError):
class Updater(object):
_git_svn_cache = {}
_git_cache = {}
realtime_output = True
stdin = file(os.devnull)
......@@ -127,6 +128,7 @@ class Updater(object):
raise
def spawn(self, *args, **kw):
quiet = kw.pop('quiet', False)
env = kw and dict(os.environ, **kw) or None
command = format_command(*args, **kw)
print '\n$ ' + command
......@@ -134,10 +136,11 @@ class Updater(object):
p = subprocess.Popen(args, stdin=self.stdin, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env)
if self.realtime_output:
stdout, stderr = subprocess_capture(p)
stdout, stderr = subprocess_capture(p, quiet)
else:
stdout, stderr = p.communicate()
sys.stdout.write(stdout)
if not quiet:
sys.stdout.write(stdout)
sys.stderr.write(stderr)
result = dict(status_code=p.returncode, command=command,
stdout=stdout, stderr=stderr)
......@@ -150,13 +153,15 @@ class Updater(object):
def _git_find_rev(self, ref):
try:
return self._git_svn_cache[ref]
return self._git_cache[ref]
except KeyError:
r = self._git('svn', 'find-rev', ref)
assert r
ref2 = ref[0] != 'r' and 'r%u' % int(r) or r
self._git_svn_cache[ref] = ref2
self._git_svn_cache[ref2] = ref
if os.path.exists('.git/svn'):
r = self._git('svn', 'find-rev', ref)
assert r
self._git_cache[ref[0] != 'r' and 'r%u' % int(r) or r] = ref
else:
r = self._git('rev-list', '--topo-order', '--count', ref), ref
self._git_cache[ref] = r
return r
def getRevision(self, *path_list):
......@@ -177,14 +182,20 @@ class Updater(object):
if os.path.isdir('.git'):
# edit .git/info/sparse-checkout if you want sparse checkout
if revision:
h = self._git_find_rev('r' + revision)
if type(revision) is str:
h = self._git_find_rev('r' + revision)
else:
h = revision[1]
if h != self._git('rev-parse', 'HEAD'):
self.deletePycFiles('.')
self._git('reset', '--merge', h)
else:
self.deletePycFiles('.')
self._git('svn', 'rebase')
self.revision = str(int(self._git('svn', 'find-rev', 'HEAD')))
if os.path.exists('.git/svn'):
self._git('svn', 'rebase')
else:
self._git('pull', '--ff-only')
self.revision = self._git_find_rev(self._git('rev-parse', 'HEAD'))
elif os.path.isdir('.svn'):
# following code allows sparse checkout
def svn_mkdirs(path):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment