[bugzilla-gnome-org-extensions] Add the "function line" to the top of each hunk



commit ee5cd6bdb63608343a9d2c70b8755ccae1de3b61
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sun Sep 13 13:04:38 2009 -0400

    Add the "function line" to the top of each hunk
    
    The "function line" is the text after the:
    
     @@ -I,J +K,L @@
    
    in a unified diff - by default with 'git diff' or 'diff -P' it's the previous
    line starting with '^[\w$]' which for C will likely include the name of
    the enclosing function. (Configurable with 'diff -F' or via .gitattributes.)
    
    Extract that when parsing hunks and show it in the hunk header.

 js/patch.js      |   12 ++++++------
 js/splinter.js   |    7 +++++--
 web/splinter.css |   15 ++++++++++++++-
 3 files changed, 25 insertions(+), 9 deletions(-)
---
diff --git a/js/patch.js b/js/patch.js
index b2384e5..31b5b28 100644
--- a/js/patch.js
+++ b/js/patch.js
@@ -45,12 +45,12 @@ const CHANGED       = 1 << 2; // Part of some other segmnet
 const NEW_NONEWLINE = 1 << 3; // Old line doesn't end with \n
 const OLD_NONEWLINE = 1 << 4; // New line doesn't end with \n
 
-function Hunk(oldStart, oldCount, newStart, newCount, text) {
-    this._init(oldStart, oldCount, newStart, newCount, text);
+function Hunk(oldStart, oldCount, newStart, newCount, functionLine, text) {
+    this._init(oldStart, oldCount, newStart, newCount, functionLine, text);
 }
 
 Hunk.prototype = {
-    _init : function(oldStart, oldCount, newStart, newCount, text) {
+    _init : function(oldStart, oldCount, newStart, newCount, functionLine, text) {
         var rawlines = text.split("\n");
         if (rawlines.length > 0 && Utils.strip(rawlines[rawlines.length - 1]) == "")
             rawlines.pop(); // Remove trailing element from final \n
@@ -59,6 +59,7 @@ Hunk.prototype = {
         this.oldCount = oldCount;
         this.newStart = newStart;
         this.newCount = newCount;
+        this.functionLine = Utils.strip(functionLine);
         this.comment = null;
 
         var lines = [];
@@ -243,7 +244,7 @@ const FILE_START_RE = /^(?:(?:Index|index|===|RCS|diff).*\n)*---[ \t]*(\S+).*\n\
 
 // Hunk start: @@ -23,12 +30,11 @@
 // Followed by: lines beginning with [ +\-]
-const HUNK_RE = /^@@[ \t]+-(\d+),(\d+)[ \t]+\+(\d+),(\d+)[ \t]+@@.*\n((?:[ +\\-].*\n)*)/mg;
+const HUNK_RE = /^@@[ \t]+-(\d+),(\d+)[ \t]+\+(\d+),(\d+)[ \t]+@@(.*)\n((?:[ +\\-].*\n)*)/mg;
 
 function Patch(text) {
     this._init(text);
@@ -286,8 +287,7 @@ Patch.prototype = {
                 var newStart = parseInt(m2[3]);
                 var newCount = parseInt(m2[4]);
 
-                var hunk = new Hunk(oldStart, oldCount, newStart, newCount, m2[5]);
-                hunks.push(new Hunk(oldStart, oldCount, newStart, newCount, m2[5]));
+                hunks.push(new Hunk(oldStart, oldCount, newStart, newCount, m2[5], m2[6]));
             }
 
             this.files.push(new File(filename, hunks));
diff --git a/js/splinter.js b/js/splinter.js
index db1fbee..92bcb64 100644
--- a/js/splinter.js
+++ b/js/splinter.js
@@ -343,8 +343,11 @@ function addPatchFile(file) {
         var hunk = file.hunks[i];
         var hunkHeader = EL("tr", "hunk-header");
         tbody.appendChild(hunkHeader);
-        var hunkCell = EL("td", "hunk-cell",
-                          "Lines " + hunk.oldStart + "-" + (hunk.oldStart + hunk.oldCount - 1));
+        var hunkCell = EL("td", "hunk-cell");
+        hunkCell.appendChild(EL("div", "hunk-lines",
+                                "Lines " + hunk.oldStart + "-" + (hunk.oldStart + hunk.oldCount - 1)));
+        if (hunk.functionLine)
+            hunkCell.appendChild(EL("div", "hunk-function-line", hunk.functionLine));
         hunkCell.colSpan = 3;
         hunkHeader.appendChild(hunkCell);
 
diff --git a/web/splinter.css b/web/splinter.css
index 036f965..2c366ff 100644
--- a/web/splinter.css
+++ b/web/splinter.css
@@ -156,11 +156,24 @@ body {
 }
 
 .hunk-header {
-    color: red;
     border: 1px solid black;
     background: #dddddd;
 }
 
+.hunk-cell {
+    padding: 2px;
+}
+
+.hunk-lines {
+    color: red;
+    float: left;
+}
+
+.hunk-function-line {
+    float: left;
+    margin-left: 2em;
+}
+
 .old-line, .new-line {
     white-space: pre;
     font-family: "DejaVu Sans Mono", monospace;


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