[pypy-svn] buildbot default: switch from diff per file to diff per commit, gives a speed boost and directory rename implication

RonnyPfannschmidt commits-noreply at bitbucket.org
Mon May 2 23:23:36 CEST 2011


Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch: 
Changeset: r498:4390f9be94d8
Date: 2011-05-02 23:22 +0200
http://bitbucket.org/pypy/buildbot/changeset/4390f9be94d8/

Log:	switch from diff per file to diff per commit, gives a speed boost
	and directory rename implication

diff --git a/bitbucket_hook/scm.py b/bitbucket_hook/scm.py
--- a/bitbucket_hook/scm.py
+++ b/bitbucket_hook/scm.py
@@ -19,18 +19,25 @@
     return unicode(stdout, encoding='utf-8', errors='replace')
 
 
-def get_diff(local_repo, hgid, files):
-    import re
-    binary = re.compile('^GIT binary patch$', re.MULTILINE)
-    files = [item['file'] for item in files]
+def get_diff(local_repo, hgid):
+    out = hg('-R', local_repo, 'diff', '--git', '-c', hgid)
+    out = out.splitlines(True)
+    out_iter = iter(out)
     lines = []
-    for filename in files:
-        out = hg('-R', local_repo, 'diff', '--git', '-c', hgid,
-                      local_repo.join(filename))
-        match = binary.search(out)
-        if match:
-            # it's a binary patch, omit the content
-            out = out[:match.end()]
-            out += u'\n[cut]'
-        lines.append(out)
-    return u'\n'.join(lines)
+    for line in out_iter:
+        lines.append(line)
+        if line == 'GIT binary patch\n':
+            out_iter.next()  # discard literal line
+            lines.append('\n[cut]\n')
+
+            for item in out_iter:
+                if item[0]!='z':
+                    break  # binary patches end with a empty line
+
+
+    return u''.join(lines)
+
+
+if __name__=='__main__':
+    # needs the pypy repo
+    print get_diff(sys.argv[1], '426be91e82b0f91b09a028993d2364f1d62f1615').encode('utf-8')

diff --git a/bitbucket_hook/mail.py b/bitbucket_hook/mail.py
--- a/bitbucket_hook/mail.py
+++ b/bitbucket_hook/mail.py
@@ -31,7 +31,7 @@
     subject = '%s %s: %s' % (reponame, commit['branch'], line0)
     body = scm.hg('-R', local_repo, 'log', '-r', hgid,
              '--template', template)
-    diff = scm.get_diff(local_repo, hgid, commit['files'])
+    diff = scm.get_diff(local_repo, hgid)
     body = body + diff
     send(sender, app.config['ADDRESS'], subject, body, test)
 


More information about the Pypy-commit mailing list