gitk: Refactor per-line part of getblobdiffline and its support
For later use with data sources other than a pipe, refactor the big worker part of getblobdiffline to a separate function parseblobdiffline. Also refactor its initialization and wrap-up to separate routines. Signed-off-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Paul Mackerras <paulus@samba.org>
This commit is contained in:

committed by
Paul Mackerras

parent
71846c5caf
commit
5de460a2cf
76
gitk
76
gitk
@ -7752,15 +7752,25 @@ proc changeworddiff {name ix op} {
|
|||||||
reselectline
|
reselectline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc initblobdiffvars {} {
|
||||||
|
global diffencoding targetline diffnparents
|
||||||
|
global diffinhdr currdiffsubmod diffseehere
|
||||||
|
set targetline {}
|
||||||
|
set diffnparents 0
|
||||||
|
set diffinhdr 0
|
||||||
|
set diffencoding [get_path_encoding {}]
|
||||||
|
set currdiffsubmod ""
|
||||||
|
set diffseehere -1
|
||||||
|
}
|
||||||
|
|
||||||
proc getblobdiffs {ids} {
|
proc getblobdiffs {ids} {
|
||||||
global blobdifffd diffids env
|
global blobdifffd diffids env
|
||||||
global diffinhdr treediffs
|
global treediffs
|
||||||
global diffcontext
|
global diffcontext
|
||||||
global ignorespace
|
global ignorespace
|
||||||
global worddiff
|
global worddiff
|
||||||
global limitdiffs vfilelimit curview
|
global limitdiffs vfilelimit curview
|
||||||
global diffencoding targetline diffnparents
|
global git_version
|
||||||
global git_version currdiffsubmod
|
|
||||||
|
|
||||||
set textconv {}
|
set textconv {}
|
||||||
if {[package vcompare $git_version "1.6.1"] >= 0} {
|
if {[package vcompare $git_version "1.6.1"] >= 0} {
|
||||||
@ -7784,13 +7794,9 @@ proc getblobdiffs {ids} {
|
|||||||
error_popup [mc "Error getting diffs: %s" $err]
|
error_popup [mc "Error getting diffs: %s" $err]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
set targetline {}
|
|
||||||
set diffnparents 0
|
|
||||||
set diffinhdr 0
|
|
||||||
set diffencoding [get_path_encoding {}]
|
|
||||||
fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
|
fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
|
||||||
set blobdifffd($ids) $bdf
|
set blobdifffd($ids) $bdf
|
||||||
set currdiffsubmod ""
|
initblobdiffvars
|
||||||
filerun $bdf [list getblobdiffline $bdf $diffids]
|
filerun $bdf [list getblobdiffline $bdf $diffids]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7856,13 +7862,17 @@ proc makediffhdr {fname ids} {
|
|||||||
set diffline 0
|
set diffline 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc blobdiffmaybeseehere {ateof} {
|
||||||
|
global diffseehere
|
||||||
|
if {$diffseehere >= 0} {
|
||||||
|
mark_ctext_line [lindex [split $diffseehere .] 0]
|
||||||
|
}
|
||||||
|
maybe_scroll_ctext ateof
|
||||||
|
}
|
||||||
|
|
||||||
proc getblobdiffline {bdf ids} {
|
proc getblobdiffline {bdf ids} {
|
||||||
global diffids blobdifffd ctext curdiffstart
|
global diffids blobdifffd
|
||||||
global diffnexthead diffnextnote difffilestart
|
global ctext
|
||||||
global ctext_file_names ctext_file_lines
|
|
||||||
global diffinhdr treediffs mergemax diffnparents
|
|
||||||
global diffencoding jump_to_here targetline diffline currdiffsubmod
|
|
||||||
global worddiff
|
|
||||||
|
|
||||||
set nr 0
|
set nr 0
|
||||||
$ctext conf -state normal
|
$ctext conf -state normal
|
||||||
@ -7871,6 +7881,25 @@ proc getblobdiffline {bdf ids} {
|
|||||||
catch {close $bdf}
|
catch {close $bdf}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
parseblobdiffline $ids $line
|
||||||
|
}
|
||||||
|
$ctext conf -state disabled
|
||||||
|
blobdiffmaybeseehere [eof $bdf]
|
||||||
|
if {[eof $bdf]} {
|
||||||
|
catch {close $bdf}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return [expr {$nr >= 1000? 2: 1}]
|
||||||
|
}
|
||||||
|
|
||||||
|
proc parseblobdiffline {ids line} {
|
||||||
|
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 diffseehere
|
||||||
|
|
||||||
if {![string compare -length 5 "diff " $line]} {
|
if {![string compare -length 5 "diff " $line]} {
|
||||||
if {![regexp {^diff (--cc|--git) } $line m type]} {
|
if {![regexp {^diff (--cc|--git) } $line m type]} {
|
||||||
set line [encoding convertfrom $line]
|
set line [encoding convertfrom $line]
|
||||||
@ -7908,7 +7937,7 @@ proc getblobdiffline {bdf ids} {
|
|||||||
if {!(($l & 1) && [string index $line $i] eq " " &&
|
if {!(($l & 1) && [string index $line $i] eq " " &&
|
||||||
[string range $line 2 [expr {$i - 1}]] eq \
|
[string range $line 2 [expr {$i - 1}]] eq \
|
||||||
[string range $line [expr {$i + 3}] end])} {
|
[string range $line [expr {$i + 3}] end])} {
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
# unescape if quoted and chop off the a/ from the front
|
# unescape if quoted and chop off the a/ from the front
|
||||||
if {[string index $line 0] eq "\""} {
|
if {[string index $line 0] eq "\""} {
|
||||||
@ -7989,10 +8018,10 @@ proc getblobdiffline {bdf ids} {
|
|||||||
makediffhdr $fname $ids
|
makediffhdr $fname $ids
|
||||||
} elseif {[string compare -length 3 $line "---"] == 0} {
|
} elseif {[string compare -length 3 $line "---"] == 0} {
|
||||||
# do nothing
|
# do nothing
|
||||||
continue
|
return
|
||||||
} elseif {[string compare -length 3 $line "+++"] == 0} {
|
} elseif {[string compare -length 3 $line "+++"] == 0} {
|
||||||
set diffinhdr 0
|
set diffinhdr 0
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
$ctext insert end "$line\n" filesep
|
$ctext insert end "$line\n" filesep
|
||||||
|
|
||||||
@ -8043,7 +8072,7 @@ proc getblobdiffline {bdf ids} {
|
|||||||
}
|
}
|
||||||
if {$targetline ne {}} {
|
if {$targetline ne {}} {
|
||||||
if {$diffline == $targetline} {
|
if {$diffline == $targetline} {
|
||||||
set seehere [$ctext index "end - 1 chars"]
|
set diffseehere [$ctext index "end - 1 chars"]
|
||||||
set targetline {}
|
set targetline {}
|
||||||
} else {
|
} else {
|
||||||
incr diffline
|
incr diffline
|
||||||
@ -8066,17 +8095,6 @@ proc getblobdiffline {bdf ids} {
|
|||||||
$ctext insert end "$line\n" hunksep
|
$ctext insert end "$line\n" hunksep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if {[info exists seehere]} {
|
|
||||||
mark_ctext_line [lindex [split $seehere .] 0]
|
|
||||||
}
|
|
||||||
maybe_scroll_ctext [eof $bdf]
|
|
||||||
$ctext conf -state disabled
|
|
||||||
if {[eof $bdf]} {
|
|
||||||
catch {close $bdf}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return [expr {$nr >= 1000? 2: 1}]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proc changediffdisp {} {
|
proc changediffdisp {} {
|
||||||
|
Reference in New Issue
Block a user