git-gui: Switch internal blame structure to Tcl lists
[git/jrn.git] / lib / blame.tcl
blobd8d27c9cbf31fda84024bd4060a795c7d720ba6e
1 # git-gui blame viewer
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 class blame {
6 image create photo ::blame::img_back_arrow -data {R0lGODlhGAAYAIUAAPwCBEzKXFTSZIz+nGzmhGzqfGTidIT+nEzGXHTqhGzmfGzifFzadETCVES+VARWDFzWbHzyjAReDGTadFTOZDSyRDyyTCymPARaFGTedFzSbDy2TCyqRCyqPARaDAyCHES6VDy6VCyiPAR6HCSeNByWLARyFARiDARqFGTifARiFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAYABgAAAajQIBwSCwaj8ikcsk0BppJwRPqHEypQwHBis0WDAdEFyBIKBaMAKLBdjQeSkFBYTBAIvgEoS6JmhUTEwIUDQ4VFhcMGEhyCgoZExoUaxsWHB0THkgfAXUGAhoBDSAVFR0XBnCbDRmgog0hpSIiDJpJIyEQhBUcJCIlwA22SSYVogknEg8eD82qSigdDSknY0IqJQXPYxIl1dZCGNvWw+Dm510GQQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7}
8 # Persistant data (survives loads)
10 field history {}; # viewer history: {commit path}
11 field header ; # array commit,key -> header field
13 # Tk UI control paths
15 field w ; # top window in this viewer
16 field w_back ; # our back button
17 field w_path ; # label showing the current file path
18 field w_columns ; # list of all column widgets in the viewer
19 field w_line ; # text column: all line numbers
20 field w_cgrp ; # text column: abbreviated commit SHA-1s
21 field w_file ; # text column: actual file data
22 field w_cmit ; # pane showing commit message
23 field status ; # text variable bound to status bar
24 field old_height ; # last known height of $w.file_pane
26 # Tk UI colors
28 field active_color #c0edc5
29 field group_colors {
30 #d6d6d6
31 #e1e1e1
32 #ececec
35 # Current blame data; cleared/reset on each load
37 field commit ; # input commit to blame
38 field path ; # input filename to view in $commit
40 field current_fd {} ; # background process running
41 field highlight_line -1 ; # current line selected
42 field highlight_commit {} ; # sha1 of commit selected
43 field old_bgcolor {} ; # background of current selection
45 field total_lines 0 ; # total length of file
46 field blame_lines 0 ; # number of lines computed
47 field have_commit ; # array commit -> 1
48 field line_data ; # list of {commit origfile origline}
50 field r_commit ; # commit currently being parsed
51 field r_orig_line ; # original line number
52 field r_final_line ; # final line number
53 field r_line_count ; # lines in this region
55 field tooltip_wm {} ; # Current tooltip toplevel, if open
56 field tooltip_timer {} ; # Current timer event for our tooltip
57 field tooltip_commit {} ; # Commit in tooltip
58 field tooltip_text {} ; # Text in current tooltip
60 constructor new {i_commit i_path} {
61 global cursor_ptr
63 set commit $i_commit
64 set path $i_path
66 make_toplevel top w
67 wm title $top "[appname] ([reponame]): File Viewer"
69 frame $w.header -background orange
70 label $w.header.commit_l \
71 -text {Commit:} \
72 -background orange \
73 -anchor w \
74 -justify left
75 set w_back $w.header.commit_b
76 label $w_back \
77 -image ::blame::img_back_arrow \
78 -borderwidth 0 \
79 -relief flat \
80 -state disabled \
81 -background orange \
82 -activebackground orange
83 bind $w_back <Button-1> "
84 if {\[$w_back cget -state\] eq {normal}} {
85 [cb _history_menu]
88 label $w.header.commit \
89 -textvariable @commit \
90 -background orange \
91 -anchor w \
92 -justify left
93 label $w.header.path_l \
94 -text {File:} \
95 -background orange \
96 -anchor w \
97 -justify left
98 set w_path $w.header.path
99 label $w_path \
100 -background orange \
101 -anchor w \
102 -justify left
103 pack $w.header.commit_l -side left
104 pack $w_back -side left
105 pack $w.header.commit -side left
106 pack $w_path -fill x -side right
107 pack $w.header.path_l -side right
109 panedwindow $w.file_pane -orient vertical
110 frame $w.file_pane.out
111 frame $w.file_pane.cm
112 $w.file_pane add $w.file_pane.out \
113 -sticky nsew \
114 -minsize 100 \
115 -height 100 \
116 -width 100
117 $w.file_pane add $w.file_pane.cm \
118 -sticky nsew \
119 -minsize 25 \
120 -height 25 \
121 -width 100
123 set w_line $w.file_pane.out.linenumber_t
124 text $w_line \
125 -takefocus 0 \
126 -highlightthickness 0 \
127 -padx 0 -pady 0 \
128 -background white -borderwidth 0 \
129 -state disabled \
130 -wrap none \
131 -height 40 \
132 -width 6 \
133 -font font_diff
134 $w_line tag conf linenumber -justify right -rmargin 5
136 set w_cgrp $w.file_pane.out.commit_t
137 text $w_cgrp \
138 -takefocus 0 \
139 -highlightthickness 0 \
140 -padx 0 -pady 0 \
141 -background white -borderwidth 0 \
142 -state disabled \
143 -wrap none \
144 -height 40 \
145 -width 4 \
146 -font font_diff
147 $w_cgrp tag conf curr_commit
148 $w_cgrp tag conf prior_commit \
149 -foreground blue \
150 -underline 1
151 $w_cgrp tag bind prior_commit \
152 <Button-1> \
153 "[cb _load_commit @%x,%y];break"
155 set w_file $w.file_pane.out.file_t
156 text $w_file \
157 -takefocus 0 \
158 -highlightthickness 0 \
159 -padx 0 -pady 0 \
160 -background white -borderwidth 0 \
161 -state disabled \
162 -wrap none \
163 -height 40 \
164 -width 80 \
165 -xscrollcommand [list $w.file_pane.out.sbx set] \
166 -font font_diff
168 set w_columns [list $w_cgrp $w_line $w_file]
170 scrollbar $w.file_pane.out.sbx \
171 -orient h \
172 -command [list $w_file xview]
173 scrollbar $w.file_pane.out.sby \
174 -orient v \
175 -command [list scrollbar2many $w_columns yview]
176 eval grid $w_columns $w.file_pane.out.sby -sticky nsew
177 grid conf \
178 $w.file_pane.out.sbx \
179 -column [expr {[llength $w_columns] - 1}] \
180 -sticky we
181 grid columnconfigure \
182 $w.file_pane.out \
183 [expr {[llength $w_columns] - 1}] \
184 -weight 1
185 grid rowconfigure $w.file_pane.out 0 -weight 1
187 set w_cmit $w.file_pane.cm.t
188 text $w_cmit \
189 -background white -borderwidth 0 \
190 -state disabled \
191 -wrap none \
192 -height 10 \
193 -width 80 \
194 -xscrollcommand [list $w.file_pane.cm.sbx set] \
195 -yscrollcommand [list $w.file_pane.cm.sby set] \
196 -font font_diff
197 $w_cmit tag conf header_key \
198 -tabs {3c} \
199 -background $active_color \
200 -font font_uibold
201 $w_cmit tag conf header_val \
202 -background $active_color \
203 -font font_ui
204 $w_cmit tag raise sel
205 scrollbar $w.file_pane.cm.sbx \
206 -orient h \
207 -command [list $w_cmit xview]
208 scrollbar $w.file_pane.cm.sby \
209 -orient v \
210 -command [list $w_cmit yview]
211 pack $w.file_pane.cm.sby -side right -fill y
212 pack $w.file_pane.cm.sbx -side bottom -fill x
213 pack $w_cmit -expand 1 -fill both
215 frame $w.status \
216 -borderwidth 1 \
217 -relief sunken
218 label $w.status.l \
219 -textvariable @status \
220 -anchor w \
221 -justify left
222 pack $w.status.l -side left
224 menu $w.ctxm -tearoff 0
225 $w.ctxm add command \
226 -label "Copy Commit" \
227 -command [cb _copycommit]
229 foreach i $w_columns {
230 $i conf -cursor $cursor_ptr
231 $i conf -yscrollcommand [list many2scrollbar \
232 $w_columns yview $w.file_pane.out.sby]
233 bind $i <Button-1> "
234 [cb _hide_tooltip]
235 [cb _click $i @%x,%y]
236 focus $i
238 bind $i <Any-Motion> [cb _show_tooltip $i @%x,%y]
239 bind $i <Any-Enter> [cb _hide_tooltip]
240 bind $i <Any-Leave> [cb _hide_tooltip]
241 bind_button3 $i "
242 [cb _hide_tooltip]
243 set cursorX %x
244 set cursorY %y
245 set cursorW %W
246 tk_popup $w.ctxm %X %Y
250 foreach i [concat $w_columns $w_cmit] {
251 bind $i <Key-Up> {catch {%W yview scroll -1 units};break}
252 bind $i <Key-Down> {catch {%W yview scroll 1 units};break}
253 bind $i <Key-Left> {catch {%W xview scroll -1 units};break}
254 bind $i <Key-Right> {catch {%W xview scroll 1 units};break}
255 bind $i <Key-k> {catch {%W yview scroll -1 units};break}
256 bind $i <Key-j> {catch {%W yview scroll 1 units};break}
257 bind $i <Key-h> {catch {%W xview scroll -1 units};break}
258 bind $i <Key-l> {catch {%W xview scroll 1 units};break}
259 bind $i <Control-Key-b> {catch {%W yview scroll -1 pages};break}
260 bind $i <Control-Key-f> {catch {%W yview scroll 1 pages};break}
263 bind $w_cmit <Button-1> [list focus $w_cmit]
264 bind $top <Visibility> [list focus $top]
265 bind $w_file <Destroy> [list delete_this $this]
267 grid configure $w.header -sticky ew
268 grid configure $w.file_pane -sticky nsew
269 grid configure $w.status -sticky ew
270 grid columnconfigure $top 0 -weight 1
271 grid rowconfigure $top 0 -weight 0
272 grid rowconfigure $top 1 -weight 1
273 grid rowconfigure $top 2 -weight 0
275 set req_w [winfo reqwidth $top]
276 set req_h [winfo reqheight $top]
277 if {$req_w < 600} {set req_w 600}
278 if {$req_h < 400} {set req_h 400}
279 set g "${req_w}x${req_h}"
280 wm geometry $top $g
281 update
283 set old_height [winfo height $w.file_pane]
284 $w.file_pane sash place 0 \
285 [lindex [$w.file_pane sash coord 0] 0] \
286 [expr {int($old_height * 0.70)}]
287 bind $w.file_pane <Configure> \
288 "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
290 _load $this
293 method _load {} {
294 _hide_tooltip $this
296 if {$total_lines != 0 || $current_fd ne {}} {
297 if {$current_fd ne {}} {
298 catch {close $current_fd}
299 set current_fd {}
302 foreach i $w_columns {
303 $i conf -state normal
304 $i delete 0.0 end
305 foreach cmit [array names have_commit] {
306 $i tag delete g$cmit
308 $i conf -state disabled
311 set highlight_line -1
312 set highlight_commit {}
313 set total_lines 0
314 set blame_lines 0
315 array unset have_commit
318 if {[winfo exists $w.status.c]} {
319 $w.status.c coords bar 0 0 0 20
320 } else {
321 canvas $w.status.c \
322 -width 100 \
323 -height [expr {int([winfo reqheight $w.status.l] * 0.6)}] \
324 -borderwidth 1 \
325 -relief groove \
326 -highlightt 0
327 $w.status.c create rectangle 0 0 0 20 -tags bar -fill navy
328 pack $w.status.c -side right
331 if {$history eq {}} {
332 $w_back conf -state disabled
333 } else {
334 $w_back conf -state normal
336 lappend history [list $commit $path]
338 # Index 0 is always empty. There is never line 0 as
339 # we use only 1 based lines, as that matches both with
340 # git-blame output and with Tk's text widget.
342 set line_data [list [list]]
344 set status "Loading $commit:[escape_path $path]..."
345 $w_path conf -text [escape_path $path]
346 if {$commit eq {}} {
347 set fd [open $path r]
348 } else {
349 set cmd [list git cat-file blob "$commit:$path"]
350 set fd [open "| $cmd" r]
352 fconfigure $fd -blocking 0 -translation lf -encoding binary
353 fileevent $fd readable [cb _read_file $fd]
354 set current_fd $fd
357 method _history_menu {} {
358 set m $w.backmenu
359 if {[winfo exists $m]} {
360 $m delete 0 end
361 } else {
362 menu $m -tearoff 0
365 for {set i [expr {[llength $history] - 2}]
366 } {$i >= 0} {incr i -1} {
367 set e [lindex $history $i]
368 set c [lindex $e 0]
369 set f [lindex $e 1]
371 if {[regexp {^[0-9a-f]{40}$} $c]} {
372 set t [string range $c 0 8]...
373 } else {
374 set t $c
376 if {![catch {set summary $header($c,summary)}]} {
377 append t " $summary"
378 if {[string length $t] > 70} {
379 set t [string range $t 0 66]...
383 $m add command -label $t -command [cb _goback $i $c $f]
385 set X [winfo rootx $w_back]
386 set Y [expr {[winfo rooty $w_back] + [winfo height $w_back]}]
387 tk_popup $m $X $Y
390 method _goback {i c f} {
391 set history [lrange $history 0 [expr {$i - 1}]]
392 set commit $c
393 set path $f
394 _load $this
397 method _read_file {fd} {
398 if {$fd ne $current_fd} {
399 catch {close $fd}
400 return
403 foreach i $w_columns {$i conf -state normal}
404 while {[gets $fd line] >= 0} {
405 regsub "\r\$" $line {} line
406 incr total_lines
407 lappend line_data {}
409 if {$total_lines > 1} {
410 foreach i $w_columns {$i insert end "\n"}
413 $w_line insert end "$total_lines" linenumber
414 $w_file insert end "$line"
417 set ln_wc [expr {[string length $total_lines] + 2}]
418 if {[$w_line cget -width] < $ln_wc} {
419 $w_line conf -width $ln_wc
422 foreach i $w_columns {$i conf -state disabled}
424 if {[eof $fd]} {
425 close $fd
427 _status $this
428 set cmd {nice git blame -M -C --incremental}
429 if {$commit eq {}} {
430 lappend cmd --contents $path
431 } else {
432 lappend cmd $commit
434 lappend cmd -- $path
435 set fd [open "| $cmd" r]
436 fconfigure $fd -blocking 0 -translation lf -encoding binary
437 fileevent $fd readable [cb _read_blame $fd]
438 set current_fd $fd
440 } ifdeleted { catch {close $fd} }
442 method _read_blame {fd} {
443 if {$fd ne $current_fd} {
444 catch {close $fd}
445 return
448 $w_cgrp conf -state normal
449 while {[gets $fd line] >= 0} {
450 if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
451 cmit original_line final_line line_count]} {
452 set r_commit $cmit
453 set r_orig_line $original_line
454 set r_final_line $final_line
455 set r_line_count $line_count
457 if {[catch {set g $have_commit($cmit)}]} {
458 set bg [lindex $group_colors 0]
459 set group_colors [lrange $group_colors 1 end]
460 lappend group_colors $bg
461 foreach i $w_columns {
462 $i tag conf g$cmit -background $bg
464 set have_commit($cmit) 1
466 } elseif {[string match {filename *} $line]} {
467 set file [string range $line 9 end]
468 set n $r_line_count
469 set lno $r_final_line
470 set cmit $r_commit
472 if {[regexp {^0{40}$} $cmit]} {
473 set commit_abbr work
474 set commit_type curr_commit
475 } elseif {$cmit eq $commit} {
476 set commit_abbr this
477 set commit_type curr_commit
478 } else {
479 set commit_type prior_commit
480 set commit_abbr [string range $cmit 0 4]
483 set author_abbr {}
484 set a_name {}
485 catch {set a_name $header($cmit,author)}
486 while {$a_name ne {}} {
487 if {![regexp {^([[:upper:]])} $a_name _a]} break
488 append author_abbr $_a
489 unset _a
490 if {![regsub \
491 {^[[:upper:]][^\s]*\s+} \
492 $a_name {} a_name ]} break
494 if {$author_abbr eq {}} {
495 set author_abbr { |}
496 } else {
497 set author_abbr [string range $author_abbr 0 3]
498 while {[string length $author_abbr] < 4} {
499 set author_abbr " $author_abbr"
502 unset a_name
504 set first_lno $lno
505 while {
506 $first_lno > 1
507 && $cmit eq [lindex $line_data [expr {$first_lno - 1}] 0]
508 && $file eq [lindex $line_data [expr {$first_lno - 1}] 1]
510 incr first_lno -1
513 while {$n > 0} {
514 set lno_e "$lno.0 lineend + 1c"
515 if {[lindex $line_data $lno] ne {}} {
516 set g [lindex $line_data $lno 0]
517 foreach i $w_columns {
518 $i tag remove g$g $lno.0 $lno_e
521 lset line_data $lno [list $cmit $file]
523 $w_cgrp delete $lno.0 "$lno.0 lineend"
524 if {$lno == $first_lno} {
525 $w_cgrp insert $lno.0 $commit_abbr $commit_type
526 } elseif {$lno == [expr {$first_lno + 1}]} {
527 $w_cgrp insert $lno.0 $author_abbr
528 } else {
529 $w_cgrp insert $lno.0 { |}
532 foreach i $w_columns {
533 $i tag add g$cmit $lno.0 $lno_e
536 if {$highlight_line == -1} {
537 if {[lindex [$w_file yview] 0] == 0} {
538 $w_file see $lno.0
539 _showcommit $this $lno
541 } elseif {$highlight_line == $lno} {
542 _showcommit $this $lno
545 incr n -1
546 incr lno
547 incr blame_lines
550 while {
551 $cmit eq [lindex $line_data $lno 0]
552 && $file eq [lindex $line_data $lno 1]
554 $w_cgrp delete $lno.0 "$lno.0 lineend"
556 if {$lno == $first_lno} {
557 $w_cgrp insert $lno.0 $commit_abbr $commit_type
558 } elseif {$lno == [expr {$first_lno + 1}]} {
559 $w_cgrp insert $lno.0 $author_abbr
560 } else {
561 $w_cgrp insert $lno.0 { |}
563 incr lno
566 } elseif {[regexp {^([a-z-]+) (.*)$} $line line key data]} {
567 set header($r_commit,$key) $data
570 $w_cgrp conf -state disabled
572 if {[eof $fd]} {
573 close $fd
574 set current_fd {}
575 set status {Annotation complete.}
576 destroy $w.status.c
577 } else {
578 _status $this
580 } ifdeleted { catch {close $fd} }
582 method _status {} {
583 set have $blame_lines
584 set total $total_lines
585 set pdone 0
586 if {$total} {set pdone [expr {100 * $have / $total}]}
588 set status [format \
589 "Loading annotations... %i of %i lines annotated (%2i%%)" \
590 $have $total $pdone]
591 $w.status.c coords bar 0 0 $pdone 20
594 method _click {cur_w pos} {
595 set lno [lindex [split [$cur_w index $pos] .] 0]
596 if {$lno eq {}} return
597 _showcommit $this $lno
600 method _load_commit {pos} {
601 set lno [lindex [split [$w_cgrp index $pos] .] 0]
602 set dat [lindex $line_data $lno]
603 if {$dat ne {}} {
604 set commit [lindex $dat 0]
605 set path [lindex $dat 1]
606 _load $this
610 method _showcommit {lno} {
611 global repo_config
613 if {$highlight_commit ne {}} {
614 foreach i $w_columns {
615 $i tag conf g$highlight_commit -background $old_bgcolor
619 $w_cmit conf -state normal
620 $w_cmit delete 0.0 end
622 set dat [lindex $line_data $lno]
623 if {$dat eq {}} {
624 set cmit {}
625 $w_cmit insert end "Loading annotation..."
626 } else {
627 set cmit [lindex $dat 0]
628 set file [lindex $dat 1]
630 set old_bgcolor [$w_file tag cget g$cmit -background]
631 foreach i $w_columns {
632 $i tag conf g$cmit -background $active_color
635 set author_name {}
636 set author_email {}
637 set author_time {}
638 catch {set author_name $header($cmit,author)}
639 catch {set author_email $header($cmit,author-mail)}
640 catch {set author_time [clock format \
641 $header($cmit,author-time) \
642 -format {%Y-%m-%d %H:%M:%S}
645 set committer_name {}
646 set committer_email {}
647 set committer_time {}
648 catch {set committer_name $header($cmit,committer)}
649 catch {set committer_email $header($cmit,committer-mail)}
650 catch {set committer_time [clock format \
651 $header($cmit,committer-time) \
652 -format {%Y-%m-%d %H:%M:%S}
655 if {[catch {set msg $header($cmit,message)}]} {
656 set msg {}
657 catch {
658 set fd [open "| git cat-file commit $cmit" r]
659 fconfigure $fd -encoding binary -translation lf
660 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
661 set enc utf-8
663 while {[gets $fd line] > 0} {
664 if {[string match {encoding *} $line]} {
665 set enc [string tolower [string range $line 9 end]]
668 set msg [encoding convertfrom $enc [read $fd]]
669 set msg [string trim $msg]
670 close $fd
672 set author_name [encoding convertfrom $enc $author_name]
673 set committer_name [encoding convertfrom $enc $committer_name]
675 set header($cmit,author) $author_name
676 set header($cmit,committer) $committer_name
678 set header($cmit,message) $msg
681 $w_cmit insert end "commit $cmit\n" header_key
682 $w_cmit insert end "Author:\t" header_key
683 $w_cmit insert end "$author_name $author_email" header_val
684 $w_cmit insert end "$author_time\n" header_val
686 $w_cmit insert end "Committer:\t" header_key
687 $w_cmit insert end "$committer_name $committer_email" header_val
688 $w_cmit insert end "$committer_time\n" header_val
690 if {$file ne $path} {
691 $w_cmit insert end "Original File:\t" header_key
692 $w_cmit insert end "[escape_path $file]\n" header_val
695 $w_cmit insert end "\n$msg"
697 $w_cmit conf -state disabled
699 set highlight_line $lno
700 set highlight_commit $cmit
702 if {$highlight_commit eq $tooltip_commit} {
703 _hide_tooltip $this
707 method _copycommit {} {
708 set pos @$::cursorX,$::cursorY
709 set lno [lindex [split [$::cursorW index $pos] .] 0]
710 set dat [lindex $line_data $lno]
711 if {$dat ne {}} {
712 clipboard clear
713 clipboard append \
714 -format STRING \
715 -type STRING \
716 -- [lindex $dat 0]
720 method _show_tooltip {cur_w pos} {
721 set lno [lindex [split [$cur_w index $pos] .] 0]
722 set dat [lindex $line_data $lno]
723 if {$dat eq {}} {
724 _hide_tooltip $this
725 return
727 set cmit [lindex $dat 0]
729 if {$cmit eq $highlight_commit} {
730 _hide_tooltip $this
731 return
734 if {$cmit eq $tooltip_commit} {
735 _position_tooltip $this
736 } elseif {$tooltip_wm ne {}} {
737 _open_tooltip $this $cur_w
738 } elseif {$tooltip_timer eq {}} {
739 set tooltip_timer [after 1000 [cb _open_tooltip $cur_w]]
743 method _open_tooltip {cur_w} {
744 set tooltip_timer {}
745 set pos_x [winfo pointerx $cur_w]
746 set pos_y [winfo pointery $cur_w]
747 if {[winfo containing $pos_x $pos_y] ne $cur_w} {
748 _hide_tooltip $this
749 return
752 set pos @[join [list \
753 [expr {$pos_x - [winfo rootx $cur_w]}] \
754 [expr {$pos_y - [winfo rooty $cur_w]}]] ,]
755 set lno [lindex [split [$cur_w index $pos] .] 0]
756 set dat [lindex $line_data $lno]
757 set cmit [lindex $dat 0]
758 set file [lindex $dat 1]
760 set author_name {}
761 set author_email {}
762 set author_time {}
763 catch {set author_name $header($cmit,author)}
764 catch {set author_email $header($cmit,author-mail)}
765 catch {set author_time [clock format \
766 $header($cmit,author-time) \
767 -format {%Y-%m-%d %H:%M:%S}
770 set committer_name {}
771 set committer_email {}
772 set committer_time {}
773 catch {set committer_name $header($cmit,committer)}
774 catch {set committer_email $header($cmit,committer-mail)}
775 catch {set committer_time [clock format \
776 $header($cmit,committer-time) \
777 -format {%Y-%m-%d %H:%M:%S}
780 set summary {}
781 catch {set summary $header($cmit,summary)}
783 set tooltip_commit $cmit
784 set tooltip_text "commit $cmit
785 $author_name $author_email $author_time
786 $summary"
788 if {$file ne $path} {
789 append tooltip_text "
791 Original File: $file"
794 if {$tooltip_wm ne "$cur_w.tooltip"} {
795 _hide_tooltip $this
797 set tooltip_wm [toplevel $cur_w.tooltip -borderwidth 1]
798 wm overrideredirect $tooltip_wm 1
799 wm transient $tooltip_wm [winfo toplevel $cur_w]
800 pack [label $tooltip_wm.label \
801 -background lightyellow \
802 -foreground black \
803 -textvariable @tooltip_text \
804 -justify left]
806 _position_tooltip $this
809 method _position_tooltip {} {
810 set req_w [winfo reqwidth $tooltip_wm.label]
811 set req_h [winfo reqheight $tooltip_wm.label]
812 set pos_x [expr {[winfo pointerx .] + 5}]
813 set pos_y [expr {[winfo pointery .] + 10}]
815 set g "${req_w}x${req_h}"
816 if {$pos_x >= 0} {append g +}
817 append g $pos_x
818 if {$pos_y >= 0} {append g +}
819 append g $pos_y
821 wm geometry $tooltip_wm $g
822 raise $tooltip_wm
825 method _hide_tooltip {} {
826 if {$tooltip_wm ne {}} {
827 destroy $tooltip_wm
828 set tooltip_wm {}
829 set tooltip_commit {}
831 if {$tooltip_timer ne {}} {
832 after cancel $tooltip_timer
833 set tooltip_timer {}
837 method _resize {new_height} {
838 set diff [expr {$new_height - $old_height}]
839 if {$diff == 0} return
841 set my [expr {[winfo height $w.file_pane] - 25}]
842 set o [$w.file_pane sash coord 0]
843 set ox [lindex $o 0]
844 set oy [expr {[lindex $o 1] + $diff}]
845 if {$oy < 0} {set oy 0}
846 if {$oy > $my} {set oy $my}
847 $w.file_pane sash place 0 $ox $oy
849 set old_height $new_height