diffstatdata: no longer a generator
authorMatt Mackall <mpm@selenic.com>
Sat, 21 May 2011 15:01:28 -0500
changeset 14400 cd1ca2556cac
parent 14399 71938479eff9
child 14401 7bb7be1c1385
diffstatdata: no longer a generator This produces a smallish amount of data and all consumers needed to buffer it anyway.
mercurial/patch.py
--- a/mercurial/patch.py	Wed May 18 21:31:40 2011 +0200
+++ b/mercurial/patch.py	Sat May 21 15:01:28 2011 -0500
@@ -1684,12 +1684,17 @@
 def diffstatdata(lines):
     diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$')
 
+    results = []
     filename, adds, removes = None, 0, 0
+
+    def addresult():
+        if filename:
+            isbinary = adds == 0 and removes == 0
+            results.append((filename, adds, removes, isbinary))
+
     for line in lines:
         if line.startswith('diff'):
-            if filename:
-                isbinary = adds == 0 and removes == 0
-                yield (filename, adds, removes, isbinary)
+            addresult()
             # set numbers to 0 anyway when starting new file
             adds, removes = 0, 0
             if line.startswith('diff --git'):
@@ -1701,9 +1706,8 @@
             adds += 1
         elif line.startswith('-') and not line.startswith('---'):
             removes += 1
-    if filename:
-        isbinary = adds == 0 and removes == 0
-        yield (filename, adds, removes, isbinary)
+    addresult()
+    return results
 
 def diffstat(lines, width=80, git=False):
     output = []