git-gui: Improve annotated file display.
Rather than trying to mark the background color of the line numbers to show which lines have annotated data loaded, we now show a ruler between the line numbers and the file data. This ruler is just 1 character wide and its background color is set to grey to denote which lines have annotation ready. I had to make this change as I kept loosing the annotation marker when a line was no longer colored as part of the current selection. We now color the lines blamed on the current commit in yellow, the lines in the commit which came after (descendant) in red (hotter, less tested) and the lines in the commit before (ancestor) in blue (cooler, better tested). Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Feb 9, 2007 at 01:59 UTC
486ef5270ce3162ee14634db825884cc466a32bf
1 file changed
+72
-22
git-gui.sh
+72
-22
@@ -3245,6 +3245,15 @@ proc show_blame {commit path} {
3245
pack $w.path -side top -fill x
3246
3247
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
+
3257
text $w.out.linenumber_t \
3258
-background white -borderwidth 0 \
3259
-state disabled \
@@ -3252,7 +3261,6 @@ proc show_blame {commit path} {
3261
-height 40 \
3262
-width 5 \
3263
-font font_diff
3255
- $w.out.linenumber_t tag conf annotated -background grey
3264
$w.out.linenumber_t tag conf linenumber -justify right
3265
3266
text $w.out.file_t \
@@ -3267,12 +3275,18 @@ proc show_blame {commit path} {
3275
scrollbar $w.out.sbx -orient h -command [list $w.out.file_t xview]
3276
scrollbar $w.out.sby -orient v \
3277
-command [list scrollbar2many [list \
3278
+ $w.out.loaded_t \
3279
$w.out.linenumber_t \
3280
$w.out.file_t \
3281
] 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
3290
grid rowconfigure $w.out 0 -weight 1
3291
pack $w.out -fill both -expand 1
3292
@@ -3306,17 +3320,21 @@ proc show_blame {commit path} {
3320
-font font_ui \
3321
-command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3322
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] {
3327
$i tag conf in_sel \
3328
-background [$i cget -foreground] \
3329
-foreground [$i cget -background]
3330
$i conf -yscrollcommand \
3331
[list many2scrollbar [list \
3332
+ $w.out.loaded_t \
3333
$w.out.linenumber_t \
3334
$w.out.file_t \
3335
] yview $w.out.sby]
3336
bind $i <Button-1> "
3319
- blame_highlight {$w} \\
3337
+ blame_click {$w} \\
3338
$w.cm.t \\
3339
$w.out.linenumber_t \\
3340
$w.out.file_t \\
@@ -3338,19 +3356,22 @@ proc show_blame {commit path} {
3356
"
3357
wm title $tl "[appname] ([reponame]): File Viewer"
3358
3359
+ set blame_data($w,commit_count) 0
3360
+ set blame_data($w,commit_list) {}
3361
set blame_data($w,total_lines) 0
3362
set blame_data($w,blame_lines) 0
3363
set blame_data($w,highlight_commit) {}
3364
set blame_data($w,highlight_line) -1
3365
+
3366
set cmd [list git cat-file blob "$commit:$path"]
3367
set fd [open "| $cmd" r]
3368
fconfigure $fd -blocking 0 -translation lf -encoding binary
3369
fileevent $fd readable [list read_blame_catfile \
3370
$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]
3372
}
3373
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} {
3375
global blame_status blame_data
3376
3377
if {![winfo exists $w_file]} {
@@ -3359,14 +3380,17 @@ proc read_blame_catfile {fd w commit path w_cmit w_line w_file} {
3380
}
3381
3382
set n $blame_data($w,total_lines)
3383
+ $w_load conf -state normal
3384
$w_line conf -state normal
3385
$w_file conf -state normal
3386
while {[gets $fd line] >= 0} {
3387
regsub "\r\$" $line {} line
3388
incr n
3389
+ $w_load insert end "\n"
3390
$w_line insert end "$n\n" linenumber
3391
$w_file insert end "$line\n"
3392
}
3393
+ $w_load conf -state disabled
3394
$w_line conf -state disabled
3395
$w_file conf -state disabled
3396
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} {
3403
set fd [open "| $cmd" r]
3404
fconfigure $fd -blocking 0 -translation lf -encoding binary
3405
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]
3407
}
3408
}
3409
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} {
3411
global blame_status blame_data
3412
3413
if {![winfo exists $w_file]} {
@@ -3399,12 +3423,14 @@ proc read_blame_incremental {fd w w_cmit w_line w_file} {
3423
set blame_data($w,final_line) $final_line
3424
set blame_data($w,line_count) $line_count
3425
3402
- if {[catch {set g $blame_data($w,$cmit,seen)}]} {
3426
+ if {[catch {set g $blame_data($w,$cmit,order)}]} {
3427
$w_line tag conf g$cmit
3428
$w_file tag conf g$cmit
3429
$w_line tag raise in_sel
3430
$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
3434
}
3435
} elseif {[string match {filename *} $line]} {
3436
set file [string range $line 9 end]
@@ -3414,7 +3440,7 @@ proc read_blame_incremental {fd w w_cmit w_line w_file} {
3440
3441
while {$n > 0} {
3442
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"
3444
} else {
3445
$w_line tag remove g$g $lno.0 "$lno.0 lineend + 1c"
3446
$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} {
3464
incr lno
3465
incr blame_data($w,blame_lines)
3466
}
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
+ }
3475
} elseif {[regexp {^([a-z-]+) (.*)$} $line line header data]} {
3476
set blame_data($w,$blame_data($w,commit),$header) $data
3477
}
@@ -3462,7 +3496,7 @@ proc blame_incremental_status {w} {
3496
/ $blame_data($w,total_lines)}]]
3497
}
3498
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} {
3500
set lno [lindex [split [$cur_w index $pos] .] 0]
3501
if {$lno eq {}} return
3502
@@ -3474,25 +3508,41 @@ proc blame_highlight {w w_cmit w_line w_file cur_w pos} {
3508
blame_showcommit $w $w_cmit $w_line $w_file $lno
3509
}
3510
3511
+set blame_colors {
3512
+ #ff4040
3513
+ #ff40ff
3514
+ #4040ff
3515
+}
3516
+
3517
proc blame_showcommit {w w_cmit w_line w_file lno} {
3478
- global blame_data repo_config
3518
+ global blame_colors blame_data repo_config
3519
3520
set cmit $blame_data($w,highlight_commit)
3521
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
+ }
3530
}
3531
3532
$w_cmit conf -state normal
3533
$w_cmit delete 0.0 end
3534
if {[catch {set cmit $blame_data($w,line$lno,commit)}]} {
3535
set cmit {}
3491
- $w_cmit insert end "Computing..."
3536
+ $w_cmit insert end "Loading annotation..."
3537
} 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
+ }
3546
3547
if {[catch {set msg $blame_data($w,$cmit,message)}]} {
3548
set msg {}