[extensions-web] review: Stuff the insert/delete fake chunks in diffutils



commit 88f5ac1afd8975f8ebe15074c42e24dc43c929a7
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Jun 26 13:31:23 2012 -0400

    review: Stuff the insert/delete fake chunks in diffutils

 sweettooth/review/diffutils.py |   32 ++++++++++++++++++++++----------
 sweettooth/review/views.py     |   15 ---------------
 2 files changed, 22 insertions(+), 25 deletions(-)
---
diff --git a/sweettooth/review/diffutils.py b/sweettooth/review/diffutils.py
index 3f40072..0bfd213 100644
--- a/sweettooth/review/diffutils.py
+++ b/sweettooth/review/diffutils.py
@@ -743,6 +743,22 @@ def get_line_changed_regions(oldline, newline):
 
     return (oldchanges, newchanges)
 
+def new_chunk(lines, collapsable=False, tag='equal', meta=None):
+    if not meta:
+        meta = {}
+
+    return {
+        'lines': lines,
+        'change': tag,
+        'collapsable': collapsable,
+        'meta': meta,
+    }
+
+def get_fake_chunk(numlines, tag):
+    linenums = xrange(numlines)
+    lines = [[n+1, n+1, n+1, [], []] for n in linenums]
+    return new_chunk(lines, tag=tag)
+
 def get_chunks(a, b):
     def diff_line(vlinenum, oldlinenum, newlinenum, oldline, newline):
         # This function accesses the variable meta, defined in an outer context.
@@ -762,16 +778,12 @@ def get_chunks(a, b):
 
         return result
 
-    def new_chunk(lines, collapsable=False, tag='equal', meta=None):
-        if not meta:
-            meta = {}
-
-        return {
-            'lines': lines,
-            'change': tag,
-            'collapsable': collapsable,
-            'meta': meta,
-        }
+    if a is None or b is None:
+        if a is not None:
+            yield get_fake_chunk(len(a), tag='delete')
+        if b is not None:
+            yield get_fake_chunk(len(b), tag='insert')
+        return
 
     a_num_lines = len(a)
     b_num_lines = len(b)
diff --git a/sweettooth/review/views.py b/sweettooth/review/views.py
index f2600f0..10e9bde 100644
--- a/sweettooth/review/views.py
+++ b/sweettooth/review/views.py
@@ -120,26 +120,11 @@ def grab_lines(zipfile, filename):
         f.close()
         return content.splitlines()
 
-def get_fake_chunks(numlines, tag):
-    # When a file is added/deleted, we want to show a view where
-    # we have nothing in one pane, and a bunch of inserted/delted
-    # lines in the other.
-    lines = [[n, n, n, [], []] for n in range(1, numlines + 1)]
-    return [{ 'lines': lines,
-              'numlines': numlines,
-              'change': tag,
-              'collapsable': False,
-              'meta': None }]
-
 def get_diff(old_zipfile, new_zipfile, filename):
     oldlines, newlines = grab_lines(old_zipfile, filename), grab_lines(new_zipfile, filename)
 
     if oldlines == newlines:
         return None
-    if oldlines is None:
-        return get_fake_chunks(len(newlines), 'insert')
-    if newlines is None:
-        return get_fake_chunks(len(oldlines), 'delete')
 
     chunks = list(get_chunks(oldlines, newlines))
     return dict(chunks=chunks,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]