2 # Copyright (C) 2006, 2007 Shawn Pearce
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
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_amov
; # text column: annotations + move tracking
21 field w_asim
; # text column: annotations (simple computation)
22 field w_file
; # text column: actual file data
23 field w_cviewer
; # pane showing commit message
24 field status
; # status mega-widget instance
25 field old_height
; # last known height of $w.file_pane
29 variable active_color
#c0edc5
30 variable group_colors
{
36 # Current blame data; cleared/reset on each load
38 field commit
; # input commit to blame
39 field path
; # input filename to view in $commit
41 field current_fd
{} ; # background process running
42 field highlight_line
-1 ; # current line selected
43 field highlight_column
{} ; # current commit column selected
44 field highlight_commit
{} ; # sha1 of commit selected
46 field total_lines
0 ; # total length of file
47 field blame_lines
0 ; # number of lines computed
48 field amov_data
; # list of {commit origfile origline}
49 field asim_data
; # list of {commit origfile origline}
51 field r_commit
; # commit currently being parsed
52 field r_orig_line
; # original line number
53 field r_final_line
; # final line number
54 field r_line_count
; # lines in this region
56 field tooltip_wm
{} ; # Current tooltip toplevel, if open
57 field tooltip_t
{} ; # Text widget in $tooltip_wm
58 field tooltip_timer
{} ; # Current timer event for our tooltip
59 field tooltip_commit
{} ; # Commit(s) in tooltip
61 constructor new
{i_commit i_path i_jump
} {
70 wm title
$top [append "[appname] ([reponame]): " [mc
"File Viewer"]]
72 frame $w.header
-background gold
73 label $w.header.commit_l
\
74 -text [mc
"Commit:"] \
79 set w_back
$w.header.commit_b
81 -image ::blame::img_back_arrow \
87 -activebackground gold
88 bind $w_back <Button-1
> "
89 if {\[$w_back cget -state\] eq {normal}} {
93 label $w.header.commit
\
94 -textvariable @commit
\
99 label $w.header.path_l
\
105 set w_path
$w.header.path
111 pack $w.header.commit_l
-side left
112 pack $w_back -side left
113 pack $w.header.commit
-side left
114 pack $w_path -fill x
-side right
115 pack $w.header.path_l
-side right
117 panedwindow $w.file_pane
-orient vertical
118 frame $w.file_pane.out
119 frame $w.file_pane.cm
120 $w.file_pane add
$w.file_pane.out
\
125 $w.file_pane add
$w.file_pane.cm
\
131 set w_line
$w.file_pane.out.linenumber_t
134 -highlightthickness 0 \
144 $w_line tag conf linenumber
-justify right
-rmargin 5
146 set w_amov
$w.file_pane.out.amove_t
149 -highlightthickness 0 \
159 $w_amov tag conf author_abbr
-justify right
-rmargin 5
160 $w_amov tag conf curr_commit
161 $w_amov tag conf prior_commit
-foreground blue
-underline 1
162 $w_amov tag
bind prior_commit
\
164 "[cb _load_commit $w_amov @amov_data @%x,%y];break"
166 set w_asim
$w.file_pane.out.asimple_t
169 -highlightthickness 0 \
179 $w_asim tag conf author_abbr
-justify right
180 $w_asim tag conf curr_commit
181 $w_asim tag conf prior_commit
-foreground blue
-underline 1
182 $w_asim tag
bind prior_commit
\
184 "[cb _load_commit $w_asim @asim_data @%x,%y];break"
186 set w_file
$w.file_pane.out.file_t
189 -highlightthickness 0 \
198 -xscrollcommand [list $w.file_pane.out.sbx
set] \
201 set w_columns
[list $w_amov $w_asim $w_line $w_file]
203 scrollbar $w.file_pane.out.sbx
\
205 -command [list $w_file xview
]
206 scrollbar $w.file_pane.out.sby
\
208 -command [list scrollbar2many
$w_columns yview
]
209 eval grid $w_columns $w.file_pane.out.sby
-sticky nsew
211 $w.file_pane.out.sbx
\
212 -column [expr {[llength $w_columns] - 1}] \
214 grid columnconfigure
\
216 [expr {[llength $w_columns] - 1}] \
218 grid rowconfigure
$w.file_pane.out
0 -weight 1
220 set w_cviewer
$w.file_pane.cm.t
229 -xscrollcommand [list $w.file_pane.cm.sbx
set] \
230 -yscrollcommand [list $w.file_pane.cm.sby
set] \
232 $w_cviewer tag conf still_loading
\
233 -font font_uiitalic
\
235 $w_cviewer tag conf header_key
\
237 -background $active_color \
239 $w_cviewer tag conf header_val
\
240 -background $active_color \
242 $w_cviewer tag
raise sel
243 scrollbar $w.file_pane.cm.sbx
\
245 -command [list $w_cviewer xview
]
246 scrollbar $w.file_pane.cm.sby
\
248 -command [list $w_cviewer yview
]
249 pack $w.file_pane.cm.sby
-side right
-fill y
250 pack $w.file_pane.cm.sbx
-side bottom
-fill x
251 pack $w_cviewer -expand 1 -fill both
253 set status
[::status_bar::new $w.status
]
255 menu $w.ctxm
-tearoff 0
256 $w.ctxm add command
\
257 -label [mc
"Copy Commit"] \
258 -command [cb _copycommit
]
259 $w.ctxm add separator
261 build_encoding_menu
$w.ctxm.enc
[cb _setencoding
]
262 $w.ctxm add cascade
\
263 -label [mc
"Encoding"] \
265 $w.ctxm add command
\
266 -label [mc
"Do Full Copy Detection"] \
267 -command [cb _fullcopyblame
]
268 $w.ctxm add separator
269 $w.ctxm add command
\
270 -label [mc
"Show History Context"] \
271 -command [cb _gitkcommit
]
272 $w.ctxm add command
\
273 -label [mc
"Blame Parent Commit"] \
274 -command [cb _blameparent
]
276 foreach i
$w_columns {
277 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
278 $i tag conf color
$g -background [lindex $group_colors $g]
281 $i conf
-cursor $cursor_ptr
282 $i conf
-yscrollcommand [list many2scrollbar
\
283 $w_columns yview
$w.file_pane.out.sby
]
286 [cb _click $i @%x,%y]
289 bind $i <Any-Motion
> [cb _show_tooltip
$i @%x
,%y
]
290 bind $i <Any-Enter
> [cb _hide_tooltip
]
291 bind $i <Any-Leave
> [cb _hide_tooltip
]
297 tk_popup $w.ctxm %X %Y
299 bind $i <Shift-Tab
> "[list focus $w_cviewer];break"
300 bind $i <Tab
> "[list focus $w_cviewer];break"
303 foreach i
[concat $w_columns $w_cviewer] {
304 bind $i <Key-Up
> {catch {%W yview scroll
-1 units
};break}
305 bind $i <Key-Down
> {catch {%W yview scroll
1 units
};break}
306 bind $i <Key-Left
> {catch {%W xview scroll
-1 units
};break}
307 bind $i <Key-Right
> {catch {%W xview scroll
1 units
};break}
308 bind $i <Key-k
> {catch {%W yview scroll
-1 units
};break}
309 bind $i <Key-j
> {catch {%W yview scroll
1 units
};break}
310 bind $i <Key-h
> {catch {%W xview scroll
-1 units
};break}
311 bind $i <Key-l
> {catch {%W xview scroll
1 units
};break}
312 bind $i <Control-Key-b
> {catch {%W yview scroll
-1 pages
};break}
313 bind $i <Control-Key-f
> {catch {%W yview scroll
1 pages
};break}
316 bind $w_cviewer <Shift-Tab
> "[list focus $w_file];break"
317 bind $w_cviewer <Tab
> "[list focus $w_file];break"
318 bind $w_cviewer <Button-1
> [list focus $w_cviewer]
319 bind $w_file <Visibility
> [list focus $w_file]
321 grid configure
$w.header
-sticky ew
322 grid configure
$w.file_pane
-sticky nsew
323 grid configure
$w.status
-sticky ew
324 grid columnconfigure
$top 0 -weight 1
325 grid rowconfigure
$top 0 -weight 0
326 grid rowconfigure
$top 1 -weight 1
327 grid rowconfigure
$top 2 -weight 0
329 set req_w
[winfo reqwidth
$top]
330 set req_h
[winfo reqheight
$top]
331 set scr_h
[expr {[winfo screenheight
$top] - 100}]
332 if {$req_w < 600} {set req_w
600}
333 if {$req_h < $scr_h} {set req_h
$scr_h}
334 set g
"${req_w}x${req_h}"
338 set old_height
[winfo height
$w.file_pane
]
339 $w.file_pane sash
place 0 \
340 [lindex [$w.file_pane sash coord
0] 0] \
341 [expr {int
($old_height * 0.70)}]
342 bind $w.file_pane
<Configure
> \
343 "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
345 wm protocol
$top WM_DELETE_WINDOW
"destroy $top"
346 bind $top <Destroy
> [cb _kill
]
352 if {$current_fd ne
{}} {
353 kill_file_process
$current_fd
354 catch {close $current_fd}
359 method _load
{jump
} {
360 variable group_colors
364 if {$total_lines != 0 ||
$current_fd ne
{}} {
367 foreach i
$w_columns {
368 $i conf
-state normal
370 foreach g
[$i tag names
] {
371 if {[regexp {^g
[0-9a-f
]{40}$} $g]} {
375 $i conf
-state disabled
378 $w_cviewer conf
-state normal
379 $w_cviewer delete
0.0 end
380 $w_cviewer conf
-state disabled
382 set highlight_line
-1
383 set highlight_column
{}
384 set highlight_commit
{}
388 if {$history eq
{}} {
389 $w_back conf
-state disabled
391 $w_back conf
-state normal
394 # Index 0 is always empty. There is never line 0 as
395 # we use only 1 based lines, as that matches both with
396 # git-blame output and with Tk's text widget.
398 set amov_data
[list [list]]
399 set asim_data
[list [list]]
401 $status show
[mc
"Reading %s..." "$commit:[escape_path $path]"]
402 $w_path conf
-text [escape_path
$path]
404 set fd
[open $path r
]
405 fconfigure $fd -eofchar {}
407 set fd
[git_read cat-file blob
"$commit:$path"]
412 -encoding [get_path_encoding
$path]
413 fileevent $fd readable
[cb _read_file
$fd $jump]
417 method _history_menu
{} {
419 if {[winfo exists
$m]} {
425 for {set i
[expr {[llength $history] - 1}]
426 } {$i >= 0} {incr i
-1} {
427 set e
[lindex $history $i]
431 if {[regexp {^
[0-9a-f
]{40}$} $c]} {
432 set t
[string range
$c 0 8]...
433 } elseif
{$c eq
{}} {
434 set t
{Working Directory
}
438 if {![catch {set summary
$header($c,summary
)}]} {
440 if {[string length
$t] > 70} {
441 set t
[string range
$t 0 66]...
445 $m add command
-label $t -command [cb _goback
$i]
447 set X
[winfo rootx
$w_back]
448 set Y
[expr {[winfo rooty
$w_back] + [winfo height
$w_back]}]
453 set dat
[lindex $history $i]
454 set history [lrange $history 0 [expr {$i - 1}]]
455 set commit
[lindex $dat 0]
456 set path
[lindex $dat 1]
457 _load
$this [lrange $dat 2 5]
460 method _read_file
{fd jump
} {
461 if {$fd ne
$current_fd} {
466 foreach i
$w_columns {$i conf
-state normal
}
467 while {[gets $fd line
] >= 0} {
468 regsub "\r\$" $line {} line
473 if {$total_lines > 1} {
474 foreach i
$w_columns {$i insert end
"\n"}
477 $w_line insert end
"$total_lines" linenumber
478 $w_file insert end
"$line"
481 set ln_wc
[expr {[string length
$total_lines] + 2}]
482 if {[$w_line cget
-width] < $ln_wc} {
483 $w_line conf
-width $ln_wc
486 foreach i
$w_columns {$i conf
-state disabled
}
491 # If we don't force Tk to update the widgets *right now*
492 # none of our jump commands will cause a change in the UI.
496 if {[llength $jump] == 1} {
497 set highlight_line
[lindex $jump 0]
498 $w_file see
"$highlight_line.0"
499 } elseif
{[llength $jump] == 4} {
500 set highlight_column
[lindex $jump 0]
501 set highlight_line
[lindex $jump 1]
502 $w_file xview moveto
[lindex $jump 2]
503 $w_file yview moveto
[lindex $jump 3]
506 _exec_blame
$this $w_asim @asim_data
\
508 [mc
"Loading copy/move tracking annotations..."]
510 } ifdeleted
{ catch {close $fd} }
512 method _exec_blame
{cur_w cur_d
options cur_s
} {
513 lappend options --incremental
515 lappend options --contents $path
517 lappend options $commit
519 lappend options -- $path
520 set fd
[eval git_read
--nice blame
$options]
521 fconfigure $fd -blocking 0 -translation lf
-encoding utf-8
522 fileevent $fd readable
[cb _read_blame
$fd $cur_w $cur_d]
528 [mc
"lines annotated"]
531 method _read_blame
{fd cur_w cur_d
} {
532 upvar #0 $cur_d line_data
533 variable group_colors
535 if {$fd ne
$current_fd} {
540 $cur_w conf
-state normal
541 while {[gets $fd line
] >= 0} {
542 if {[regexp {^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$} $line line
\
543 cmit original_line final_line line_count
]} {
545 set r_orig_line
$original_line
546 set r_final_line
$final_line
547 set r_line_count
$line_count
548 } elseif
{[string match
{filename *} $line]} {
549 set file [string range
$line 9 end
]
551 set lno
$r_final_line
555 if {[regexp {^
0{40}$} $cmit]} {
557 set commit_type curr_commit
558 } elseif
{$cmit eq
$commit} {
560 set commit_type curr_commit
562 set commit_type prior_commit
563 set commit_abbr
[string range
$cmit 0 3]
568 catch {set a_name
$header($cmit,author
)}
569 while {$a_name ne
{}} {
570 if {$author_abbr ne
{}
571 && [string index
$a_name 0] eq
{'
}} {
572 regsub {^'
[^'
]+'
\s
+} $a_name {} a_name
574 if {![regexp {^
([[:upper
:]])} $a_name _a
]} break
575 append author_abbr
$_a
578 {^
[[:upper
:]][^
\s
]*\s
+} \
579 $a_name {} a_name
]} break
581 if {$author_abbr eq
{}} {
584 set author_abbr
[string range
$author_abbr 0 3]
591 && $cmit eq
[lindex $line_data [expr {$first_lno - 1}] 0]
592 && $file eq
[lindex $line_data [expr {$first_lno - 1}] 1]
598 if {$first_lno < $lno} {
599 foreach g
[$w_file tag names
$first_lno.0] {
600 if {[regexp {^color
[0-9]+$} $g]} {
606 set i
[lsort [concat \
607 [$w_file tag names
"[expr {$first_lno - 1}].0"] \
608 [$w_file tag names
"[expr {$lno + $n}].0"] \
610 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
611 if {[lsearch -sorted -exact $i color
$g] == -1} {
622 set lno_e
"$lno.0 lineend + 1c"
623 if {[lindex $line_data $lno] ne
{}} {
624 set g
[lindex $line_data $lno 0]
625 foreach i
$w_columns {
626 $i tag remove g
$g $lno.0 $lno_e
629 lset line_data
$lno [list $cmit $file $oln]
631 $cur_w delete
$lno.0 "$lno.0 lineend"
632 if {$lno == $first_lno} {
633 $cur_w insert
$lno.0 $commit_abbr $commit_type
634 } elseif
{$lno == [expr {$first_lno + 1}]} {
635 $cur_w insert
$lno.0 $author_abbr author_abbr
637 $cur_w insert
$lno.0 { |
}
640 foreach i
$w_columns {
641 if {$cur_w eq
$w_amov} {
643 {$g < [llength $group_colors]} \
645 $i tag remove color
$g $lno.0 $lno_e
647 $i tag add
$color $lno.0 $lno_e
649 $i tag add g
$cmit $lno.0 $lno_e
652 if {$highlight_column eq
$cur_w} {
653 if {$highlight_line == -1
654 && [lindex [$w_file yview
] 0] == 0} {
656 set highlight_line
$lno
658 if {$highlight_line == $lno} {
659 _showcommit
$this $cur_w $lno
670 $cmit eq
[lindex $line_data $lno 0]
671 && $file eq
[lindex $line_data $lno 1]
673 $cur_w delete
$lno.0 "$lno.0 lineend"
675 if {$lno == $first_lno} {
676 $cur_w insert
$lno.0 $commit_abbr $commit_type
677 } elseif
{$lno == [expr {$first_lno + 1}]} {
678 $cur_w insert
$lno.0 $author_abbr author_abbr
680 $cur_w insert
$lno.0 { |
}
683 if {$cur_w eq
$w_amov} {
684 foreach i
$w_columns {
686 {$g < [llength $group_colors]} \
688 $i tag remove color
$g $lno.0 $lno_e
690 $i tag add
$color $lno.0 $lno_e
697 } elseif
{[regexp {^
([a-z-
]+) (.
*)$} $line line key data
]} {
698 set header
($r_commit,$key) $data
701 $cur_w conf
-state disabled
705 if {$cur_w eq
$w_asim} {
706 # Switches for original location detection
707 set threshold
[get_config gui.copyblamethreshold
]
708 set original_options
[list "-C$threshold"]
710 if {![is_config_true gui.fastcopyblame
]} {
711 # thorough copy search; insert before the threshold
712 set original_options
[linsert $original_options 0 -C]
714 if {[git-version
>= 1.5.3]} {
715 lappend original_options
-w ; # ignore indentation changes
718 _exec_blame
$this $w_amov @amov_data
\
720 [mc
"Loading original location annotations..."]
723 $status stop
[mc
"Annotation complete."]
726 $status update $blame_lines $total_lines
728 } ifdeleted
{ catch {close $fd} }
730 method _find_commit_bound
{data_list start_idx delta
} {
731 upvar #0 $data_list line_data
733 set limit
[expr {[llength $line_data] - 1}]
734 set base_commit
[lindex $line_data $pos 0]
736 while {$pos > 0 && $pos < $limit} {
737 set new_pos
[expr {$pos + $delta}]
738 if {[lindex $line_data $new_pos 0] ne
$base_commit} {
748 method _fullcopyblame
{} {
749 if {$current_fd ne
{}} {
754 -message [mc
"Annotation process is already running."]
759 # Switches for original location detection
760 set threshold
[get_config gui.copyblamethreshold
]
761 set original_options
[list -C -C "-C$threshold"]
763 if {[git-version
>= 1.5.3]} {
764 lappend original_options
-w ; # ignore indentation changes
767 # Find the line range
768 set pos
@$::cursorX,$::cursorY
769 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
770 set min_amov_lno
[_find_commit_bound
$this @amov_data
$lno -1]
771 set max_amov_lno
[_find_commit_bound
$this @amov_data
$lno 1]
772 set min_asim_lno
[_find_commit_bound
$this @asim_data
$lno -1]
773 set max_asim_lno
[_find_commit_bound
$this @asim_data
$lno 1]
775 if {$min_asim_lno < $min_amov_lno} {
776 set min_amov_lno
$min_asim_lno
779 if {$max_asim_lno > $max_amov_lno} {
780 set max_amov_lno
$max_asim_lno
783 lappend original_options
-L "$min_amov_lno,$max_amov_lno"
786 for {set i
$min_amov_lno} {$i <= $max_amov_lno} {incr i
} {
787 lset amov_data
$i [list ]
790 # Start the back-end process
791 _exec_blame
$this $w_amov @amov_data
\
793 [mc
"Running thorough copy detection..."]
796 method _click
{cur_w pos
} {
797 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
798 _showcommit
$this $cur_w $lno
801 method _setencoding
{enc
} {
802 force_path_encoding
$path $enc
806 [lindex [$w_file xview
] 0] \
807 [lindex [$w_file yview
] 0] \
811 method _load_commit
{cur_w cur_d pos
} {
812 upvar #0 $cur_d line_data
813 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
814 set dat
[lindex $line_data $lno]
816 _load_new_commit
$this \
819 [list [lindex $dat 2]]
823 method _load_new_commit
{new_commit new_path jump
} {
824 lappend history [list \
828 [lindex [$w_file xview
] 0] \
829 [lindex [$w_file yview
] 0] \
832 set commit
$new_commit
837 method _showcommit
{cur_w lno
} {
839 variable active_color
841 if {$highlight_commit ne
{}} {
842 foreach i
$w_columns {
843 $i tag conf g
$highlight_commit -background {}
844 $i tag
lower g
$highlight_commit
848 if {$cur_w eq
$w_asim} {
849 set dat
[lindex $asim_data $lno]
850 set highlight_column
$w_asim
852 set dat
[lindex $amov_data $lno]
853 set highlight_column
$w_amov
856 $w_cviewer conf
-state normal
857 $w_cviewer delete
0.0 end
861 $w_cviewer insert end
[mc
"Loading annotation..."] still_loading
863 set cmit
[lindex $dat 0]
864 set file [lindex $dat 1]
866 foreach i
$w_columns {
867 $i tag conf g
$cmit -background $active_color
874 catch {set author_name
$header($cmit,author
)}
875 catch {set author_email
$header($cmit,author-mail
)}
876 catch {set author_time
[format_date
$header($cmit,author-time
)]}
878 set committer_name
{}
879 set committer_email
{}
880 set committer_time
{}
881 catch {set committer_name
$header($cmit,committer
)}
882 catch {set committer_email
$header($cmit,committer-mail
)}
883 catch {set committer_time
[format_date
$header($cmit,committer-time
)]}
885 if {[catch {set msg
$header($cmit,message)}]} {
888 set fd
[git_read cat-file commit
$cmit]
889 fconfigure $fd -encoding binary -translation lf
890 if {[catch {set enc
$repo_config(i18n.commitencoding
)}]} {
893 while {[gets $fd line
] > 0} {
894 if {[string match
{encoding *} $line]} {
895 set enc
[string tolower
[string range
$line 9 end
]]
901 set enc
[tcl_encoding
$enc]
903 set msg
[encoding convertfrom
$enc $msg]
905 set msg
[string trim
$msg]
907 set header
($cmit,message) $msg
910 $w_cviewer insert end
"commit $cmit\n" header_key
911 $w_cviewer insert end
[strcat
[mc
"Author:"] "\t"] header_key
912 $w_cviewer insert end
"$author_name $author_email" header_val
913 $w_cviewer insert end
" $author_time\n" header_val
915 $w_cviewer insert end
[strcat
[mc
"Committer:"] "\t"] header_key
916 $w_cviewer insert end
"$committer_name $committer_email" header_val
917 $w_cviewer insert end
" $committer_time\n" header_val
919 if {$file ne
$path} {
920 $w_cviewer insert end
[strcat
[mc
"Original File:"] "\t"] header_key
921 $w_cviewer insert end
"[escape_path $file]\n" header_val
924 $w_cviewer insert end
"\n$msg"
926 $w_cviewer conf
-state disabled
928 set highlight_line
$lno
929 set highlight_commit
$cmit
931 if {[lsearch -exact $tooltip_commit $highlight_commit] != -1} {
936 method _get_click_amov_info
{} {
937 set pos
@$::cursorX,$::cursorY
938 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
939 return [lindex $amov_data $lno]
942 method _copycommit
{} {
943 set dat
[_get_click_amov_info
$this]
953 method _format_offset_date
{base offset
} {
954 set exval
[expr {$base + $offset*24*60*60}]
955 return [clock format $exval -format {%Y-
%m-
%d
}]
958 method _gitkcommit
{} {
961 set dat
[_get_click_amov_info
$this]
963 set cmit
[lindex $dat 0]
965 # If the line belongs to the working copy, use HEAD instead
966 if {$cmit eq
$nullid} {
967 if {[catch {set cmit
[git rev-parse
--verify HEAD
]} err
]} {
968 error_popup
[strcat
[mc
"Cannot find HEAD commit:"] "\n\n$err"]
973 set radius
[get_config gui.blamehistoryctx
]
974 set cmdline
[list --select-commit
=$cmit]
978 set committer_time
{}
980 catch {set author_time
$header($cmit,author-time
)}
981 catch {set committer_time
$header($cmit,committer-time
)}
983 if {$committer_time eq
{}} {
984 set committer_time
$author_time
987 set after_time
[_format_offset_date
$this $committer_time [expr {-$radius}]]
988 set before_time
[_format_offset_date
$this $committer_time $radius]
990 lappend cmdline
--after=$after_time --before=$before_time
993 lappend cmdline
$cmit
1000 if {$base_rev ne
$cmit} {
1001 lappend cmdline
$base_rev
1008 method _blameparent
{} {
1011 set dat
[_get_click_amov_info
$this]
1013 set cmit
[lindex $dat 0]
1014 set new_path
[lindex $dat 1]
1016 # Allow using Blame Parent on lines modified in the working copy
1017 if {$cmit eq
$nullid} {
1018 set parent_ref
"HEAD"
1020 set parent_ref
"$cmit^"
1022 if {[catch {set cparent
[git rev-parse
--verify $parent_ref]} err
]} {
1023 error_popup
[strcat
[mc
"Cannot find parent commit:"] "\n\n$err"]
1029 # Generate a diff between the commit and its parent,
1030 # and use the hunks to update the line number.
1031 # Request zero context to simplify calculations.
1032 if {$cmit eq
$nullid} {
1033 set diffcmd
[list diff-index
--unified=0 $cparent -- $new_path]
1035 set diffcmd
[list diff-tree
--unified=0 $cparent $cmit -- $new_path]
1037 if {[catch {set fd
[eval git_read
$diffcmd]} err
]} {
1038 $status stop
[mc
"Unable to display parent"]
1039 error_popup
[strcat
[mc
"Error loading diff:"] "\n\n$err"]
1043 set r_orig_line
[lindex $dat 2]
1049 fileevent $fd readable
[cb _read_diff_load_commit
\
1050 $fd $cparent $new_path $r_orig_line]
1055 method _read_diff_load_commit
{fd cparent new_path tline
} {
1056 if {$fd ne
$current_fd} {
1061 while {[gets $fd line
] >= 0} {
1062 if {[regexp {^
@@ -(\d
+)(,(\d
+))?
\+(\d
+)(,(\d
+))?
@@} $line line
\
1063 old_line osz old_size new_line nsz new_size
]} {
1065 if {$osz eq
{}} { set old_size
1 }
1066 if {$nsz eq
{}} { set new_size
1 }
1068 if {$new_line <= $tline} {
1069 if {[expr {$new_line + $new_size}] > $tline} {
1070 # Target line within the hunk
1071 set line_shift
[expr {
1072 ($new_size-$old_size)*($tline-$new_line)/$new_size
1075 set line_shift
[expr {$new_size-$old_size}]
1078 set r_orig_line
[expr {$r_orig_line - $line_shift}]
1087 _load_new_commit
$this \
1092 } ifdeleted
{ catch {close $fd} }
1094 method _show_tooltip
{cur_w pos
} {
1095 if {$tooltip_wm ne
{}} {
1096 _open_tooltip
$this $cur_w
1097 } elseif
{$tooltip_timer eq
{}} {
1098 set tooltip_timer
[after 1000 [cb _open_tooltip
$cur_w]]
1102 method _open_tooltip
{cur_w
} {
1103 set tooltip_timer
{}
1104 set pos_x
[winfo pointerx
$cur_w]
1105 set pos_y
[winfo pointery
$cur_w]
1106 if {[winfo containing
$pos_x $pos_y] ne
$cur_w} {
1111 if {$tooltip_wm ne
"$cur_w.tooltip"} {
1114 set tooltip_wm
[toplevel $cur_w.tooltip
-borderwidth 1]
1115 wm overrideredirect
$tooltip_wm 1
1116 wm transient
$tooltip_wm [winfo toplevel $cur_w]
1117 set tooltip_t
$tooltip_wm.
label
1120 -highlightthickness 0 \
1124 -background lightyellow
\
1126 $tooltip_t tag conf section_header
-font font_uibold
1129 $tooltip_t conf
-state normal
1130 $tooltip_t delete
0.0 end
1133 set pos
@[join [list \
1134 [expr {$pos_x - [winfo rootx
$cur_w]}] \
1135 [expr {$pos_y - [winfo rooty
$cur_w]}]] ,]
1136 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
1137 if {$cur_w eq
$w_amov} {
1138 set dat
[lindex $amov_data $lno]
1141 set dat
[lindex $asim_data $lno]
1142 set org
[lindex $amov_data $lno]
1150 set cmit
[lindex $dat 0]
1151 set tooltip_commit
[list $cmit]
1156 catch {set author_name
$header($cmit,author
)}
1157 catch {set summary
$header($cmit,summary
)}
1158 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1160 $tooltip_t insert end
"commit $cmit\n"
1161 $tooltip_t insert end
"$author_name $author_time\n"
1162 $tooltip_t insert end
"$summary"
1164 if {$org ne
{} && [lindex $org 0] ne
$cmit} {
1165 set save
[$tooltip_t get
0.0 end
]
1166 $tooltip_t delete
0.0 end
1168 set cmit
[lindex $org 0]
1169 set file [lindex $org 1]
1170 lappend tooltip_commit
$cmit
1175 catch {set author_name
$header($cmit,author
)}
1176 catch {set summary
$header($cmit,summary
)}
1177 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1179 $tooltip_t insert end
[strcat
[mc
"Originally By:"] "\n"] section_header
1180 $tooltip_t insert end
"commit $cmit\n"
1181 $tooltip_t insert end
"$author_name $author_time\n"
1182 $tooltip_t insert end
"$summary\n"
1184 if {$file ne
$path} {
1185 $tooltip_t insert end
[strcat
[mc
"In File:"] " "] section_header
1186 $tooltip_t insert end
"$file\n"
1189 $tooltip_t insert end
"\n"
1190 $tooltip_t insert end
[strcat
[mc
"Copied Or Moved Here By:"] "\n"] section_header
1191 $tooltip_t insert end
$save
1194 $tooltip_t conf
-state disabled
1195 _position_tooltip
$this
1198 method _position_tooltip
{} {
1199 set max_h
[lindex [split [$tooltip_t index end
] .
] 0]
1201 for {set i
1} {$i <= $max_h} {incr i
} {
1202 set c
[lindex [split [$tooltip_t index
"$i.0 lineend"] .
] 1]
1203 if {$c > $max_w} {set max_w
$c}
1205 $tooltip_t conf
-width $max_w -height $max_h
1207 set req_w
[winfo reqwidth
$tooltip_t]
1208 set req_h
[winfo reqheight
$tooltip_t]
1209 set pos_x
[expr {[winfo pointerx .
] + 5}]
1210 set pos_y
[expr {[winfo pointery .
] + 10}]
1212 set g
"${req_w}x${req_h}"
1213 if {$pos_x >= 0} {append g
+}
1215 if {$pos_y >= 0} {append g
+}
1218 wm geometry
$tooltip_wm $g
1222 method _hide_tooltip
{} {
1223 if {$tooltip_wm ne
{}} {
1226 set tooltip_commit
{}
1228 if {$tooltip_timer ne
{}} {
1229 after cancel
$tooltip_timer
1230 set tooltip_timer
{}
1234 method _resize
{new_height
} {
1235 set diff
[expr {$new_height - $old_height}]
1236 if {$diff == 0} return
1238 set my
[expr {[winfo height
$w.file_pane
] - 25}]
1239 set o
[$w.file_pane sash coord
0]
1240 set ox
[lindex $o 0]
1241 set oy
[expr {[lindex $o 1] + $diff}]
1242 if {$oy < 0} {set oy
0}
1243 if {$oy > $my} {set oy
$my}
1244 $w.file_pane sash
place 0 $ox $oy
1246 set old_height
$new_height