git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC 3/4] gitk: Refactor getblobdiffline to split off adddiffline

From
Steffen Prohaska <prohaska@zib.de>
Date
Dec 15, 2007, 16:51 UTC
Message-ID
<11977375051617-git-send-email-prohaska@zib.de>
In-Reply-To
<1197737505599-git-send-email-prohaska@zib.de>

getblobdiffline used to read from a file descriptor, parsed the line read, and displayed the line nicely formatted.

Parsing and displaying the line is split off to a separate function adddiffline.

---
 gitk-git/gitk |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index ca121e4..3c4ec03 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -5324,18 +5324,11 @@ proc makediffhdr {fname ids} {
     $ctext insert $curdiffstart "$pad $fname $pad" filesep
 }
 
-proc getblobdiffline {bdf ids} {
+proc adddiffline {line ids} {
     global diffids blobdifffd ctext curdiffstart
     global diffnexthead diffnextnote difffilestart
     global diffinhdr treediffs
 
-    set nr 0
-    $ctext conf -state normal
-    while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
-	if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
-	    close $bdf
-	    return 0
-	}
 	if {![string compare -length 11 "diff --git " $line]} {
 	    # trim off "diff --git "
 	    set line [string range $line 11 end]
@@ -5357,7 +5350,7 @@ proc getblobdiffline {bdf ids} {
 	    if {!(($l & 1) && [string index $line $i] eq " " &&
 		  [string range $line 2 [expr {$i - 1}]] eq \
 		      [string range $line [expr {$i + 3}] end])} {
-		continue
+		return
 	    }
 	    # unescape if quoted and chop off the a/ from the front
 	    if {[string index $line 0] eq "\""} {
@@ -5391,10 +5384,10 @@ proc getblobdiffline {bdf ids} {
 		makediffhdr $fname $ids
 	    } elseif {[string compare -length 3 $line "---"] == 0} {
 		# do nothing
-		continue
+		return
 	    } elseif {[string compare -length 3 $line "+++"] == 0} {
 		set diffinhdr 0
-		continue
+		return
 	    }
 	    $ctext insert end "$line\n" filesep
 
@@ -5411,6 +5404,21 @@ proc getblobdiffline {bdf ids} {
 		$ctext insert end "$line\n" hunksep
 	    }
 	}
+}
+
+proc getblobdiffline {bdf ids} {
+    global diffids blobdifffd ctext curdiffstart
+    global diffnexthead diffnextnote difffilestart
+    global diffinhdr treediffs
+
+    set nr 0
+    $ctext conf -state normal
+    while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
+	if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
+	    close $bdf
+	    return 0
+	}
+	adddiffline $line $ids
     }
     $ctext conf -state disabled
     if {[eof $bdf]} {
-- 
1.5.4.rc0.37.geff3a-dirty
Previous: Steffen ProhaskaNext: Steffen Prohaska
Message 3 of 8 in “[RFC 1/4] Add diff-diff, which compares the diffs of two commits”
  1. Steffen ProhaskaDec 15, 2007
  2. 2/4 gitk: Add diff-diff supportSteffen Prohaska, Dec 15, 2007
  3. 3/4 gitk: Refactor getblobdiffline to split off adddifflineSteffen Prohaska, Dec 15, 2007
  4. 4/4 gitk: Use adddiffline to nicely format diff-diffSteffen Prohaska, Dec 15, 2007
  5. Johannes SchindelinDec 15, 2007
  6. Björn SteinbrinkDec 15, 2007
  7. Steffen ProhaskaDec 15, 2007
  8. Junio C HamanoDec 15, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.