[gitg] Coalesce multiple added/removed lines in patch set



commit 1151d764f7eb3d5d29c2138e823cdfa4037ba5a7
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Tue Dec 31 17:09:22 2013 +0100

    Coalesce multiple added/removed lines in patch set

 libgitg/resources/diff-view.js |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/libgitg/resources/diff-view.js b/libgitg/resources/diff-view.js
index 364e986..36ea92a 100644
--- a/libgitg/resources/diff-view.js
+++ b/libgitg/resources/diff-view.js
@@ -191,6 +191,8 @@ function prepare_patchset(filediv)
        var a = "a".charCodeAt(0);
        var r = "r".charCodeAt(0);
 
+       var last = null;
+
        while (elem != null)
        {
                var e = elem;
@@ -210,8 +212,18 @@ function prepare_patchset(filediv)
 
                if (selected)
                {
-                       // [sign, old_offset, new_offset, length]
-                       patches.push([added ? a : r, offset + doffset, offset, length]);
+                       var tp = added ? a : r;
+
+                       if (last != null && last[0] == tp && last[2] + last[3] == offset)
+                       {
+                               last[3] += length;
+                       }
+                       else
+                       {
+                               // [sign, old_offset, new_offset, length]
+                               last = [tp, offset + doffset, offset, length];
+                               patches.push(last);
+                       }
 
                        doffset += added ? -length : length;
                }


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