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 finder
; # find mini-dialog frame
25 field status
; # status mega-widget instance
26 field old_height
; # last known height of $w.file_pane
31 variable active_color
#c0edc5
32 variable group_colors
{
38 # Current blame data; cleared/reset on each load
40 field commit
; # input commit to blame
41 field path
; # input filename to view in $commit
43 field current_fd
{} ; # background process running
44 field highlight_line
-1 ; # current line selected
45 field highlight_column
{} ; # current commit column selected
46 field highlight_commit
{} ; # sha1 of commit selected
48 field total_lines
0 ; # total length of file
49 field blame_lines
0 ; # number of lines computed
50 field amov_data
; # list of {commit origfile origline}
51 field asim_data
; # list of {commit origfile origline}
53 field r_commit
; # commit currently being parsed
54 field r_orig_line
; # original line number
55 field r_final_line
; # final line number
56 field r_line_count
; # lines in this region
58 field tooltip_wm
{} ; # Current tooltip toplevel, if open
59 field tooltip_t
{} ; # Text widget in $tooltip_wm
60 field tooltip_timer
{} ; # Current timer event for our tooltip
61 field tooltip_commit
{} ; # Commit(s) in tooltip
63 constructor new
{i_commit i_path i_jump
} {
64 global cursor_ptr M1B M1T have_tk85 use_ttk NS
72 wm title
$top [append "[appname] ([reponame]): " [mc
"File Viewer"]]
74 set font_w
[font measure font_diff
"0"]
77 tlabel
$w.header.commit_l
\
78 -text [mc
"Commit:"] \
83 set w_back
$w.header.commit_b
85 -image ::blame::img_back_arrow \
91 -activebackground gold
92 bind $w_back <Button-1
> "
93 if {\[$w_back cget -state\] eq {normal}} {
97 tlabel
$w.header.commit
\
98 -textvariable @commit
\
103 tlabel
$w.header.path_l
\
109 set w_path
$w.header.path
115 pack $w.header.commit_l
-side left
116 pack $w_back -side left
117 pack $w.header.commit
-side left
118 pack $w_path -fill x
-side right
119 pack $w.header.path_l
-side right
121 panedwindow $w.file_pane
-orient vertical
-borderwidth 0 -sashwidth 3
122 frame $w.file_pane.out
-relief flat
-borderwidth 1
123 frame $w.file_pane.cm
-relief sunken
-borderwidth 1
124 $w.file_pane add
$w.file_pane.out
\
129 $w.file_pane add
$w.file_pane.cm
\
135 set w_line
$w.file_pane.out.linenumber_t
138 -highlightthickness 0 \
148 $w_line tag conf linenumber
-justify right
-rmargin 5
150 set w_amov
$w.file_pane.out.amove_t
153 -highlightthickness 0 \
163 $w_amov tag conf author_abbr
-justify right
-rmargin 5
164 $w_amov tag conf curr_commit
165 $w_amov tag conf prior_commit
-foreground blue
-underline 1
166 $w_amov tag
bind prior_commit
\
168 "[cb _load_commit $w_amov @amov_data @%x,%y];break"
170 set w_asim
$w.file_pane.out.asimple_t
173 -highlightthickness 0 \
183 $w_asim tag conf author_abbr
-justify right
184 $w_asim tag conf curr_commit
185 $w_asim tag conf prior_commit
-foreground blue
-underline 1
186 $w_asim tag
bind prior_commit
\
188 "[cb _load_commit $w_asim @asim_data @%x,%y];break"
190 set w_file
$w.file_pane.out.file_t
193 -highlightthickness 0 \
202 -xscrollcommand [list $w.file_pane.out.sbx
set] \
205 $w_file configure
-inactiveselectbackground darkblue
207 $w_file tag conf found
\
210 set w_columns
[list $w_amov $w_asim $w_line $w_file]
212 ${NS
}::scrollbar $w.file_pane.out.sbx
\
214 -command [list $w_file xview
]
215 ${NS
}::scrollbar $w.file_pane.out.sby
\
217 -command [list scrollbar2many
$w_columns yview
]
218 eval grid $w_columns $w.file_pane.out.sby
-sticky nsew
220 $w.file_pane.out.sbx
\
221 -column [expr {[llength $w_columns] - 1}] \
223 grid columnconfigure
\
225 [expr {[llength $w_columns] - 1}] \
227 grid rowconfigure
$w.file_pane.out
0 -weight 1
229 set finder
[::searchbar::new \
230 $w.file_pane.out.ff
$w_file \
231 -column [expr {[llength $w_columns] - 1}] \
234 set w_cviewer
$w.file_pane.cm.t
243 -xscrollcommand [list $w.file_pane.cm.sbx
set] \
244 -yscrollcommand [list $w.file_pane.cm.sby
set] \
246 $w_cviewer tag conf still_loading
\
247 -font font_uiitalic
\
249 $w_cviewer tag conf header_key
\
251 -background $active_color \
253 $w_cviewer tag conf header_val
\
254 -background $active_color \
256 $w_cviewer tag
raise sel
257 ${NS
}::scrollbar $w.file_pane.cm.sbx
\
259 -command [list $w_cviewer xview
]
260 ${NS
}::scrollbar $w.file_pane.cm.sby
\
262 -command [list $w_cviewer yview
]
263 pack $w.file_pane.cm.sby
-side right
-fill y
264 pack $w.file_pane.cm.sbx
-side bottom
-fill x
265 pack $w_cviewer -expand 1 -fill both
267 set status
[::status_bar::new $w.status
]
269 menu $w.ctxm
-tearoff 0
270 $w.ctxm add command
\
271 -label [mc
"Copy Commit"] \
272 -command [cb _copycommit
]
273 $w.ctxm add separator
274 $w.ctxm add command
\
275 -label [mc
"Find Text..."] \
277 -command [list searchbar
::show $finder]
279 build_encoding_menu
$w.ctxm.enc
[cb _setencoding
]
280 $w.ctxm add cascade
\
281 -label [mc
"Encoding"] \
283 $w.ctxm add command
\
284 -label [mc
"Do Full Copy Detection"] \
285 -command [cb _fullcopyblame
]
286 $w.ctxm add separator
287 $w.ctxm add command
\
288 -label [mc
"Show History Context"] \
289 -command [cb _gitkcommit
]
290 $w.ctxm add command
\
291 -label [mc
"Blame Parent Commit"] \
292 -command [cb _blameparent
]
294 foreach i
$w_columns {
295 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
296 $i tag conf color
$g -background [lindex $group_colors $g]
300 $w_file tag
raise found
304 $i conf
-cursor $cursor_ptr
305 $i conf
-yscrollcommand \
306 "[list ::searchbar::scrolled $finder]
307 [list many2scrollbar $w_columns yview $w.file_pane.out.sby]"
310 [cb _click $i @%x,%y]
313 bind $i <Any-Motion
> [cb _show_tooltip
$i @%x
,%y
]
314 bind $i <Any-Enter
> [cb _hide_tooltip
]
315 bind $i <Any-Leave
> [cb _hide_tooltip
]
321 tk_popup $w.ctxm %X %Y
323 bind $i <Shift-Tab
> "[list focus $w_cviewer];break"
324 bind $i <Tab
> "[cb _focus_search $w_cviewer];break"
327 foreach i
[concat $w_columns $w_cviewer] {
328 bind $i <Key-Up
> {catch {%W yview scroll
-1 units
};break}
329 bind $i <Key-Down
> {catch {%W yview scroll
1 units
};break}
330 bind $i <Key-Left
> {catch {%W xview scroll
-1 units
};break}
331 bind $i <Key-Right
> {catch {%W xview scroll
1 units
};break}
332 bind $i <Key-k
> {catch {%W yview scroll
-1 units
};break}
333 bind $i <Key-j
> {catch {%W yview scroll
1 units
};break}
334 bind $i <Key-h
> {catch {%W xview scroll
-1 units
};break}
335 bind $i <Key-l
> {catch {%W xview scroll
1 units
};break}
336 bind $i <Control-Key-b
> {catch {%W yview scroll
-1 pages
};break}
337 bind $i <Control-Key-f
> {catch {%W yview scroll
1 pages
};break}
340 bind $w_cviewer <Shift-Tab
> "[cb _focus_search $w_file];break"
341 bind $w_cviewer <Tab
> "[list focus $w_file];break"
342 bind $w_cviewer <Button-1
> [list focus $w_cviewer]
343 bind $w_file <Visibility
> [cb _focus_search
$w_file]
344 bind $top <F7
> [list searchbar
::show $finder]
345 bind $top <Escape
> [list searchbar
::hide $finder]
346 bind $top <F3
> [list searchbar
::find_next $finder]
347 bind $top <Shift-F3
> [list searchbar
::find_prev $finder]
348 catch { bind $top <Shift-Key-XF86_Switch_VT_3
> [list searchbar
::find_prev $finder] }
350 grid configure
$w.header
-sticky ew
351 grid configure
$w.file_pane
-sticky nsew
352 grid configure
$w.status
-sticky ew
353 grid columnconfigure
$top 0 -weight 1
354 grid rowconfigure
$top 0 -weight 0
355 grid rowconfigure
$top 1 -weight 1
356 grid rowconfigure
$top 2 -weight 0
358 set req_w
[winfo reqwidth
$top]
359 set req_h
[winfo reqheight
$top]
360 set scr_w
[expr {[winfo screenwidth
$top] - 40}]
361 set scr_h
[expr {[winfo screenheight
$top] - 120}]
362 set opt_w
[expr {$font_w * (80 + 5*3 + 3)}]
363 if {$req_w < $opt_w} {set req_w
$opt_w}
364 if {$req_w > $scr_w} {set req_w
$scr_w}
365 set opt_h
[expr {$req_w*4/3}]
366 if {$req_h < $scr_h} {set req_h
$scr_h}
367 if {$req_h > $opt_h} {set req_h
$opt_h}
368 set g
"${req_w}x${req_h}"
372 set old_height
[winfo height
$w.file_pane
]
373 $w.file_pane sash
place 0 \
374 [lindex [$w.file_pane sash coord
0] 0] \
375 [expr {int
($old_height * 0.80)}]
376 bind $w.file_pane
<Configure
> \
377 "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
379 wm protocol
$top WM_DELETE_WINDOW
"destroy $top"
380 bind $top <Destroy
> [cb _handle_destroy
%W
]
385 method _focus_search
{win
} {
386 if {[searchbar
::visible $finder]} {
387 focus [searchbar
::editor $finder]
393 method _handle_destroy
{win
} {
401 if {$current_fd ne
{}} {
402 kill_file_process
$current_fd
403 catch {close $current_fd}
408 method _load
{jump
} {
409 variable group_colors
413 if {$total_lines != 0 ||
$current_fd ne
{}} {
416 foreach i
$w_columns {
417 $i conf
-state normal
419 foreach g
[$i tag names
] {
420 if {[regexp {^g
[0-9a-f
]{40}$} $g]} {
424 $i conf
-state disabled
427 $w_cviewer conf
-state normal
428 $w_cviewer delete
0.0 end
429 $w_cviewer conf
-state disabled
431 set highlight_line
-1
432 set highlight_column
{}
433 set highlight_commit
{}
437 if {$history eq
{}} {
438 $w_back conf
-state disabled
440 $w_back conf
-state normal
443 # Index 0 is always empty. There is never line 0 as
444 # we use only 1 based lines, as that matches both with
445 # git-blame output and with Tk's text widget.
447 set amov_data
[list [list]]
448 set asim_data
[list [list]]
450 $status show
[mc
"Reading %s..." "$commit:[escape_path $path]"]
451 $w_path conf
-text [escape_path
$path]
454 if {![is_config_false gui.textconv
] && [git-version
>= 1.7.2]} {
455 set filter
[gitattr
$path diff
set]
456 set textconv
[get_config
[join [list diff
$filter textconv
] .
]]
457 if {$filter ne
{set} && $textconv ne
{}} {
462 if {$do_textconv ne
0} {
463 # Run textconv with sh -c "..." to allow it to
464 # contain command + arguments.
465 set fd
[open |
[list [shellpath
] -c "$textconv \"\$0\"" $path] r
]
467 set fd
[open $path r
]
469 fconfigure $fd -eofchar {}
471 if {$do_textconv ne
0} {
472 set fd
[git_read cat-file
--textconv "$commit:$path"]
474 set fd
[git_read cat-file blob
"$commit:$path"]
480 -encoding [get_path_encoding
$path]
481 fileevent $fd readable
[cb _read_file
$fd $jump]
485 method _history_menu
{} {
487 if {[winfo exists
$m]} {
493 for {set i
[expr {[llength $history] - 1}]
494 } {$i >= 0} {incr i
-1} {
495 set e
[lindex $history $i]
499 if {[regexp {^
[0-9a-f
]{40}$} $c]} {
500 set t
[string range
$c 0 8]...
501 } elseif
{$c eq
{}} {
502 set t
{Working Directory
}
506 if {![catch {set summary
$header($c,summary
)}]} {
508 if {[string length
$t] > 70} {
509 set t
[string range
$t 0 66]...
513 $m add command
-label $t -command [cb _goback
$i]
515 set X
[winfo rootx
$w_back]
516 set Y
[expr {[winfo rooty
$w_back] + [winfo height
$w_back]}]
521 set dat
[lindex $history $i]
522 set history [lrange $history 0 [expr {$i - 1}]]
523 set commit
[lindex $dat 0]
524 set path
[lindex $dat 1]
525 _load
$this [lrange $dat 2 5]
528 method _read_file
{fd jump
} {
529 if {$fd ne
$current_fd} {
534 foreach i
$w_columns {$i conf
-state normal
}
535 while {[gets $fd line
] >= 0} {
536 regsub "\r\$" $line {} line
541 if {$total_lines > 1} {
542 foreach i
$w_columns {$i insert end
"\n"}
545 $w_line insert end
"$total_lines" linenumber
546 $w_file insert end
"$line"
549 set ln_wc
[expr {[string length
$total_lines] + 2}]
550 if {[$w_line cget
-width] < $ln_wc} {
551 $w_line conf
-width $ln_wc
554 foreach i
$w_columns {$i conf
-state disabled
}
559 # If we don't force Tk to update the widgets *right now*
560 # none of our jump commands will cause a change in the UI.
564 if {[llength $jump] == 1} {
565 set highlight_line
[lindex $jump 0]
566 $w_file see
"$highlight_line.0"
567 } elseif
{[llength $jump] == 4} {
568 set highlight_column
[lindex $jump 0]
569 set highlight_line
[lindex $jump 1]
570 $w_file xview moveto
[lindex $jump 2]
571 $w_file yview moveto
[lindex $jump 3]
574 _exec_blame
$this $w_asim @asim_data
\
576 [mc
"Loading copy/move tracking annotations..."]
578 } ifdeleted
{ catch {close $fd} }
580 method _exec_blame
{cur_w cur_d
options cur_s
} {
581 lappend options --incremental --encoding=utf-8
583 lappend options --contents $path
585 lappend options $commit
587 lappend options -- $path
588 set fd
[eval git_read
--nice blame
$options]
589 fconfigure $fd -blocking 0 -translation lf
-encoding utf-8
590 fileevent $fd readable
[cb _read_blame
$fd $cur_w $cur_d]
596 [mc
"lines annotated"]
599 method _read_blame
{fd cur_w cur_d
} {
600 upvar #0 $cur_d line_data
601 variable group_colors
603 if {$fd ne
$current_fd} {
608 $cur_w conf
-state normal
609 while {[gets $fd line
] >= 0} {
610 if {[regexp {^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$} $line line
\
611 cmit original_line final_line line_count
]} {
613 set r_orig_line
$original_line
614 set r_final_line
$final_line
615 set r_line_count
$line_count
616 } elseif
{[string match
{filename *} $line]} {
617 set file [string range
$line 9 end
]
619 set lno
$r_final_line
623 if {[regexp {^
0{40}$} $cmit]} {
625 set commit_type curr_commit
626 } elseif
{$cmit eq
$commit} {
628 set commit_type curr_commit
630 set commit_type prior_commit
631 set commit_abbr
[string range
$cmit 0 3]
636 catch {set a_name
$header($cmit,author
)}
637 while {$a_name ne
{}} {
638 if {$author_abbr ne
{}
639 && [string index
$a_name 0] eq
{'
}} {
640 regsub {^'
[^'
]+'
\s
+} $a_name {} a_name
642 if {![regexp {^
([[:upper
:]])} $a_name _a
]} break
643 append author_abbr
$_a
646 {^
[[:upper
:]][^
\s
]*\s
+} \
647 $a_name {} a_name
]} break
649 if {$author_abbr eq
{}} {
652 set author_abbr
[string range
$author_abbr 0 3]
659 && $cmit eq
[lindex $line_data [expr {$first_lno - 1}] 0]
660 && $file eq
[lindex $line_data [expr {$first_lno - 1}] 1]
666 if {$first_lno < $lno} {
667 foreach g
[$w_file tag names
$first_lno.0] {
668 if {[regexp {^color
[0-9]+$} $g]} {
674 set i
[lsort [concat \
675 [$w_file tag names
"[expr {$first_lno - 1}].0"] \
676 [$w_file tag names
"[expr {$lno + $n}].0"] \
678 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
679 if {[lsearch -sorted -exact $i color
$g] == -1} {
690 set lno_e
"$lno.0 lineend + 1c"
691 if {[lindex $line_data $lno] ne
{}} {
692 set g
[lindex $line_data $lno 0]
693 foreach i
$w_columns {
694 $i tag remove g
$g $lno.0 $lno_e
697 lset line_data
$lno [list $cmit $file $oln]
699 $cur_w delete
$lno.0 "$lno.0 lineend"
700 if {$lno == $first_lno} {
701 $cur_w insert
$lno.0 $commit_abbr $commit_type
702 } elseif
{$lno == [expr {$first_lno + 1}]} {
703 $cur_w insert
$lno.0 $author_abbr author_abbr
705 $cur_w insert
$lno.0 { |
}
708 foreach i
$w_columns {
709 if {$cur_w eq
$w_amov} {
711 {$g < [llength $group_colors]} \
713 $i tag remove color
$g $lno.0 $lno_e
715 $i tag add
$color $lno.0 $lno_e
717 $i tag add g
$cmit $lno.0 $lno_e
720 if {$highlight_column eq
$cur_w} {
721 if {$highlight_line == -1
722 && [lindex [$w_file yview
] 0] == 0} {
724 set highlight_line
$lno
726 if {$highlight_line == $lno} {
727 _showcommit
$this $cur_w $lno
738 $cmit eq
[lindex $line_data $lno 0]
739 && $file eq
[lindex $line_data $lno 1]
741 $cur_w delete
$lno.0 "$lno.0 lineend"
743 if {$lno == $first_lno} {
744 $cur_w insert
$lno.0 $commit_abbr $commit_type
745 } elseif
{$lno == [expr {$first_lno + 1}]} {
746 $cur_w insert
$lno.0 $author_abbr author_abbr
748 $cur_w insert
$lno.0 { |
}
751 if {$cur_w eq
$w_amov} {
752 foreach i
$w_columns {
754 {$g < [llength $group_colors]} \
756 $i tag remove color
$g $lno.0 $lno_e
758 $i tag add
$color $lno.0 $lno_e
765 } elseif
{[regexp {^
([a-z-
]+) (.
*)$} $line line key data
]} {
766 set header
($r_commit,$key) $data
769 $cur_w conf
-state disabled
773 if {$cur_w eq
$w_asim} {
774 # Switches for original location detection
775 set threshold
[get_config gui.copyblamethreshold
]
776 set original_options
[list "-C$threshold"]
778 if {![is_config_true gui.fastcopyblame
]} {
779 # thorough copy search; insert before the threshold
780 set original_options
[linsert $original_options 0 -C]
782 if {[git-version
>= 1.5.3]} {
783 lappend original_options
-w ; # ignore indentation changes
786 _exec_blame
$this $w_amov @amov_data
\
788 [mc
"Loading original location annotations..."]
791 $status stop
[mc
"Annotation complete."]
794 $status update $blame_lines $total_lines
796 } ifdeleted
{ catch {close $fd} }
798 method _find_commit_bound
{data_list start_idx delta
} {
799 upvar #0 $data_list line_data
801 set limit
[expr {[llength $line_data] - 1}]
802 set base_commit
[lindex $line_data $pos 0]
804 while {$pos > 0 && $pos < $limit} {
805 set new_pos
[expr {$pos + $delta}]
806 if {[lindex $line_data $new_pos 0] ne
$base_commit} {
816 method _fullcopyblame
{} {
817 if {$current_fd ne
{}} {
822 -message [mc
"Annotation process is already running."]
827 # Switches for original location detection
828 set threshold
[get_config gui.copyblamethreshold
]
829 set original_options
[list -C -C "-C$threshold"]
831 if {[git-version
>= 1.5.3]} {
832 lappend original_options
-w ; # ignore indentation changes
835 # Find the line range
836 set pos
@$::cursorX,$::cursorY
837 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
838 set min_amov_lno
[_find_commit_bound
$this @amov_data
$lno -1]
839 set max_amov_lno
[_find_commit_bound
$this @amov_data
$lno 1]
840 set min_asim_lno
[_find_commit_bound
$this @asim_data
$lno -1]
841 set max_asim_lno
[_find_commit_bound
$this @asim_data
$lno 1]
843 if {$min_asim_lno < $min_amov_lno} {
844 set min_amov_lno
$min_asim_lno
847 if {$max_asim_lno > $max_amov_lno} {
848 set max_amov_lno
$max_asim_lno
851 lappend original_options
-L "$min_amov_lno,$max_amov_lno"
854 for {set i
$min_amov_lno} {$i <= $max_amov_lno} {incr i
} {
855 lset amov_data
$i [list ]
858 # Start the back-end process
859 _exec_blame
$this $w_amov @amov_data
\
861 [mc
"Running thorough copy detection..."]
864 method _click
{cur_w pos
} {
865 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
866 _showcommit
$this $cur_w $lno
869 method _setencoding
{enc
} {
870 force_path_encoding
$path $enc
874 [lindex [$w_file xview
] 0] \
875 [lindex [$w_file yview
] 0] \
879 method _load_commit
{cur_w cur_d pos
} {
880 upvar #0 $cur_d line_data
881 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
882 set dat
[lindex $line_data $lno]
884 _load_new_commit
$this \
887 [list [lindex $dat 2]]
891 method _load_new_commit
{new_commit new_path jump
} {
892 lappend history [list \
896 [lindex [$w_file xview
] 0] \
897 [lindex [$w_file yview
] 0] \
900 set commit
$new_commit
905 method _showcommit
{cur_w lno
} {
907 variable active_color
909 if {$highlight_commit ne
{}} {
910 foreach i
$w_columns {
911 $i tag conf g
$highlight_commit -background {}
912 $i tag
lower g
$highlight_commit
916 if {$cur_w eq
$w_asim} {
917 set dat
[lindex $asim_data $lno]
918 set highlight_column
$w_asim
920 set dat
[lindex $amov_data $lno]
921 set highlight_column
$w_amov
924 $w_cviewer conf
-state normal
925 $w_cviewer delete
0.0 end
929 $w_cviewer insert end
[mc
"Loading annotation..."] still_loading
931 set cmit
[lindex $dat 0]
932 set file [lindex $dat 1]
934 foreach i
$w_columns {
935 $i tag conf g
$cmit -background $active_color
938 $w_file tag
raise found
946 catch {set author_name
$header($cmit,author
)}
947 catch {set author_email
$header($cmit,author-mail
)}
948 catch {set author_time
[format_date
$header($cmit,author-time
)]}
950 set committer_name
{}
951 set committer_email
{}
952 set committer_time
{}
953 catch {set committer_name
$header($cmit,committer
)}
954 catch {set committer_email
$header($cmit,committer-mail
)}
955 catch {set committer_time
[format_date
$header($cmit,committer-time
)]}
957 if {[catch {set msg
$header($cmit,message)}]} {
960 set fd
[git_read cat-file commit
$cmit]
961 fconfigure $fd -encoding binary -translation lf
962 # By default commits are assumed to be in utf-8
964 while {[gets $fd line
] > 0} {
965 if {[string match
{encoding *} $line]} {
966 set enc
[string tolower
[string range
$line 9 end
]]
972 set enc
[tcl_encoding
$enc]
974 set msg
[encoding convertfrom
$enc $msg]
976 set msg
[string trim
$msg]
978 set header
($cmit,message) $msg
981 $w_cviewer insert end
"commit $cmit\n" header_key
982 $w_cviewer insert end
[strcat
[mc
"Author:"] "\t"] header_key
983 $w_cviewer insert end
"$author_name $author_email" header_val
984 $w_cviewer insert end
" $author_time\n" header_val
986 $w_cviewer insert end
[strcat
[mc
"Committer:"] "\t"] header_key
987 $w_cviewer insert end
"$committer_name $committer_email" header_val
988 $w_cviewer insert end
" $committer_time\n" header_val
990 if {$file ne
$path} {
991 $w_cviewer insert end
[strcat
[mc
"Original File:"] "\t"] header_key
992 $w_cviewer insert end
"[escape_path $file]\n" header_val
995 $w_cviewer insert end
"\n$msg"
997 $w_cviewer conf
-state disabled
999 set highlight_line
$lno
1000 set highlight_commit
$cmit
1002 if {[lsearch -exact $tooltip_commit $highlight_commit] != -1} {
1007 method _get_click_amov_info
{} {
1008 set pos
@$::cursorX,$::cursorY
1009 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
1010 return [lindex $amov_data $lno]
1013 method _copycommit
{} {
1014 set dat
[_get_click_amov_info
$this]
1024 method _format_offset_date
{base offset
} {
1025 set exval
[expr {$base + $offset*24*60*60}]
1026 return [clock format $exval -format {%Y-
%m-
%d
}]
1029 method _gitkcommit
{} {
1032 set dat
[_get_click_amov_info
$this]
1034 set cmit
[lindex $dat 0]
1036 # If the line belongs to the working copy, use HEAD instead
1037 if {$cmit eq
$nullid} {
1038 if {[catch {set cmit
[git rev-parse
--verify HEAD
]} err
]} {
1039 error_popup
[strcat
[mc
"Cannot find HEAD commit:"] "\n\n$err"]
1044 set radius
[get_config gui.blamehistoryctx
]
1045 set cmdline
[list --select-commit
=$cmit]
1049 set committer_time
{}
1051 catch {set author_time
$header($cmit,author-time
)}
1052 catch {set committer_time
$header($cmit,committer-time
)}
1054 if {$committer_time eq
{}} {
1055 set committer_time
$author_time
1058 set after_time
[_format_offset_date
$this $committer_time [expr {-$radius}]]
1059 set before_time
[_format_offset_date
$this $committer_time $radius]
1061 lappend cmdline
--after=$after_time --before=$before_time
1064 lappend cmdline
$cmit
1067 if {$commit ne
{}} {
1068 set base_rev
$commit
1071 if {$base_rev ne
$cmit} {
1072 lappend cmdline
$base_rev
1079 method _blameparent
{} {
1082 set dat
[_get_click_amov_info
$this]
1084 set cmit
[lindex $dat 0]
1085 set new_path
[lindex $dat 1]
1087 # Allow using Blame Parent on lines modified in the working copy
1088 if {$cmit eq
$nullid} {
1089 set parent_ref
"HEAD"
1091 set parent_ref
"$cmit^"
1093 if {[catch {set cparent
[git rev-parse
--verify $parent_ref]} err
]} {
1094 error_popup
[strcat
[mc
"Cannot find parent commit:"] "\n\n$err"]
1100 # Generate a diff between the commit and its parent,
1101 # and use the hunks to update the line number.
1102 # Request zero context to simplify calculations.
1103 if {$cmit eq
$nullid} {
1104 set diffcmd
[list diff-index
--unified=0 $cparent -- $new_path]
1106 set diffcmd
[list diff-tree
--unified=0 $cparent $cmit -- $new_path]
1108 if {[catch {set fd
[eval git_read
$diffcmd]} err
]} {
1109 $status stop
[mc
"Unable to display parent"]
1110 error_popup
[strcat
[mc
"Error loading diff:"] "\n\n$err"]
1114 set r_orig_line
[lindex $dat 2]
1120 fileevent $fd readable
[cb _read_diff_load_commit
\
1121 $fd $cparent $new_path $r_orig_line]
1126 method _read_diff_load_commit
{fd cparent new_path tline
} {
1127 if {$fd ne
$current_fd} {
1132 while {[gets $fd line
] >= 0} {
1133 if {[regexp {^
@@ -(\d
+)(,(\d
+))?
\+(\d
+)(,(\d
+))?
@@} $line line
\
1134 old_line osz old_size new_line nsz new_size
]} {
1136 if {$osz eq
{}} { set old_size
1 }
1137 if {$nsz eq
{}} { set new_size
1 }
1139 if {$new_line <= $tline} {
1140 if {[expr {$new_line + $new_size}] > $tline} {
1141 # Target line within the hunk
1142 set line_shift
[expr {
1143 ($new_size-$old_size)*($tline-$new_line)/$new_size
1146 set line_shift
[expr {$new_size-$old_size}]
1149 set r_orig_line
[expr {$r_orig_line - $line_shift}]
1158 _load_new_commit
$this \
1163 } ifdeleted
{ catch {close $fd} }
1165 method _show_tooltip
{cur_w pos
} {
1166 if {$tooltip_wm ne
{}} {
1167 _open_tooltip
$this $cur_w
1168 } elseif
{$tooltip_timer eq
{}} {
1169 set tooltip_timer
[after 1000 [cb _open_tooltip
$cur_w]]
1173 method _open_tooltip
{cur_w
} {
1174 set tooltip_timer
{}
1175 set pos_x
[winfo pointerx
$cur_w]
1176 set pos_y
[winfo pointery
$cur_w]
1177 if {[winfo containing
$pos_x $pos_y] ne
$cur_w} {
1182 if {$tooltip_wm ne
"$cur_w.tooltip"} {
1185 set tooltip_wm
[toplevel $cur_w.tooltip
-borderwidth 1]
1186 wm overrideredirect
$tooltip_wm 1
1187 wm transient
$tooltip_wm [winfo toplevel $cur_w]
1188 set tooltip_t
$tooltip_wm.
label
1191 -highlightthickness 0 \
1195 -background lightyellow
\
1197 $tooltip_t tag conf section_header
-font font_uibold
1200 $tooltip_t conf
-state normal
1201 $tooltip_t delete
0.0 end
1204 set pos
@[join [list \
1205 [expr {$pos_x - [winfo rootx
$cur_w]}] \
1206 [expr {$pos_y - [winfo rooty
$cur_w]}]] ,]
1207 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
1208 if {$cur_w eq
$w_amov} {
1209 set dat
[lindex $amov_data $lno]
1212 set dat
[lindex $asim_data $lno]
1213 set org
[lindex $amov_data $lno]
1221 set cmit
[lindex $dat 0]
1222 set tooltip_commit
[list $cmit]
1227 catch {set author_name
$header($cmit,author
)}
1228 catch {set summary
$header($cmit,summary
)}
1229 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1231 $tooltip_t insert end
"commit $cmit\n"
1232 $tooltip_t insert end
"$author_name $author_time\n"
1233 $tooltip_t insert end
"$summary"
1235 if {$org ne
{} && [lindex $org 0] ne
$cmit} {
1236 set save
[$tooltip_t get
0.0 end
]
1237 $tooltip_t delete
0.0 end
1239 set cmit
[lindex $org 0]
1240 set file [lindex $org 1]
1241 lappend tooltip_commit
$cmit
1246 catch {set author_name
$header($cmit,author
)}
1247 catch {set summary
$header($cmit,summary
)}
1248 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1250 $tooltip_t insert end
[strcat
[mc
"Originally By:"] "\n"] section_header
1251 $tooltip_t insert end
"commit $cmit\n"
1252 $tooltip_t insert end
"$author_name $author_time\n"
1253 $tooltip_t insert end
"$summary\n"
1255 if {$file ne
$path} {
1256 $tooltip_t insert end
[strcat
[mc
"In File:"] " "] section_header
1257 $tooltip_t insert end
"$file\n"
1260 $tooltip_t insert end
"\n"
1261 $tooltip_t insert end
[strcat
[mc
"Copied Or Moved Here By:"] "\n"] section_header
1262 $tooltip_t insert end
$save
1265 $tooltip_t conf
-state disabled
1266 _position_tooltip
$this
1268 # On MacOS raising a window causes it to acquire focus.
1269 # Tk 8.5 on MacOS seems to properly support wm transient,
1270 # so we can safely counter the effect there.
1271 if {$::have_tk85 && [is_MacOSX
]} {
1281 method _position_tooltip
{} {
1282 set max_h
[lindex [split [$tooltip_t index end
] .
] 0]
1284 for {set i
1} {$i <= $max_h} {incr i
} {
1285 set c
[lindex [split [$tooltip_t index
"$i.0 lineend"] .
] 1]
1286 if {$c > $max_w} {set max_w
$c}
1288 $tooltip_t conf
-width $max_w -height $max_h
1290 set req_w
[winfo reqwidth
$tooltip_t]
1291 set req_h
[winfo reqheight
$tooltip_t]
1292 set pos_x
[expr {[winfo pointerx .
] + 5}]
1293 set pos_y
[expr {[winfo pointery .
] + 10}]
1295 set g
"${req_w}x${req_h}"
1296 if {$pos_x >= 0} {append g
+}
1298 if {$pos_y >= 0} {append g
+}
1301 wm geometry
$tooltip_wm $g
1307 method _hide_tooltip
{} {
1308 if {$tooltip_wm ne
{}} {
1311 set tooltip_commit
{}
1313 if {$tooltip_timer ne
{}} {
1314 after cancel
$tooltip_timer
1315 set tooltip_timer
{}
1319 method _resize
{new_height
} {
1320 set diff
[expr {$new_height - $old_height}]
1321 if {$diff == 0} return
1323 set my
[expr {[winfo height
$w.file_pane
] - 25}]
1324 set o
[$w.file_pane sash coord
0]
1325 set ox
[lindex $o 0]
1326 set oy
[expr {[lindex $o 1] + $diff}]
1327 if {$oy < 0} {set oy
0}
1328 if {$oy > $my} {set oy
$my}
1329 $w.file_pane sash
place 0 $ox $oy
1331 set old_height
$new_height