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): ...@@ -30,24 +30,25 @@ def format_command(*args, **kw):
cmdline.append(v) cmdline.append(v)
return ' '.join(cmdline) return ' '.join(cmdline)
def subprocess_capture(p): def subprocess_capture(p, quiet=False):
def readerthread(input, output, buffer): def readerthread(input, output, buffer):
while True: while True:
data = input.readline() data = input.readline()
if not data: if not data:
break break
output.write(data) output(data)
buffer.append(data) buffer.append(data)
if p.stdout: if p.stdout:
stdout = [] stdout = []
output = quiet and (lambda data: None) or sys.stdout.write
stdout_thread = threading.Thread(target=readerthread, stdout_thread = threading.Thread(target=readerthread,
args=(p.stdout, sys.stdout, stdout)) args=(p.stdout, output, stdout))
stdout_thread.setDaemon(True) stdout_thread.setDaemon(True)
stdout_thread.start() stdout_thread.start()
if p.stderr: if p.stderr:
stderr = [] stderr = []
stderr_thread = threading.Thread(target=readerthread, 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.setDaemon(True)
stderr_thread.start() stderr_thread.start()
if p.stdout: if p.stdout:
...@@ -106,7 +107,7 @@ class SubprocessError(EnvironmentError): ...@@ -106,7 +107,7 @@ class SubprocessError(EnvironmentError):
class Updater(object): class Updater(object):
_git_svn_cache = {} _git_cache = {}
realtime_output = True realtime_output = True
stdin = file(os.devnull) stdin = file(os.devnull)
...@@ -127,6 +128,7 @@ class Updater(object): ...@@ -127,6 +128,7 @@ class Updater(object):
raise raise
def spawn(self, *args, **kw): def spawn(self, *args, **kw):
quiet = kw.pop('quiet', False)
env = kw and dict(os.environ, **kw) or None env = kw and dict(os.environ, **kw) or None
command = format_command(*args, **kw) command = format_command(*args, **kw)
print '\n$ ' + command print '\n$ ' + command
...@@ -134,10 +136,11 @@ class Updater(object): ...@@ -134,10 +136,11 @@ class Updater(object):
p = subprocess.Popen(args, stdin=self.stdin, stdout=subprocess.PIPE, p = subprocess.Popen(args, stdin=self.stdin, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env) stderr=subprocess.PIPE, env=env)
if self.realtime_output: if self.realtime_output:
stdout, stderr = subprocess_capture(p) stdout, stderr = subprocess_capture(p, quiet)
else: else:
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
sys.stdout.write(stdout) if not quiet:
sys.stdout.write(stdout)
sys.stderr.write(stderr) sys.stderr.write(stderr)
result = dict(status_code=p.returncode, command=command, result = dict(status_code=p.returncode, command=command,
stdout=stdout, stderr=stderr) stdout=stdout, stderr=stderr)
...@@ -150,13 +153,15 @@ class Updater(object): ...@@ -150,13 +153,15 @@ class Updater(object):
def _git_find_rev(self, ref): def _git_find_rev(self, ref):
try: try:
return self._git_svn_cache[ref] return self._git_cache[ref]
except KeyError: except KeyError:
r = self._git('svn', 'find-rev', ref) if os.path.exists('.git/svn'):
assert r r = self._git('svn', 'find-rev', ref)
ref2 = ref[0] != 'r' and 'r%u' % int(r) or r assert r
self._git_svn_cache[ref] = ref2 self._git_cache[ref[0] != 'r' and 'r%u' % int(r) or r] = ref
self._git_svn_cache[ref2] = ref else:
r = self._git('rev-list', '--topo-order', '--count', ref), ref
self._git_cache[ref] = r
return r return r
def getRevision(self, *path_list): def getRevision(self, *path_list):
...@@ -177,14 +182,20 @@ class Updater(object): ...@@ -177,14 +182,20 @@ class Updater(object):
if os.path.isdir('.git'): if os.path.isdir('.git'):
# edit .git/info/sparse-checkout if you want sparse checkout # edit .git/info/sparse-checkout if you want sparse checkout
if revision: 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'): if h != self._git('rev-parse', 'HEAD'):
self.deletePycFiles('.') self.deletePycFiles('.')
self._git('reset', '--merge', h) self._git('reset', '--merge', h)
else: else:
self.deletePycFiles('.') self.deletePycFiles('.')
self._git('svn', 'rebase') if os.path.exists('.git/svn'):
self.revision = str(int(self._git('svn', 'find-rev', 'HEAD'))) 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'): elif os.path.isdir('.svn'):
# following code allows sparse checkout # following code allows sparse checkout
def svn_mkdirs(path): 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