@matheusbsbs / matheus-bagliano / commits / 6910ae80d0
Fork 0

git-gui: Redesign the display of annotated files.

Using 180 columns worth of screen space to display just 20 columns of file data and 160 columns worth of annotation information is not practically useful. Users need/want to see the file data, and have the anotation associated with it displayed in a detail pane only when they have focused on a particular region of the file. Now our file viewer has a small 10-line high pane below the file which shows the commit message for the commit this line was blamed on. The columns have all been removed, except the current line number column as that has some real value when trying to locate an interesting block. To keep the user entertained we have a progress meter in the status bar of the viewer which lets them know how many lines have been annotated, and how much has been completed. We use a grey background on the line numbers for lines which we have obtained annotation from, and we color all lines in the current commit with a yellow background, so they stand out when scanning through the file. All other lines are kept with a white background, making the yellow really pop. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Feb 8, 2007 at 21:39 UTC 6910ae80d0e84f03151473ee55055c46b5480ec5
1 file changed +160 -199
git-gui.sh
+160 -199
@@ -3235,7 +3235,6 @@ proc show_blame {commit path} {
3235 set tl .
3236 }
3237 set blame_status($w) {Loading current file content...}
3238 - set texts [list]
3238
3239 label $w.path -text "$commit:$path" \
3240 -anchor w \
@@ -3245,84 +3244,7 @@ proc show_blame {commit path} {
3244 -font font_uibold
3245 pack $w.path -side top -fill x
3246
3248 - set hbg #e2effa
3247 frame $w.out
3250 - label $w.out.commit_l -text Commit \
3251 - -relief solid \
3252 - -borderwidth 1 \
3253 - -background $hbg \
3254 - -font font_uibold
3255 - text $w.out.commit_t \
3256 - -background white -borderwidth 0 \
3257 - -state disabled \
3258 - -wrap none \
3259 - -height 40 \
3260 - -width 9 \
3261 - -font font_diff
3262 - lappend texts $w.out.commit_t
3263 -
3264 - label $w.out.author_l -text Author \
3265 - -relief solid \
3266 - -borderwidth 1 \
3267 - -background $hbg \
3268 - -font font_uibold
3269 - text $w.out.author_t \
3270 - -background white -borderwidth 0 \
3271 - -state disabled \
3272 - -wrap none \
3273 - -height 40 \
3274 - -width 20 \
3275 - -font font_diff
3276 - lappend texts $w.out.author_t
3277 -
3278 - label $w.out.date_l -text Date \
3279 - -relief solid \
3280 - -borderwidth 1 \
3281 - -background $hbg \
3282 - -font font_uibold
3283 - text $w.out.date_t \
3284 - -background white -borderwidth 0 \
3285 - -state disabled \
3286 - -wrap none \
3287 - -height 40 \
3288 - -width [string length "yyyy-mm-dd hh:mm:ss"] \
3289 - -font font_diff
3290 - lappend texts $w.out.date_t
3291 -
3292 - label $w.out.filename_l -text Filename \
3293 - -relief solid \
3294 - -borderwidth 1 \
3295 - -background $hbg \
3296 - -font font_uibold
3297 - text $w.out.filename_t \
3298 - -background white -borderwidth 0 \
3299 - -state disabled \
3300 - -wrap none \
3301 - -height 40 \
3302 - -width 20 \
3303 - -font font_diff
3304 - lappend texts $w.out.filename_t
3305 -
3306 - label $w.out.origlinenumber_l -text {Orig Line} \
3307 - -relief solid \
3308 - -borderwidth 1 \
3309 - -background $hbg \
3310 - -font font_uibold
3311 - text $w.out.origlinenumber_t \
3312 - -background white -borderwidth 0 \
3313 - -state disabled \
3314 - -wrap none \
3315 - -height 40 \
3316 - -width 5 \
3317 - -font font_diff
3318 - $w.out.origlinenumber_t tag conf linenumber -justify right
3319 - lappend texts $w.out.origlinenumber_t
3320 -
3321 - label $w.out.linenumber_l -text {Curr Line} \
3322 - -relief solid \
3323 - -borderwidth 1 \
3324 - -background $hbg \
3325 - -font font_uibold
3248 text $w.out.linenumber_t \
3249 -background white -borderwidth 0 \
3250 -state disabled \
@@ -3330,14 +3252,9 @@ proc show_blame {commit path} {
3252 -height 40 \
3253 -width 5 \
3254 -font font_diff
3255 + $w.out.linenumber_t tag conf annotated -background grey
3256 $w.out.linenumber_t tag conf linenumber -justify right
3334 - lappend texts $w.out.linenumber_t
3257
3336 - label $w.out.file_l -text {File Content} \
3337 - -relief solid \
3338 - -borderwidth 1 \
3339 - -background $hbg \
3340 - -font font_uibold
3258 text $w.out.file_t \
3259 -background white -borderwidth 0 \
3260 -state disabled \
@@ -3346,22 +3263,17 @@ proc show_blame {commit path} {
3263 -width 80 \
3264 -xscrollcommand [list $w.out.sbx set] \
3265 -font font_diff
3349 - lappend texts $w.out.file_t
3266
3267 scrollbar $w.out.sbx -orient h -command [list $w.out.file_t xview]
3268 scrollbar $w.out.sby -orient v \
3353 - -command [list scrollbar2many $texts yview]
3354 - set labels [list]
3355 - foreach i $texts {
3356 - regsub {_t$} $i _l l
3357 - lappend labels $l
3358 - }
3359 - set file_col [expr {[llength $texts] - 1}]
3360 - eval grid $labels -sticky we
3361 - eval grid $texts $w.out.sby -sticky nsew
3362 - grid conf $w.out.sbx -column $file_col -sticky we
3363 - grid columnconfigure $w.out $file_col -weight 1
3364 - grid rowconfigure $w.out 1 -weight 1
3269 + -command [list scrollbar2many [list \
3270 + $w.out.linenumber_t \
3271 + $w.out.file_t \
3272 + ] 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
3276 + grid rowconfigure $w.out 0 -weight 1
3277 pack $w.out -fill both -expand 1
3278
3279 label $w.status -textvariable blame_status($w) \
@@ -3372,18 +3284,45 @@ proc show_blame {commit path} {
3284 -font font_ui
3285 pack $w.status -side bottom -fill x
3286
3287 + frame $w.cm
3288 + text $w.cm.t \
3289 + -background white -borderwidth 0 \
3290 + -state disabled \
3291 + -wrap none \
3292 + -height 10 \
3293 + -width 80 \
3294 + -xscrollcommand [list $w.cm.sbx set] \
3295 + -yscrollcommand [list $w.cm.sby set] \
3296 + -font font_diff
3297 + scrollbar $w.cm.sbx -orient h -command [list $w.cm.t xview]
3298 + scrollbar $w.cm.sby -orient v -command [list $w.cm.t yview]
3299 + pack $w.cm.sby -side right -fill y
3300 + pack $w.cm.sbx -side bottom -fill x
3301 + pack $w.cm.t -expand 1 -fill both
3302 + pack $w.cm -side bottom -fill x
3303 +
3304 menu $w.ctxm -tearoff 0
3305 $w.ctxm add command -label "Copy Commit" \
3306 -font font_ui \
3307 -command "blame_copycommit $w \$cursorW @\$cursorX,\$cursorY"
3308
3380 - foreach i $texts {
3309 + foreach i [list $w.out.linenumber_t $w.out.file_t] {
3310 $i tag conf in_sel \
3311 -background [$i cget -foreground] \
3312 -foreground [$i cget -background]
3313 $i conf -yscrollcommand \
3385 - [list many2scrollbar $texts yview $w.out.sby]
3386 - bind $i <Button-1> "blame_highlight $i @%x,%y $texts;break"
3314 + [list many2scrollbar [list \
3315 + $w.out.linenumber_t \
3316 + $w.out.file_t \
3317 + ] yview $w.out.sby]
3318 + bind $i <Button-1> "
3319 + blame_highlight {$w} \\
3320 + $w.cm.t \\
3321 + $w.out.linenumber_t \\
3322 + $w.out.file_t \\
3323 + $i @%x,%y
3324 + break
3325 + "
3326 bind_button3 $i "
3327 set cursorX %x
3328 set cursorY %y
@@ -3392,8 +3331,6 @@ proc show_blame {commit path} {
3331 "
3332 }
3333
3395 - set blame_data($w,colors) {}
3396 -
3334 bind $tl <Visibility> "focus $tl"
3335 bind $tl <Destroy> "
3336 array unset blame_status {$w}
@@ -3402,15 +3339,18 @@ proc show_blame {commit path} {
3339 wm title $tl "[appname] ([reponame]): File Viewer"
3340
3341 set blame_data($w,total_lines) 0
3342 + set blame_data($w,blame_lines) 0
3343 + set blame_data($w,highlight_commit) {}
3344 + set blame_data($w,highlight_line) -1
3345 set cmd [list git cat-file blob "$commit:$path"]
3346 set fd [open "| $cmd" r]
3347 fconfigure $fd -blocking 0 -translation lf -encoding binary
3348 fileevent $fd readable [list read_blame_catfile \
3349 $fd $w $commit $path \
3410 - $texts $w.out.linenumber_t $w.out.file_t]
3350 + $w.cm.t $w.out.linenumber_t $w.out.file_t]
3351 }
3352
3413 -proc read_blame_catfile {fd w commit path texts w_lno w_file} {
3353 +proc read_blame_catfile {fd w commit path w_cmit w_line w_file} {
3354 global blame_status blame_data
3355
3356 if {![winfo exists $w_file]} {
@@ -3419,55 +3359,38 @@ proc read_blame_catfile {fd w commit path texts w_lno w_file} {
3359 }
3360
3361 set n $blame_data($w,total_lines)
3422 - foreach i $texts {$i conf -state normal}
3362 + $w_line conf -state normal
3363 + $w_file conf -state normal
3364 while {[gets $fd line] >= 0} {
3365 regsub "\r\$" $line {} line
3366 incr n
3426 - $w_lno insert end $n linenumber
3427 - $w_file insert end $line
3428 - foreach i $texts {$i insert end "\n"}
3367 + $w_line insert end "$n\n" linenumber
3368 + $w_file insert end "$line\n"
3369 }
3430 - foreach i $texts {$i conf -state disabled}
3370 + $w_line conf -state disabled
3371 + $w_file conf -state disabled
3372 set blame_data($w,total_lines) $n
3373
3374 if {[eof $fd]} {
3375 close $fd
3435 - set blame_status($w) {Loading annotations...}
3376 + blame_incremental_status $w
3377 set cmd [list git blame -M -C --incremental]
3378 lappend cmd $commit -- $path
3379 set fd [open "| $cmd" r]
3380 fconfigure $fd -blocking 0 -translation lf -encoding binary
3440 - set handler [list read_blame_incremental $fd $w]
3441 - append handler " $texts"
3442 - fileevent $fd readable $handler
3381 + fileevent $fd readable [list read_blame_incremental $fd $w \
3382 + $w_cmit $w_line $w_file]
3383 }
3384 }
3385
3446 -proc read_blame_incremental {fd w
3447 - w_commit w_author w_date w_filename w_olno
3448 - w_lno w_file} {
3386 +proc read_blame_incremental {fd w w_cmit w_line w_file} {
3387 global blame_status blame_data
3388
3451 - if {![winfo exists $w_commit]} {
3389 + if {![winfo exists $w_file]} {
3390 catch {close $fd}
3391 return
3392 }
3393
3456 - set all [list \
3457 - $w_commit \
3458 - $w_author \
3459 - $w_date \
3460 - $w_filename \
3461 - $w_olno \
3462 - $w_lno \
3463 - $w_file]
3464 -
3465 - $w_commit conf -state normal
3466 - $w_author conf -state normal
3467 - $w_date conf -state normal
3468 - $w_filename conf -state normal
3469 - $w_olno conf -state normal
3470 -
3394 while {[gets $fd line] >= 0} {
3395 if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
3396 cmit original_line final_line line_count]} {
@@ -3477,102 +3400,140 @@ proc read_blame_incremental {fd w
3400 set blame_data($w,line_count) $line_count
3401
3402 if {[catch {set g $blame_data($w,$cmit,seen)}]} {
3480 - if {$blame_data($w,colors) eq {}} {
3481 - set blame_data($w,colors) {
3482 - yellow
3483 - red
3484 - pink
3485 - orange
3486 - green
3487 - grey
3488 - }
3489 - }
3490 - set c [lindex $blame_data($w,colors) 0]
3491 - set blame_data($w,colors) \
3492 - [lrange $blame_data($w,colors) 1 end]
3493 - foreach t $all {
3494 - $t tag conf g$cmit -background $c
3495 - }
3496 - } else {
3403 + $w_line tag conf g$cmit
3404 + $w_file tag conf g$cmit
3405 + $w_line tag raise in_sel
3406 + $w_file tag raise in_sel
3407 set blame_data($w,$cmit,seen) 1
3408 }
3409 } elseif {[string match {filename *} $line]} {
3410 + set file [string range $line 9 end]
3411 set n $blame_data($w,line_count)
3412 set lno $blame_data($w,final_line)
3502 - set ol $blame_data($w,original_line)
3503 - set file [string range $line 9 end]
3413 set cmit $blame_data($w,commit)
3505 - set abbrev [string range $cmit 0 8]
3506 -
3507 - if {[catch {set author $blame_data($w,$cmit,author)} err]} {
3508 - set author {}
3509 - }
3510 -
3511 - if {[catch {set atime $blame_data($w,$cmit,author-time)}]} {
3512 - set atime {}
3513 - } else {
3514 - set atime [clock format $atime -format {%Y-%m-%d %T}]
3515 - }
3414
3415 while {$n > 0} {
3518 - if {![catch {set g g$blame_data($w,line$lno,commit)}]} {
3519 - foreach t $all {
3520 - $t tag remove $g $lno.0 "$lno.0 lineend + 1c"
3521 - }
3522 - }
3523 -
3524 - foreach t [list \
3525 - $w_commit \
3526 - $w_author \
3527 - $w_date \
3528 - $w_filename \
3529 - $w_olno] {
3530 - $t delete $lno.0 "$lno.0 lineend"
3416 + if {[catch {set g g$blame_data($w,line$lno,commit)}]} {
3417 + $w_line tag add annotated $lno.0 "$lno.0 lineend + 1c"
3418 + } else {
3419 + $w_line tag remove g$g $lno.0 "$lno.0 lineend + 1c"
3420 + $w_file tag remove g$g $lno.0 "$lno.0 lineend + 1c"
3421 }
3422
3533 - $w_commit insert $lno.0 $abbrev
3534 - $w_author insert $lno.0 $author
3535 - $w_date insert $lno.0 $atime
3536 - $w_filename insert $lno.0 $file
3537 - $w_olno insert $lno.0 $ol linenumber
3423 + set blame_data($w,line$lno,commit) $cmit
3424 + set blame_data($w,line$lno,file) $file
3425 + $w_line tag add g$cmit $lno.0 "$lno.0 lineend + 1c"
3426 + $w_file tag add g$cmit $lno.0 "$lno.0 lineend + 1c"
3427
3539 - set g g$cmit
3540 - foreach t $all {
3541 - $t tag add $g $lno.0 "$lno.0 lineend + 1c"
3428 + if {$blame_data($w,highlight_line) == $lno} {
3429 + blame_showcommit $w $w_cmit $w_line $w_file $lno
3430 }
3431
3544 - set blame_data($w,line$lno,commit) $cmit
3545 -
3432 incr n -1
3433 incr lno
3548 - incr ol
3434 + incr blame_data($w,blame_lines)
3435 }
3436 } elseif {[regexp {^([a-z-]+) (.*)$} $line line header data]} {
3437 set blame_data($w,$blame_data($w,commit),$header) $data
3438 }
3439 }
3440
3555 - $w_commit conf -state disabled
3556 - $w_author conf -state disabled
3557 - $w_date conf -state disabled
3558 - $w_filename conf -state disabled
3559 - $w_olno conf -state disabled
3560 -
3441 if {[eof $fd]} {
3442 close $fd
3443 set blame_status($w) {Annotation complete.}
3444 + } else {
3445 + blame_incremental_status $w
3446 }
3447 }
3448
3567 -proc blame_highlight {w pos args} {
3568 - set lno [lindex [split [$w index $pos] .] 0]
3569 - foreach i $args {
3570 - $i tag remove in_sel 0.0 end
3571 - }
3449 +proc blame_incremental_status {w} {
3450 + global blame_status blame_data
3451 +
3452 + set blame_status($w) [format \
3453 + "Loading annotations... %i of %i lines annotated (%2i%%)" \
3454 + $blame_data($w,blame_lines) \
3455 + $blame_data($w,total_lines) \
3456 + [expr {100 * $blame_data($w,blame_lines)
3457 + / $blame_data($w,total_lines)}]]
3458 +}
3459 +
3460 +proc blame_highlight {w w_cmit w_line w_file cur_w pos} {
3461 + set lno [lindex [split [$cur_w index $pos] .] 0]
3462 if {$lno eq {}} return
3573 - foreach i $args {
3574 - $i tag add in_sel $lno.0 "$lno.0 + 1 line"
3463 +
3464 + $w_line tag remove in_sel 0.0 end
3465 + $w_file tag remove in_sel 0.0 end
3466 + $w_line tag add in_sel $lno.0 "$lno.0 + 1 line"
3467 + $w_file tag add in_sel $lno.0 "$lno.0 + 1 line"
3468 +
3469 + blame_showcommit $w $w_cmit $w_line $w_file $lno
3470 +}
3471 +
3472 +proc blame_showcommit {w w_cmit w_line w_file lno} {
3473 + global blame_data repo_config
3474 +
3475 + set cmit $blame_data($w,highlight_commit)
3476 + if {$cmit ne {}} {
3477 + $w_line tag conf g$cmit -background white
3478 + $w_file tag conf g$cmit -background white
3479 + $w_line tag raise annotated g$cmit
3480 }
3481 +
3482 + $w_cmit conf -state normal
3483 + $w_cmit delete 0.0 end
3484 + if {[catch {set cmit $blame_data($w,line$lno,commit)}]} {
3485 + set cmit {}
3486 + $w_cmit insert end "Computing..."
3487 + } else {
3488 + $w_line tag conf g$cmit -background yellow
3489 + $w_file tag conf g$cmit -background yellow
3490 + $w_line tag raise g$cmit annotated
3491 +
3492 + if {[catch {set msg $blame_data($w,$cmit,message)}]} {
3493 + set msg {}
3494 + catch {
3495 + set fd [open "| git cat-file commit $cmit" r]
3496 + fconfigure $fd -encoding binary -translation lf
3497 + if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
3498 + set enc utf-8
3499 + }
3500 + while {[gets $fd line] > 0} {
3501 + if {[string match {encoding *} $line]} {
3502 + set enc [string tolower [string range $line 9 end]]
3503 + }
3504 + }
3505 + fconfigure $fd -encoding $enc
3506 + set msg [string trim [read $fd]]
3507 + close $fd
3508 + }
3509 + set blame_data($w,$cmit,message) $msg
3510 + }
3511 +
3512 + set author_name {}
3513 + set author_email {}
3514 + set author_time {}
3515 + catch {set author_name $blame_data($w,$cmit,author)}
3516 + catch {set author_email $blame_data($w,$cmit,author-mail)}
3517 + catch {set author_time [clock format $blame_data($w,$cmit,author-time)]}
3518 +
3519 + set committer_name {}
3520 + set committer_email {}
3521 + set committer_time {}
3522 + catch {set committer_name $blame_data($w,$cmit,committer)}
3523 + catch {set committer_email $blame_data($w,$cmit,committer-mail)}
3524 + catch {set committer_time [clock format $blame_data($w,$cmit,committer-time)]}
3525 +
3526 + $w_cmit insert end "commit $cmit\n"
3527 + $w_cmit insert end "Author: $author_name $author_email $author_time\n"
3528 + $w_cmit insert end "Committer: $committer_name $committer_email $committer_time\n"
3529 + $w_cmit insert end "Original File: [escape_path $blame_data($w,line$lno,file)]\n"
3530 + $w_cmit insert end "\n"
3531 + $w_cmit insert end $msg
3532 + }
3533 + $w_cmit conf -state disabled
3534 +
3535 + set blame_data($w,highlight_line) $lno
3536 + set blame_data($w,highlight_commit) $cmit
3537 }
3538
3539 proc blame_copycommit {w i pos} {