From be3c276b93b646269d0402946a4ed144a47f75cb Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Fri, 9 Sep 2011 16:08:21 +0200
Subject: [PATCH] Update test_bot after migration to Git

---
 tools/test_bot | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/tools/test_bot b/tools/test_bot
index b2385306..47198e25 100755
--- a/tools/test_bot
+++ b/tools/test_bot
@@ -1,6 +1,5 @@
 #!/usr/bin/python
 import os, subprocess, sys, time
-import pysvn
 
 def clean():
     for path, dir_list, file_list in os.walk('.'):
@@ -9,6 +8,26 @@ def clean():
             if file[-4:] in ('.pyc', '.pyo'):
                 os.remove(os.path.join(path, file))
 
+class GitError(EnvironmentError):
+    def __init__(self, err, out, returncode):
+        EnvironmentError.__init__(self, err)
+        self.stdout = out
+        self.returncode = returncode
+
+def _git(*args, **kw):
+    p = subprocess.Popen(('git',) + args, **kw)
+    out, err = p.communicate()
+    if p.returncode:
+        raise GitError(err, out, p.returncode)
+    return out
+
+def git(*args, **kw):
+    out = _git(stdout=subprocess.PIPE, stderr=subprocess.PIPE, *args, **kw)
+    return out.strip()
+
+def getRevision(*path):
+    return git('log', '-1', '--format=%H', '--', *path)
+
 def main():
     if 'LANG' in os.environ:
       del os.environ['LANG']
@@ -21,10 +40,7 @@ def main():
             break
         arg_count += '=' in arg and 1 or 2
 
-    svn = pysvn.Client()
-    def getRevision(path):
-        return svn.info(path).commit_revision.number
-
+    branch = git('rev-parse', '--abbrev-ref', 'HEAD')
     test_bot = os.path.realpath(__file__).split(os.getcwd())[1][1:]
     test_bot_revision = getRevision(test_bot)
     revision = 0
@@ -35,10 +51,11 @@ def main():
         delay = delay and time.sleep(delay) or 1800
         old_revision = revision
         try:
-            svn.update('.')
-        except pysvn.ClientError, e:
+            _git('fetch')
+            _git('reset', '--merge', '@{u}')
+        except GitError, e:
             continue
-        revision = getRevision('.')
+        revision = getRevision()
         if revision == old_revision:
             continue
         if test_bot_revision != getRevision(test_bot):
@@ -50,7 +67,9 @@ def main():
             bin = os.path.join(test_home, 'bin')
             if not subprocess.call((os.path.join(bin, 'buildout'), '-v'),
                                    cwd=test_home):
-                title = '(r%u-%s)' % (revision, os.path.basename(test_home))
+                title = '[%s:%s-g%s:%s]' % (branch,
+                  git('rev-list', '--topo-order', '--count', revision),
+                  revision[:7], os.path.basename(test_home))
                 if tests:
                     subprocess.call([os.path.join(bin, 'neotestrunner'),
                                      '-' + tests, '--title',
-- 
2.30.9