@@ -3245,14 +3245,22 @@ proc show_blame {commit path} {
32453245 pack $w .path -side top -fill x
32463246
32473247 frame $w .out
3248+ text $w .out.loaded_t \
3249+ -background white -borderwidth 0 \
3250+ -state disabled \
3251+ -wrap none \
3252+ -height 40 \
3253+ -width 1 \
3254+ -font font_diff
3255+ $w .out.loaded_t tag conf annotated -background grey
3256+
32483257 text $w .out.linenumber_t \
32493258 -background white -borderwidth 0 \
32503259 -state disabled \
32513260 -wrap none \
32523261 -height 40 \
32533262 -width 5 \
32543263 -font font_diff
3255- $w .out.linenumber_t tag conf annotated -background grey
32563264 $w .out.linenumber_t tag conf linenumber -justify right
32573265
32583266 text $w .out.file_t \
@@ -3267,12 +3275,18 @@ proc show_blame {commit path} {
32673275 scrollbar $w .out.sbx -orient h -command [list $w .out.file_t xview]
32683276 scrollbar $w .out.sby -orient v \
32693277 -command [list scrollbar2many [list \
3278+ $w .out.loaded_t \
32703279 $w .out.linenumber_t \
32713280 $w .out.file_t \
32723281 ] yview]
3273- grid $w .out.linenumber_t $w .out.file_t $w .out.sby -sticky nsew
3274- grid conf $w .out.sbx -column 1 -sticky we
3275- grid columnconfigure $w .out 1 -weight 1
3282+ grid \
3283+ $w .out.linenumber_t \
3284+ $w .out.loaded_t \
3285+ $w .out.file_t \
3286+ $w .out.sby \
3287+ -sticky nsew
3288+ grid conf $w .out.sbx -column 2 -sticky we
3289+ grid columnconfigure $w .out 2 -weight 1
32763290 grid rowconfigure $w .out 0 -weight 1
32773291 pack $w .out -fill both -expand 1
32783292
@@ -3306,17 +3320,21 @@ proc show_blame {commit path} {
33063320 -font font_ui \
33073321 -command " blame_copycommit $w \$ cursorW @\$ cursorX,\$ cursorY"
33083322
3309- foreach i [list $w .out.linenumber_t $w .out.file_t] {
3323+ foreach i [list \
3324+ $w .out.loaded_t \
3325+ $w .out.linenumber_t \
3326+ $w .out.file_t] {
33103327 $i tag conf in_sel \
33113328 -background [$i cget -foreground] \
33123329 -foreground [$i cget -background]
33133330 $i conf -yscrollcommand \
33143331 [list many2scrollbar [list \
3332+ $w .out.loaded_t \
33153333 $w .out.linenumber_t \
33163334 $w .out.file_t \
33173335 ] yview $w .out.sby]
33183336 bind $i <Button-1> "
3319- blame_highlight {$w } \\
3337+ blame_click {$w } \\
33203338 $w .cm.t \\
33213339 $w .out.linenumber_t \\
33223340 $w .out.file_t \\
@@ -3338,19 +3356,22 @@ proc show_blame {commit path} {
33383356 "
33393357 wm title $tl " [ appname] ([ reponame] ): File Viewer"
33403358
3359+ set blame_data($w ,commit_count) 0
3360+ set blame_data($w ,commit_list) {}
33413361 set blame_data($w ,total_lines) 0
33423362 set blame_data($w ,blame_lines) 0
33433363 set blame_data($w ,highlight_commit) {}
33443364 set blame_data($w ,highlight_line) -1
3365+
33453366 set cmd [list git cat-file blob " $commit :$path " ]
33463367 set fd [open " | $cmd " r]
33473368 fconfigure $fd -blocking 0 -translation lf -encoding binary
33483369 fileevent $fd readable [list read_blame_catfile \
33493370 $fd $w $commit $path \
3350- $w .cm.t $w .out.linenumber_t $w .out.file_t]
3371+ $w .cm.t $w .out.loaded_t $w .out. linenumber_t $w .out.file_t]
33513372}
33523373
3353- proc read_blame_catfile {fd w commit path w_cmit w_line w_file} {
3374+ proc read_blame_catfile {fd w commit path w_cmit w_load w_line w_file} {
33543375 global blame_status blame_data
33553376
33563377 if {![winfo exists $w_file ]} {
@@ -3359,14 +3380,17 @@ proc read_blame_catfile {fd w commit path w_cmit w_line w_file} {
33593380 }
33603381
33613382 set n $blame_data($w,total_lines)
3383+ $w_load conf -state normal
33623384 $w_line conf -state normal
33633385 $w_file conf -state normal
33643386 while {[gets $fd line] >= 0} {
33653387 regsub "\r\$ " $line {} line
33663388 incr n
3389+ $w_load insert end " \n "
33673390 $w_line insert end " $n \n " linenumber
33683391 $w_file insert end " $line \n "
33693392 }
3393+ $w_load conf -state disabled
33703394 $w_line conf -state disabled
33713395 $w_file conf -state disabled
33723396 set blame_data($w ,total_lines) $n
@@ -3379,11 +3403,11 @@ proc read_blame_catfile {fd w commit path w_cmit w_line w_file} {
33793403 set fd [open " | $cmd " r]
33803404 fconfigure $fd -blocking 0 -translation lf -encoding binary
33813405 fileevent $fd readable [list read_blame_incremental $fd $w \
3382- $w_cmit $w_line $w_file ]
3406+ $w_load $ w_cmit $w_line $w_file ]
33833407 }
33843408}
33853409
3386- proc read_blame_incremental {fd w w_cmit w_line w_file} {
3410+ proc read_blame_incremental {fd w w_load w_cmit w_line w_file} {
33873411 global blame_status blame_data
33883412
33893413 if {![winfo exists $w_file ]} {
@@ -3399,12 +3423,14 @@ proc read_blame_incremental {fd w w_cmit w_line w_file} {
33993423 set blame_data($w ,final_line) $final_line
34003424 set blame_data($w ,line_count) $line_count
34013425
3402- if {[catch {set g $blame_data($w,$cmit,seen ) }]} {
3426+ if {[catch {set g $blame_data($w,$cmit,order ) }]} {
34033427 $w_line tag conf g$cmit
34043428 $w_file tag conf g$cmit
34053429 $w_line tag raise in_sel
34063430 $w_file tag raise in_sel
3407- set blame_data($w ,$cmit ,seen) 1
3431+ set blame_data($w ,$cmit ,order) $blame_data($w,commit_count)
3432+ incr blame_data($w ,commit_count)
3433+ lappend blame_data($w ,commit_list) $cmit
34083434 }
34093435 } elseif {[string match {filename *} $line ]} {
34103436 set file [string range $line 9 end]
@@ -3414,7 +3440,7 @@ proc read_blame_incremental {fd w w_cmit w_line w_file} {
34143440
34153441 while {$n > 0} {
34163442 if {[catch {set g g$blame_data($w,line$lno,commit) }]} {
3417- $w_line tag add annotated $lno .0 " $lno .0 lineend + 1c"
3443+ $w_load tag add annotated $lno .0 " $lno .0 lineend + 1c"
34183444 } else {
34193445 $w_line tag remove g$g $lno .0 " $lno .0 lineend + 1c"
34203446 $w_file tag remove g$g $lno .0 " $lno .0 lineend + 1c"
@@ -3438,6 +3464,14 @@ proc read_blame_incremental {fd w w_cmit w_line w_file} {
34383464 incr lno
34393465 incr blame_data($w ,blame_lines)
34403466 }
3467+
3468+ set hc $blame_data($w,highlight_commit)
3469+ if {$hc ne {}
3470+ && [expr {$blame_data($w,$hc,order) + 1}]
3471+ == $blame_data($w,$cmit,order) } {
3472+ blame_showcommit $w $w_cmit $w_line $w_file \
3473+ $blame_data($w,highlight_line)
3474+ }
34413475 } elseif {[regexp {^([a-z-]+) (.*)$} $line line header data]} {
34423476 set blame_data($w ,$blame_data($w,commit) ,$header ) $data
34433477 }
@@ -3462,7 +3496,7 @@ proc blame_incremental_status {w} {
34623496 / $blame_data($w,total_lines) }]]
34633497}
34643498
3465- proc blame_highlight {w w_cmit w_line w_file cur_w pos} {
3499+ proc blame_click {w w_cmit w_line w_file cur_w pos} {
34663500 set lno [lindex [split [$cur_w index $pos ] .] 0]
34673501 if {$lno eq {}} return
34683502
@@ -3474,25 +3508,41 @@ proc blame_highlight {w w_cmit w_line w_file cur_w pos} {
34743508 blame_showcommit $w $w_cmit $w_line $w_file $lno
34753509}
34763510
3511+ set blame_colors {
3512+ # ff4040
3513+ # ff40ff
3514+ # 4040ff
3515+ }
3516+
34773517proc blame_showcommit {w w_cmit w_line w_file lno} {
3478- global blame_data repo_config
3518+ global blame_colors blame_data repo_config
34793519
34803520 set cmit $blame_data($w,highlight_commit)
34813521 if {$cmit ne {}} {
3482- $w_line tag conf g$cmit -background white
3483- $w_file tag conf g$cmit -background white
3484- $w_line tag raise annotated g$cmit
3522+ set idx $blame_data($w,$cmit,order)
3523+ set i 0
3524+ foreach c $blame_colors {
3525+ set h [lindex $blame_data($w,commit_list) [expr {$idx - 1 + $i }]]
3526+ $w_line tag conf g$h -background white
3527+ $w_file tag conf g$h -background white
3528+ incr i
3529+ }
34853530 }
34863531
34873532 $w_cmit conf -state normal
34883533 $w_cmit delete 0.0 end
34893534 if {[catch {set cmit $blame_data($w,line$lno,commit) }]} {
34903535 set cmit {}
3491- $w_cmit insert end " Computing ..."
3536+ $w_cmit insert end " Loading annotation ..."
34923537 } else {
3493- $w_line tag conf g$cmit -background yellow
3494- $w_file tag conf g$cmit -background yellow
3495- $w_line tag raise g$cmit annotated
3538+ set idx $blame_data($w,$cmit,order)
3539+ set i 0
3540+ foreach c $blame_colors {
3541+ set h [lindex $blame_data($w,commit_list) [expr {$idx - 1 + $i }]]
3542+ $w_line tag conf g$h -background $c
3543+ $w_file tag conf g$h -background $c
3544+ incr i
3545+ }
34963546
34973547 if {[catch {set msg $blame_data($w,$cmit,message) }]} {
34983548 set msg {}
0 commit comments