Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
gitk: more aggressive space ignoring
From cd696bc74d369ac5c3a61a93afd327cddd57adf3 Mon Sep 17 00:00:00 2001
From: Max Kirillov <max@max630.net>
Date: Sat, 20 Apr 2013 18:26:31 +0300
Subject: [PATCH 1/3] gitk refactor: split getblobdiffline into IO and text
handling
I would like to hack into diffs which gitk gets from commands.
To ease it, let's divide the read handler, getblobdiffline,
into reading and subsequent handling.
Now the function named getblobdiffline performs only IO,
and other functionality moved to getblobdiffline_line and
getblobdiffline_end. Also getblobdiffline_close is introduced,
though currently it is empty.
---
gitk-git/gitk | 422 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 220 insertions(+), 202 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index b3706fc..140da31 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -7769,226 +7769,244 @@ proc makediffhdr {fname ids} {
set diffline 0
}
-proc getblobdiffline {bdf ids} {
- global diffids blobdifffd ctext curdiffstart
+proc getblobdiffline_line {line ids seehere_name} {
+ global ctext curdiffstart
global diffnexthead diffnextnote difffilestart
global ctext_file_names ctext_file_lines
global diffinhdr treediffs mergemax diffnparents
global diffencoding jump_to_here targetline diffline currdiffsubmod
global worddiff
+ upvar 1 $seehere_name seehere
+
+ if {![string compare -length 5 "diff " $line]} {
+ if {![regexp {^diff (--cc|--git) } $line m type]} {
+ set line [encoding convertfrom $line]
+ $ctext insert end "$line\n" hunksep
+ return -code continue
+ }
+ # start of a new file
+ set diffinhdr 1
+ $ctext insert end "\n"
+ set curdiffstart [$ctext index "end - 1c"]
+ lappend ctext_file_names ""
+ lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
+ $ctext insert end "\n" filesep
+
+ if {$type eq "--cc"} {
+ # start of a new file in a merge diff
+ set fname [string range $line 10 end]
+ if {[lsearch -exact $treediffs($ids) $fname] < 0} {
+ lappend treediffs($ids) $fname
+ add_flist [list $fname]
+ }
+
+ } else {
+ set line [string range $line 11 end]
+ # If the name hasn't changed the length will be odd,
+ # the middle char will be a space, and the two bits either
+ # side will be a/name and b/name, or "a/name" and "b/name".
+ # If the name has changed we'll get "rename from" and
+ # "rename to" or "copy from" and "copy to" lines following
+ # this, and we'll use them to get the filenames.
+ # This complexity is necessary because spaces in the
+ # filename(s) don't get escaped.
+ set l [string length $line]
+ set i [expr {$l / 2}]
+ if {!(($l & 1) && [string index $line $i] eq " " &&
+ [string range $line 2 [expr {$i - 1}]] eq \
+ [string range $line [expr {$i + 3}] end])} {
+ return -code continue
+ }
+ # unescape if quoted and chop off the a/ from the front
+ if {[string index $line 0] eq "\""} {
+ set fname [string range [lindex $line 0] 2 end]
+ } else {
+ set fname [string range $line 2 [expr {$i - 1}]]
+ }
+ }
+ makediffhdr $fname $ids
+
+ } elseif {![string compare -length 16 "* Unmerged path " $line]} {
+ set fname [encoding convertfrom [string range $line 16 end]]
+ $ctext insert end "\n"
+ set curdiffstart [$ctext index "end - 1c"]
+ lappend ctext_file_names $fname
+ lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
+ $ctext insert end "$line\n" filesep
+ set i [lsearch -exact $treediffs($ids) $fname]
+ if {$i >= 0} {
+ setinlist difffilestart $i $curdiffstart
+ }
+
+ } elseif {![string compare -length 2 "@@" $line]} {
+ regexp {^@@+} $line ats
+ set line [encoding convertfrom $diffencoding $line]
+ $ctext insert end "$line\n" hunksep
+ if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
+ set diffline $nl
+ }
+ set diffnparents [expr {[string length $ats] - 1}]
+ set diffinhdr 0
+
+ } elseif {![string compare -length 10 "Submodule " $line]} {
+ # start of a new submodule
+ if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
+ set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
+ } else {
+ set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
+ }
+ if {$currdiffsubmod != $fname} {
+ $ctext insert end "\n"; # Add newline after commit message
+ }
+ set curdiffstart [$ctext index "end - 1c"]
+ lappend ctext_file_names ""
+ if {$currdiffsubmod != $fname} {
+ lappend ctext_file_lines $fname
+ makediffhdr $fname $ids
+ set currdiffsubmod $fname
+ $ctext insert end "\n$line\n" filesep
+ } else {
+ $ctext insert end "$line\n" filesep
+ }
+ } elseif {![string compare -length 3 " >" $line]} {
+ set $currdiffsubmod ""
+ set line [encoding convertfrom $diffencoding $line]
+ $ctext insert end "$line\n" dresult
+ } elseif {![string compare -length 3 " <" $line]} {
+ set $currdiffsubmod ""
+ set line [encoding convertfrom $diffencoding $line]
+ $ctext insert end "$line\n" d0
+ } elseif {$diffinhdr} {
+ if {![string compare -length 12 "rename from " $line]} {
+ set fname [string range $line [expr 6 + [string first " from " $line] ] end]
+ if {[string index $fname 0] eq "\""} {
+ set fname [lindex $fname 0]
+ }
+ set fname [encoding convertfrom $fname]
+ set i [lsearch -exact $treediffs($ids) $fname]
+ if {$i >= 0} {
+ setinlist difffilestart $i $curdiffstart
+ }
+ } elseif {![string compare -length 10 $line "rename to "] ||
+ ![string compare -length 8 $line "copy to "]} {
+ set fname [string range $line [expr 4 + [string first " to " $line] ] end]
+ if {[string index $fname 0] eq "\""} {
+ set fname [lindex $fname 0]
+ }
+ makediffhdr $fname $ids
+ } elseif {[string compare -length 3 $line "---"] == 0} {
+ # do nothing
+ return -code continue
+ } elseif {[string compare -length 3 $line "+++"] == 0} {
+ set diffinhdr 0
+ return -code continue
+ }
+ $ctext insert end "$line\n" filesep
+
+ } else {
+ set line [string map {\x1A ^Z} \
+ [encoding convertfrom $diffencoding $line]]
+ # parse the prefix - one ' ', '-' or '+' for each parent
+ set prefix [string range $line 0 [expr {$diffnparents - 1}]]
+ set tag [expr {$diffnparents > 1? "m": "d"}]
+ set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
+ set words_pre_markup ""
+ set words_post_markup ""
+ if {[string trim $prefix " -+"] eq {}} {
+ # prefix only has " ", "-" and "+" in it: normal diff line
+ set num [string first "-" $prefix]
+ if {$dowords} {
+ set line [string range $line 1 end]
+ }
+ if {$num >= 0} {
+ # removed line, first parent with line is $num
+ if {$num >= $mergemax} {
+ set num "max"
+ }
+ if {$dowords && $worddiff eq [mc "Markup words"]} {
+ $ctext insert end "\[-$line-\]" $tag$num
+ } else {
+ $ctext insert end "$line" $tag$num
+ }
+ if {!$dowords} {
+ $ctext insert end "\n" $tag$num
+ }
+ } else {
+ set tags {}
+ if {[string first "+" $prefix] >= 0} {
+ # added line
+ lappend tags ${tag}result
+ if {$diffnparents > 1} {
+ set num [string first " " $prefix]
+ if {$num >= 0} {
+ if {$num >= $mergemax} {
+ set num "max"
+ }
+ lappend tags m$num
+ }
+ }
+ set words_pre_markup "{+"
+ set words_post_markup "+}"
+ }
+ if {$targetline ne {}} {
+ if {$diffline == $targetline} {
+ set seehere [$ctext index "end - 1 chars"]
+ set targetline {}
+ } else {
+ incr diffline
+ }
+ }
+ if {$dowords && $worddiff eq [mc "Markup words"]} {
+ $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
+ } else {
+ $ctext insert end "$line" $tags
+ }
+ if {!$dowords} {
+ $ctext insert end "\n" $tags
+ }
+ }
+ } elseif {$dowords && $prefix eq "~"} {
+ $ctext insert end "\n" {}
+ } else {
+ # "\ No newline at end of file",
+ # or something else we don't recognize
+ $ctext insert end "$line\n" hunksep
+ }
+ }
+}
+
+proc getblobdiffline_end {is_eof seehere_name} {
+ upvar 1 $seehere_name seehere
+
+ if {[info exists seehere]} {
+ mark_ctext_line [lindex [split $seehere .] 0]
+ }
+ maybe_scroll_ctext $is_eof
+}
+
+proc getblobdiffline_close {} {
+}
+
+proc getblobdiffline {bdf ids} {
+ global diffids ctext blobdifffd
set nr 0
$ctext conf -state normal
while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
catch {close $bdf}
+ getblobdiffline_close
return 0
}
- if {![string compare -length 5 "diff " $line]} {
- if {![regexp {^diff (--cc|--git) } $line m type]} {
- set line [encoding convertfrom $line]
- $ctext insert end "$line\n" hunksep
- continue
- }
- # start of a new file
- set diffinhdr 1
- $ctext insert end "\n"
- set curdiffstart [$ctext index "end - 1c"]
- lappend ctext_file_names ""
- lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
- $ctext insert end "\n" filesep
-
- if {$type eq "--cc"} {
- # start of a new file in a merge diff
- set fname [string range $line 10 end]
- if {[lsearch -exact $treediffs($ids) $fname] < 0} {
- lappend treediffs($ids) $fname
- add_flist [list $fname]
- }
-
- } else {
- set line [string range $line 11 end]
- # If the name hasn't changed the length will be odd,
- # the middle char will be a space, and the two bits either
- # side will be a/name and b/name, or "a/name" and "b/name".
- # If the name has changed we'll get "rename from" and
- # "rename to" or "copy from" and "copy to" lines following
- # this, and we'll use them to get the filenames.
- # This complexity is necessary because spaces in the
- # filename(s) don't get escaped.
- set l [string length $line]
- set i [expr {$l / 2}]
- if {!(($l & 1) && [string index $line $i] eq " " &&
- [string range $line 2 [expr {$i - 1}]] eq \
- [string range $line [expr {$i + 3}] end])} {
- continue
- }
- # unescape if quoted and chop off the a/ from the front
- if {[string index $line 0] eq "\""} {
- set fname [string range [lindex $line 0] 2 end]
- } else {
- set fname [string range $line 2 [expr {$i - 1}]]
- }
- }
- makediffhdr $fname $ids
-
- } elseif {![string compare -length 16 "* Unmerged path " $line]} {
- set fname [encoding convertfrom [string range $line 16 end]]
- $ctext insert end "\n"
- set curdiffstart [$ctext index "end - 1c"]
- lappend ctext_file_names $fname
- lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
- $ctext insert end "$line\n" filesep
- set i [lsearch -exact $treediffs($ids) $fname]
- if {$i >= 0} {
- setinlist difffilestart $i $curdiffstart
- }
-
- } elseif {![string compare -length 2 "@@" $line]} {
- regexp {^@@+} $line ats
- set line [encoding convertfrom $diffencoding $line]
- $ctext insert end "$line\n" hunksep
- if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
- set diffline $nl
- }
- set diffnparents [expr {[string length $ats] - 1}]
- set diffinhdr 0
-
- } elseif {![string compare -length 10 "Submodule " $line]} {
- # start of a new submodule
- if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
- set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
- } else {
- set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
- }
- if {$currdiffsubmod != $fname} {
- $ctext insert end "\n"; # Add newline after commit message
- }
- set curdiffstart [$ctext index "end - 1c"]
- lappend ctext_file_names ""
- if {$currdiffsubmod != $fname} {
- lappend ctext_file_lines $fname
- makediffhdr $fname $ids
- set currdiffsubmod $fname
- $ctext insert end "\n$line\n" filesep
- } else {
- $ctext insert end "$line\n" filesep
- }
- } elseif {![string compare -length 3 " >" $line]} {
- set $currdiffsubmod ""
- set line [encoding convertfrom $diffencoding $line]
- $ctext insert end "$line\n" dresult
- } elseif {![string compare -length 3 " <" $line]} {
- set $currdiffsubmod ""
- set line [encoding convertfrom $diffencoding $line]
- $ctext insert end "$line\n" d0
- } elseif {$diffinhdr} {
- if {![string compare -length 12 "rename from " $line]} {
- set fname [string range $line [expr 6 + [string first " from " $line] ] end]
- if {[string index $fname 0] eq "\""} {
- set fname [lindex $fname 0]
- }
- set fname [encoding convertfrom $fname]
- set i [lsearch -exact $treediffs($ids) $fname]
- if {$i >= 0} {
- setinlist difffilestart $i $curdiffstart
- }
- } elseif {![string compare -length 10 $line "rename to "] ||
- ![string compare -length 8 $line "copy to "]} {
- set fname [string range $line [expr 4 + [string first " to " $line] ] end]
- if {[string index $fname 0] eq "\""} {
- set fname [lindex $fname 0]
- }
- makediffhdr $fname $ids
- } elseif {[string compare -length 3 $line "---"] == 0} {
- # do nothing
- continue
- } elseif {[string compare -length 3 $line "+++"] == 0} {
- set diffinhdr 0
- continue
- }
- $ctext insert end "$line\n" filesep
-
- } else {
- set line [string map {\x1A ^Z} \
- [encoding convertfrom $diffencoding $line]]
- # parse the prefix - one ' ', '-' or '+' for each parent
- set prefix [string range $line 0 [expr {$diffnparents - 1}]]
- set tag [expr {$diffnparents > 1? "m": "d"}]
- set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
- set words_pre_markup ""
- set words_post_markup ""
- if {[string trim $prefix " -+"] eq {}} {
- # prefix only has " ", "-" and "+" in it: normal diff line
- set num [string first "-" $prefix]
- if {$dowords} {
- set line [string range $line 1 end]
- }
- if {$num >= 0} {
- # removed line, first parent with line is $num
- if {$num >= $mergemax} {
- set num "max"
- }
- if {$dowords && $worddiff eq [mc "Markup words"]} {
- $ctext insert end "\[-$line-\]" $tag$num
- } else {
- $ctext insert end "$line" $tag$num
- }
- if {!$dowords} {
- $ctext insert end "\n" $tag$num
- }
- } else {
- set tags {}
- if {[string first "+" $prefix] >= 0} {
- # added line
- lappend tags ${tag}result
- if {$diffnparents > 1} {
- set num [string first " " $prefix]
- if {$num >= 0} {
- if {$num >= $mergemax} {
- set num "max"
- }
- lappend tags m$num
- }
- }
- set words_pre_markup "{+"
- set words_post_markup "+}"
- }
- if {$targetline ne {}} {
- if {$diffline == $targetline} {
- set seehere [$ctext index "end - 1 chars"]
- set targetline {}
- } else {
- incr diffline
- }
- }
- if {$dowords && $worddiff eq [mc "Markup words"]} {
- $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
- } else {
- $ctext insert end "$line" $tags
- }
- if {!$dowords} {
- $ctext insert end "\n" $tags
- }
- }
- } elseif {$dowords && $prefix eq "~"} {
- $ctext insert end "\n" {}
- } else {
- # "\ No newline at end of file",
- # or something else we don't recognize
- $ctext insert end "$line\n" hunksep
- }
- }
+ getblobdiffline_line $line $ids seehere
}
- if {[info exists seehere]} {
- mark_ctext_line [lindex [split $seehere .] 0]
- }
- maybe_scroll_ctext [eof $bdf]
- $ctext conf -state disabled
+ getblobdiffline_end [eof $bdf] seehere
if {[eof $bdf]} {
catch {close $bdf}
+ getblobdiffline_close
return 0
}
+ $ctext conf -state disabled
return [expr {$nr >= 1000? 2: 1}]
}
--
1.8.2.rc0
From 144c033d734ad16c00a88e3a19deed73f60c7f07 Mon Sep 17 00:00:00 2001
From: Max Kirillov <max@max630.net>
Date: Sat, 20 Apr 2013 22:09:12 +0300
Subject: [PATCH 2/3] gitk refactor: add getblobdiffline_proxy_* commands
Now actually add the commands which is going to perform
substitutions in input data. Currently they only pass data,
but let's go further.
---
gitk-git/gitk | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 140da31..b9955ed 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -7987,6 +7987,27 @@ proc getblobdiffline_end {is_eof seehere_name} {
proc getblobdiffline_close {} {
}
+proc getblobdiffline_proxy_line {line ids seehere_name} {
+ upvar 1 $seehere_name seehere
+
+ set ret [catch {getblobdiffline_line $line $ids seehere} result options]
+ case [dict get $options -code] {
+ 0 { return $ret }
+ 4 { return -code continue }
+ default { error [list Unexpected: $ret $result $options] }
+ }
+}
+
+proc getblobdiffline_proxy_end {is_eof seehere_name} {
+ upvar 1 $seehere_name seehere
+
+ getblobdiffline_end $is_eof seehere
+}
+
+proc getblobdiffline_proxy_close {} {
+ getblobdiffline_close
+}
+
proc getblobdiffline {bdf ids} {
global diffids ctext blobdifffd
@@ -7995,15 +8016,15 @@ proc getblobdiffline {bdf ids} {
while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
catch {close $bdf}
- getblobdiffline_close
+ getblobdiffline_proxy_close
return 0
}
- getblobdiffline_line $line $ids seehere
+ getblobdiffline_proxy_line $line $ids seehere
}
- getblobdiffline_end [eof $bdf] seehere
+ getblobdiffline_proxy_end [eof $bdf] seehere
if {[eof $bdf]} {
catch {close $bdf}
- getblobdiffline_close
+ getblobdiffline_proxy_close
return 0
}
$ctext conf -state disabled
--
1.8.2.rc0
From 5a57b496f28ea8a67a555616ab5002be2c877112 Mon Sep 17 00:00:00 2001
From: Max Kirillov <max@max630.net>
Date: Sat, 20 Apr 2013 23:48:07 +0300
Subject: [PATCH 3/3] gitk: more aggressive space ignoring
diff -w is not enough to ignore all insignificant changes. For example,
it does not skip newlines. To workaround it, gitk additionaly filters
the diff hunks, skipping those which actually change only whitespaces.
Instead of passing each read line directly to the diff widget, how lines
of each hunk are collected and when hunk end is detected, it is
analysed: both old and new texts are collected, then normalized and the
normalized values are compared literally. If they are different, hunk is
added to diff widget.
The normalization is implemented as normalize_string function, looks
like it correctly hands switch from kr to gnu style.
The hunk filtering is turned on for linear diffs (not for merges),
when is enabled "Ignore space change" and word difference is disabled.
---
gitk-git/gitk | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 108 insertions(+), 9 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index b9955ed..30db556 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -7704,6 +7704,7 @@ proc getblobdiffs {ids} {
fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
set blobdifffd($ids) $bdf
set currdiffsubmod ""
+ hunkfilter_init $bdf
filerun $bdf [list getblobdiffline $bdf $diffids]
}
@@ -7987,24 +7988,121 @@ proc getblobdiffline_end {is_eof seehere_name} {
proc getblobdiffline_close {} {
}
+proc normalize_string {str} {
+ set str [regsub -all {[ \r\n\t]+} $str " "]
+ set str [regsub -all {([\{\}\(\)\[\]\*\+;,\\\/\+\*<>-]) ([a-zA-Z0-9_])} $str {\1\2}]
+ set str [regsub -all {([a-zA-Z0-9_]) ([\{\}\(\)\[\]\*\+;,\\\/\+\*<>-])} $str {\1\2}]
+ set str [regsub -all {([\{\}\(\)\[\],;]) ([\{\}\(\)\[\],;])} $str {\1\2}]
+ set str [regsub -all {([\{\}\(\)\[\],;]) ([\{\}\(\)\[\],;])} $str {\1\2}]
+ return $str
+}
+
+proc hunkfilter_flush {ids} {
+ global hunkfilter_enabled hunkfilter_data hunkfilter_oldlines hunkfilter_newlines
+
+ set old [normalize_string $hunkfilter_oldlines]
+ set new [normalize_string $hunkfilter_newlines]
+ if {[normalize_string $hunkfilter_oldlines] ne [normalize_string $hunkfilter_newlines]} {
+ foreach cached_line $hunkfilter_data {
+ catch {getblobdiffline_line $cached_line $ids fake_seehere} result options
+ case [dict get $options -code] {
+ 0 { getblobdiffline_end 0 fake_seehere }
+ 4 { }
+ default { error [list Unexpected: $result $options] }
+ }
+ }
+ }
+
+ set hunkfilter_enabled 0
+ set hunkfilter_data {}
+ set hunkfilter_newlines ""
+ set hunkfilter_oldlines ""
+}
+
proc getblobdiffline_proxy_line {line ids seehere_name} {
+ global hunkfilter_enabled hunkfilter_data hunkfilter_oldlines hunkfilter_newlines
upvar 1 $seehere_name seehere
+ global ignorespace worddiff
+
+ if {[info exists hunkfilter_enabled] && $hunkfilter_enabled} {
+ set line_rest [string range $line 1 end]
+ set operation [string index $line 0]
+ case $operation {
+ {" "} {
+ lappend hunkfilter_data $line
+ set hunkfilter_oldlines "$hunkfilter_oldlines$line_rest\n"
+ set hunkfilter_newlines "$hunkfilter_newlines$line_rest\n"
+ }
+ "+" {
+ lappend hunkfilter_data $line
+ set hunkfilter_newlines "$hunkfilter_newlines$line_rest\n"
+ }
+ "-" {
+ lappend hunkfilter_data $line
+ set hunkfilter_oldlines "$hunkfilter_oldlines$line_rest\n"
+ }
+ "\\" { # newline EOF
+ lappend hunkfilter_data $line
+ }
+ default {
+ hunkfilter_flush $ids
+ if {[string match "@@ *" $line] && $ignorespace && $worddiff eq [mc "Line diff"]} {
+ set hunkfilter_enabled 1
+ set hunkfilter_data [list $line]
+ set hunkfilter_oldlines ""
+ set hunkfilter_newlines ""
+ } else {
+ set hunkfilter_enabled 0
+ }
+ }
+ }
+ } else {
+ if {[string match "@@ *" $line] && $ignorespace && $worddiff eq [mc "Line diff"]} {
+ set hunkfilter_enabled 1
+ set hunkfilter_data [list $line]
+ set hunkfilter_oldlines ""
+ set hunkfilter_newlines ""
+ }
+ }
- set ret [catch {getblobdiffline_line $line $ids seehere} result options]
- case [dict get $options -code] {
- 0 { return $ret }
- 4 { return -code continue }
- default { error [list Unexpected: $ret $result $options] }
+ if {![info exists hunkfilter_enabled] || !$hunkfilter_enabled} {
+ set ret [catch {getblobdiffline_line $line $ids seehere} result options]
+ case [dict get $options -code] {
+ 0 { return $ret }
+ 4 { return -code continue }
+ default { error [list Unexpected: $ret $result $options] }
+ }
}
}
proc getblobdiffline_proxy_end {is_eof seehere_name} {
upvar 1 $seehere_name seehere
- getblobdiffline_end $is_eof seehere
+ if {![info exists hunkfilter_enabled] || !$hunkfilter_enabled} {
+ getblobdiffline_end $is_eof seehere
+ }
}
-proc getblobdiffline_proxy_close {} {
+proc hunkfilter_init {channel} {
+ global hunkfilter_enabled hunkfilter_data
+
+ if {[info exists hunkfilter_enabled] && $hunkfilter_enabled \
+ && [info exists hunkfilter_data] && [llength $hunkfilter_data] > 0} {
+ puts "Lost hunkfilter data:"
+ foreach d $hunkfilter_data {
+ puts [list l: $d]
+ }
+ }
+ set hunkfilter_enabled 0
+}
+
+proc getblobdiffline_proxy_close {ids} {
+ global hunkfilter_enabled hunkfilter_oldlines hunkfilter_newlines hunkfilter_data
+
+ if {[info exists hunkfilter_enabled] && $hunkfilter_enabled} {
+ hunkfilter_flush $ids
+ }
+
getblobdiffline_close
}
@@ -8016,7 +8114,7 @@ proc getblobdiffline {bdf ids} {
while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
catch {close $bdf}
- getblobdiffline_proxy_close
+ getblobdiffline_proxy_close ids
return 0
}
getblobdiffline_proxy_line $line $ids seehere
@@ -8024,7 +8122,7 @@ proc getblobdiffline {bdf ids} {
getblobdiffline_proxy_end [eof $bdf] seehere
if {[eof $bdf]} {
catch {close $bdf}
- getblobdiffline_proxy_close
+ getblobdiffline_proxy_close ids
return 0
}
$ctext conf -state disabled
@@ -8854,6 +8952,7 @@ proc diffcommits {a b} {
set blobdifffd($diffids) $fd
set diffinhdr 0
set currdiffsubmod ""
+ hunkfilter_init $fd
filerun $fd [list getblobdiffline $fd $diffids]
}
--
1.8.2.rc0
@max630

This comment has been minimized.

Copy link
Owner Author

max630 commented Mar 13, 2014

later version: https://github.com/max630/git/commits/gitk_ignorespace
used the refactoring made by upstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.