a9a6bf62224c

api: handle diffs with no content (adds, removes, etc)
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 20 Jul 2010 18:27:53 -0400
parents 79f123993c81
children fcdbab575d22
branches/tags (none)
files review/api.py

Changes

--- a/review/api.py	Tue Jul 20 18:27:47 2010 -0400
+++ b/review/api.py	Tue Jul 20 18:27:53 2010 -0400
@@ -539,7 +539,11 @@
 
             # the second is the diff's contents, which is what we want,
             # minus the header
-            diffs[filename] = '\n'.join(d.next().splitlines()[3:])
+            try:
+                diffs[filename] = '\n'.join(d.next().splitlines()[3:])
+            except StopIteration:
+                # This is an add, remove, or something else without a diff body.
+                diffs[filename] = None
 
         return diffs
 
@@ -588,11 +592,14 @@
                     yield (n, line)
 
         for filename, content in ds.iteritems():
-            content = content.splitlines()
-            ds[filename] = {
-                'max': len(content) - 1,
-                'content': list(_filter_diff(content)),
-            }
+            if content:
+                content = content.splitlines()
+                ds[filename] = {
+                    'max': len(content) - 1,
+                    'content': list(_filter_diff(content)),
+                }
+            else:
+                ds[filename] = {'max': None, 'content': []}
 
         return ds