2 # Copyright (C) 2006, 2007 Shawn Pearce
6 image create
photo ::blame::img_back_arrow -data {R0lGODlhGAAYAIUAAPwCBEzKXFTSZIz
+nGzmhGzqfGTidIT
+nEzGXHTqhGzmfGzifFzadETCVES
+VARWDFzWbHzyjAReDGTadFTOZDSyRDyyTCymPARaFGTedFzSbDy2TCyqRCyqPARaDAyCHES6VDy6VCyiPAR6HCSeNByWLARyFARiDARqFGTifARiFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAYABgAAAajQIBwSCwaj8ikcsk0BppJwRPqHEypQwHBis0WDAdEFyBIKBaMAKLBdjQeSkFBYTBAIvgEoS6JmhUTEwIUDQ4VFhcMGEhyCgoZExoUaxsWHB0THkgfAXUGAhoBDSAVFR0XBnCbDRmgog0hpSIiDJpJIyEQhBUcJCIlwA22SSYVogknEg8eD82qSigdDSknY0IqJQXPYxIl1dZCGNvWw
+Dm510GQQAh
/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7
}
8 # Persistent 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 gotoline
; # line goto mini-dialog frame
26 field status
; # status mega-widget instance
27 field old_height
; # last known height of $w.file_pane
32 variable active_color
#c0edc5
33 variable group_colors
{
39 # Current blame data; cleared/reset on each load
41 field commit
; # input commit to blame
42 field path
; # input filename to view in $commit
44 field current_fd
{} ; # background process running
45 field highlight_line
-1 ; # current line selected
46 field highlight_column
{} ; # current commit column selected
47 field highlight_commit
{} ; # sha1 of commit selected
49 field total_lines
0 ; # total length of file
50 field blame_lines
0 ; # number of lines computed
51 field amov_data
; # list of {commit origfile origline}
52 field asim_data
; # list of {commit origfile origline}
54 field r_commit
; # commit currently being parsed
55 field r_orig_line
; # original line number
56 field r_final_line
; # final line number
57 field r_line_count
; # lines in this region
59 field tooltip_wm
{} ; # Current tooltip toplevel, if open
60 field tooltip_t
{} ; # Text widget in $tooltip_wm
61 field tooltip_timer
{} ; # Current timer event for our tooltip
62 field tooltip_commit
{} ; # Commit(s) in tooltip
64 constructor new
{i_commit i_path i_jump
} {
65 global cursor_ptr M1B M1T have_tk85 use_ttk NS
73 wm title
$top [append "[appname] ([reponame]): " [mc
"File Viewer"]]
75 set font_w
[font measure font_diff
"0"]
78 tlabel
$w.header.commit_l
\
79 -text [mc
"Commit:"] \
84 set w_back
$w.header.commit_b
86 -image ::blame::img_back_arrow \
92 -activebackground gold
93 bind $w_back <Button-1
> "
94 if {\[$w_back cget -state\] eq {normal}} {
98 tlabel
$w.header.commit
\
99 -textvariable @commit
\
104 tlabel
$w.header.path_l
\
110 set w_path
$w.header.path
116 pack $w.header.commit_l
-side left
117 pack $w_back -side left
118 pack $w.header.commit
-side left
119 pack $w_path -fill x
-side right
120 pack $w.header.path_l
-side right
122 panedwindow $w.file_pane
-orient vertical
-borderwidth 0 -sashwidth 3
123 frame $w.file_pane.out
-relief flat
-borderwidth 1
124 frame $w.file_pane.cm
-relief sunken
-borderwidth 1
125 $w.file_pane add
$w.file_pane.out
\
130 $w.file_pane add
$w.file_pane.cm
\
136 set w_line
$w.file_pane.out.linenumber_t
139 -highlightthickness 0 \
149 $w_line tag conf linenumber
-justify right
-rmargin 5
151 set w_amov
$w.file_pane.out.amove_t
154 -highlightthickness 0 \
164 $w_amov tag conf author_abbr
-justify right
-rmargin 5
165 $w_amov tag conf curr_commit
166 $w_amov tag conf prior_commit
-foreground blue
-underline 1
167 $w_amov tag
bind prior_commit
\
169 "[cb _load_commit $w_amov @amov_data @%x,%y];break"
171 set w_asim
$w.file_pane.out.asimple_t
174 -highlightthickness 0 \
184 $w_asim tag conf author_abbr
-justify right
185 $w_asim tag conf curr_commit
186 $w_asim tag conf prior_commit
-foreground blue
-underline 1
187 $w_asim tag
bind prior_commit
\
189 "[cb _load_commit $w_asim @asim_data @%x,%y];break"
191 set w_file
$w.file_pane.out.file_t
194 -highlightthickness 0 \
203 -xscrollcommand [list $w.file_pane.out.sbx
set] \
206 $w_file configure
-inactiveselectbackground darkblue
208 $w_file tag conf found
\
211 set w_columns
[list $w_amov $w_asim $w_line $w_file]
213 ${NS
}::scrollbar $w.file_pane.out.sbx
\
215 -command [list $w_file xview
]
216 ${NS
}::scrollbar $w.file_pane.out.sby
\
218 -command [list scrollbar2many
$w_columns yview
]
219 eval grid $w_columns $w.file_pane.out.sby
-sticky nsew
221 $w.file_pane.out.sbx
\
223 -columnspan [expr {[llength $w_columns] + 1}] \
225 grid columnconfigure
\
227 [expr {[llength $w_columns] - 1}] \
229 grid rowconfigure
$w.file_pane.out
0 -weight 1
231 set finder
[::searchbar::new \
232 $w.file_pane.out.ff
$w_file \
234 -columnspan [expr {[llength $w_columns] + 1}] \
237 set gotoline
[::linebar::new \
238 $w.file_pane.out.lf
$w_file \
240 -columnspan [expr {[llength $w_columns] + 1}] \
243 set w_cviewer
$w.file_pane.cm.t
252 -xscrollcommand [list $w.file_pane.cm.sbx
set] \
253 -yscrollcommand [list $w.file_pane.cm.sby
set] \
255 $w_cviewer tag conf still_loading
\
256 -font font_uiitalic
\
258 $w_cviewer tag conf header_key
\
260 -background $active_color \
262 $w_cviewer tag conf header_val
\
263 -background $active_color \
265 $w_cviewer tag
raise sel
266 ${NS
}::scrollbar $w.file_pane.cm.sbx
\
268 -command [list $w_cviewer xview
]
269 ${NS
}::scrollbar $w.file_pane.cm.sby
\
271 -command [list $w_cviewer yview
]
272 pack $w.file_pane.cm.sby
-side right
-fill y
273 pack $w.file_pane.cm.sbx
-side bottom
-fill x
274 pack $w_cviewer -expand 1 -fill both
276 set status
[::status_bar::new $w.status
]
278 menu $w.ctxm
-tearoff 0
279 $w.ctxm add command
\
280 -label [mc
"Copy Commit"] \
281 -command [cb _copycommit
]
282 $w.ctxm add separator
283 $w.ctxm add command
\
284 -label [mc
"Find Text..."] \
286 -command [cb _show_finder
]
287 $w.ctxm add command
\
288 -label [mc
"Goto Line..."] \
289 -accelerator "Ctrl-G" \
290 -command [cb _show_linebar
]
292 build_encoding_menu
$w.ctxm.enc
[cb _setencoding
]
293 $w.ctxm add cascade
\
294 -label [mc
"Encoding"] \
296 $w.ctxm add command
\
297 -label [mc
"Do Full Copy Detection"] \
298 -command [cb _fullcopyblame
]
299 $w.ctxm add separator
300 $w.ctxm add command
\
301 -label [mc
"Show History Context"] \
302 -command [cb _gitkcommit
]
303 $w.ctxm add command
\
304 -label [mc
"Blame Parent Commit"] \
305 -command [cb _blameparent
]
307 foreach i
$w_columns {
308 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
309 $i tag conf color
$g -background [lindex $group_colors $g]
313 $w_file tag
raise found
317 $i conf
-cursor $cursor_ptr
318 $i conf
-yscrollcommand \
319 "[list ::searchbar::scrolled $finder]
320 [list many2scrollbar $w_columns yview $w.file_pane.out.sby]"
323 [cb _click $i @%x,%y]
326 bind $i <Any-Motion
> [cb _show_tooltip
$i @%x
,%y
]
327 bind $i <Any-Enter
> [cb _hide_tooltip
]
328 bind $i <Any-Leave
> [cb _hide_tooltip
]
334 tk_popup $w.ctxm %X %Y
336 bind $i <Shift-Tab
> "[list focus $w_cviewer];break"
337 bind $i <Tab
> "[cb _focus_search $w_cviewer];break"
340 foreach i
[concat $w_columns $w_cviewer] {
341 bind $i <Key-Up
> {catch {%W yview scroll
-1 units
};break}
342 bind $i <Key-Down
> {catch {%W yview scroll
1 units
};break}
343 bind $i <Key-Left
> {catch {%W xview scroll
-1 units
};break}
344 bind $i <Key-Right
> {catch {%W xview scroll
1 units
};break}
345 bind $i <Key-k
> {catch {%W yview scroll
-1 units
};break}
346 bind $i <Key-j
> {catch {%W yview scroll
1 units
};break}
347 bind $i <Key-h
> {catch {%W xview scroll
-1 units
};break}
348 bind $i <Key-l
> {catch {%W xview scroll
1 units
};break}
349 bind $i <Control-Key-b
> {catch {%W yview scroll
-1 pages
};break}
350 bind $i <Control-Key-f
> {catch {%W yview scroll
1 pages
};break}
353 bind $w_cviewer <Shift-Tab
> "[cb _focus_search $w_file];break"
354 bind $w_cviewer <Tab
> "[list focus $w_file];break"
355 bind $w_cviewer <Button-1
> [list focus $w_cviewer]
356 bind $w_file <Visibility
> [cb _focus_search
$w_file]
357 bind $top <F7
> [cb _show_finder
]
358 bind $top <Key-slash
> [cb _show_finder
]
359 bind $top <Control-Key-s
> [cb _show_finder
]
360 bind $top <Escape
> [list searchbar
::hide $finder]
361 bind $top <F3
> [list searchbar
::find_next $finder]
362 bind $top <Shift-F3
> [list searchbar
::find_prev $finder]
363 bind $top <Control-Key-g
> [cb _show_linebar
]
364 catch { bind $top <Shift-Key-XF86_Switch_VT_3
> [list searchbar
::find_prev $finder] }
366 grid configure
$w.header
-sticky ew
367 grid configure
$w.file_pane
-sticky nsew
368 grid configure
$w.status
-sticky ew
369 grid columnconfigure
$top 0 -weight 1
370 grid rowconfigure
$top 0 -weight 0
371 grid rowconfigure
$top 1 -weight 1
372 grid rowconfigure
$top 2 -weight 0
374 set req_w
[winfo reqwidth
$top]
375 set req_h
[winfo reqheight
$top]
376 set scr_w
[expr {[winfo screenwidth
$top] - 40}]
377 set scr_h
[expr {[winfo screenheight
$top] - 120}]
378 set opt_w
[expr {$font_w * (80 + 5*3 + 3)}]
379 if {$req_w < $opt_w} {set req_w
$opt_w}
380 if {$req_w > $scr_w} {set req_w
$scr_w}
381 set opt_h
[expr {$req_w*4/3}]
382 if {$req_h < $scr_h} {set req_h
$scr_h}
383 if {$req_h > $opt_h} {set req_h
$opt_h}
384 set g
"${req_w}x${req_h}"
388 set old_height
[winfo height
$w.file_pane
]
389 $w.file_pane sash
place 0 \
390 [lindex [$w.file_pane sash coord
0] 0] \
391 [expr {int
($old_height * 0.80)}]
392 bind $w.file_pane
<Configure
> \
393 "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
395 wm protocol
$top WM_DELETE_WINDOW
"destroy $top"
396 bind $top <Destroy
> [cb _handle_destroy
%W
]
401 method _focus_search
{win
} {
402 if {[searchbar
::visible $finder]} {
403 focus [searchbar
::editor $finder]
409 method _handle_destroy
{win
} {
417 if {$current_fd ne
{}} {
418 kill_file_process
$current_fd
419 catch {close $current_fd}
424 method _load
{jump
} {
425 variable group_colors
429 if {$total_lines != 0 ||
$current_fd ne
{}} {
432 foreach i
$w_columns {
433 $i conf
-state normal
435 foreach g
[$i tag names
] {
436 if {[regexp {^g
[0-9a-f
]{40}$} $g]} {
440 $i conf
-state disabled
443 $w_cviewer conf
-state normal
444 $w_cviewer delete
0.0 end
445 $w_cviewer conf
-state disabled
447 set highlight_line
-1
448 set highlight_column
{}
449 set highlight_commit
{}
453 if {$history eq
{}} {
454 $w_back conf
-state disabled
456 $w_back conf
-state normal
459 # Index 0 is always empty. There is never line 0 as
460 # we use only 1 based lines, as that matches both with
461 # git-blame output and with Tk's text widget.
463 set amov_data
[list [list]]
464 set asim_data
[list [list]]
466 $status show
[mc
"Reading %s..." "$commit:[escape_path $path]"]
467 $w_path conf
-text [escape_path
$path]
470 if {![is_config_false gui.textconv
] && [git-version
>= 1.7.2]} {
471 set filter
[gitattr
$path diff
set]
472 set textconv
[get_config
[join [list diff
$filter textconv
] .
]]
473 if {$filter ne
{set} && $textconv ne
{}} {
478 if {$do_textconv ne
0} {
479 set fd
[open_cmd_pipe
$textconv $path]
481 set fd
[open $path r
]
483 fconfigure $fd -eofchar {}
485 if {$do_textconv ne
0} {
486 set fd
[git_read cat-file
--textconv "$commit:$path"]
488 set fd
[git_read cat-file blob
"$commit:$path"]
494 -encoding [get_path_encoding
$path]
495 fileevent $fd readable
[cb _read_file
$fd $jump]
499 method _history_menu
{} {
501 if {[winfo exists
$m]} {
507 for {set i
[expr {[llength $history] - 1}]
508 } {$i >= 0} {incr i
-1} {
509 set e
[lindex $history $i]
513 if {[regexp {^
[0-9a-f
]{40}$} $c]} {
514 set t
[string range
$c 0 8]...
515 } elseif
{$c eq
{}} {
516 set t
{Working Directory
}
520 if {![catch {set summary
$header($c,summary
)}]} {
522 if {[string length
$t] > 70} {
523 set t
[string range
$t 0 66]...
527 $m add command
-label $t -command [cb _goback
$i]
529 set X
[winfo rootx
$w_back]
530 set Y
[expr {[winfo rooty
$w_back] + [winfo height
$w_back]}]
535 set dat
[lindex $history $i]
536 set history [lrange $history 0 [expr {$i - 1}]]
537 set commit
[lindex $dat 0]
538 set path
[lindex $dat 1]
539 _load
$this [lrange $dat 2 5]
542 method _read_file
{fd jump
} {
543 if {$fd ne
$current_fd} {
548 foreach i
$w_columns {$i conf
-state normal
}
549 while {[gets $fd line
] >= 0} {
550 regsub "\r\$" $line {} line
555 if {$total_lines > 1} {
556 foreach i
$w_columns {$i insert end
"\n"}
559 $w_line insert end
"$total_lines" linenumber
560 $w_file insert end
"$line"
563 set ln_wc
[expr {[string length
$total_lines] + 2}]
564 if {[$w_line cget
-width] < $ln_wc} {
565 $w_line conf
-width $ln_wc
568 foreach i
$w_columns {$i conf
-state disabled
}
571 fconfigure $fd -blocking 1; # enable error reporting on close
572 if {[catch {close $fd} err
]} {
573 tk_messageBox -icon error -title [mc Error
] \
577 # If we don't force Tk to update the widgets *right now*
578 # none of our jump commands will cause a change in the UI.
582 if {[llength $jump] == 1} {
583 set highlight_line
[lindex $jump 0]
584 $w_file see
"$highlight_line.0"
585 } elseif
{[llength $jump] == 4} {
586 set highlight_column
[lindex $jump 0]
587 set highlight_line
[lindex $jump 1]
588 $w_file xview moveto
[lindex $jump 2]
589 $w_file yview moveto
[lindex $jump 3]
592 _exec_blame
$this $w_asim @asim_data
\
594 [mc
"Loading copy/move tracking annotations..."]
596 } ifdeleted
{ catch {close $fd} }
598 method _exec_blame
{cur_w cur_d
options cur_s
} {
599 lappend options --incremental --encoding=utf-8
601 lappend options --contents $path
603 lappend options $commit
605 lappend options -- $path
606 set fd
[eval git_read
--nice blame
$options]
607 fconfigure $fd -blocking 0 -translation lf
-encoding utf-8
608 fileevent $fd readable
[cb _read_blame
$fd $cur_w $cur_d]
614 [mc
"lines annotated"]
617 method _read_blame
{fd cur_w cur_d
} {
618 upvar #0 $cur_d line_data
619 variable group_colors
621 if {$fd ne
$current_fd} {
626 $cur_w conf
-state normal
627 while {[gets $fd line
] >= 0} {
628 if {[regexp {^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$} $line line
\
629 cmit original_line final_line line_count
]} {
631 set r_orig_line
$original_line
632 set r_final_line
$final_line
633 set r_line_count
$line_count
634 } elseif
{[string match
{filename *} $line]} {
635 set file [string range
$line 9 end
]
637 set lno
$r_final_line
641 if {[regexp {^
0{40}$} $cmit]} {
643 set commit_type curr_commit
644 } elseif
{$cmit eq
$commit} {
646 set commit_type curr_commit
648 set commit_type prior_commit
649 set commit_abbr
[string range
$cmit 0 3]
654 catch {set a_name
$header($cmit,author
)}
655 while {$a_name ne
{}} {
656 if {$author_abbr ne
{}
657 && [string index
$a_name 0] eq
{'
}} {
658 regsub {^'
[^'
]+'
\s
+} $a_name {} a_name
660 if {![regexp {^
([[:upper
:]])} $a_name _a
]} break
661 append author_abbr
$_a
664 {^
[[:upper
:]][^
\s
]*\s
+} \
665 $a_name {} a_name
]} break
667 if {$author_abbr eq
{}} {
670 set author_abbr
[string range
$author_abbr 0 3]
677 && $cmit eq
[lindex $line_data [expr {$first_lno - 1}] 0]
678 && $file eq
[lindex $line_data [expr {$first_lno - 1}] 1]
684 if {$first_lno < $lno} {
685 foreach g
[$w_file tag names
$first_lno.0] {
686 if {[regexp {^color
[0-9]+$} $g]} {
692 set i
[lsort [concat \
693 [$w_file tag names
"[expr {$first_lno - 1}].0"] \
694 [$w_file tag names
"[expr {$lno + $n}].0"] \
696 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
697 if {[lsearch -sorted -exact $i color
$g] == -1} {
708 set lno_e
"$lno.0 lineend + 1c"
709 if {[lindex $line_data $lno] ne
{}} {
710 set g
[lindex $line_data $lno 0]
711 foreach i
$w_columns {
712 $i tag remove g
$g $lno.0 $lno_e
715 lset line_data
$lno [list $cmit $file $oln]
717 $cur_w delete
$lno.0 "$lno.0 lineend"
718 if {$lno == $first_lno} {
719 $cur_w insert
$lno.0 $commit_abbr $commit_type
720 } elseif
{$lno == [expr {$first_lno + 1}]} {
721 $cur_w insert
$lno.0 $author_abbr author_abbr
723 $cur_w insert
$lno.0 { |
}
726 foreach i
$w_columns {
727 if {$cur_w eq
$w_amov} {
729 {$g < [llength $group_colors]} \
731 $i tag remove color
$g $lno.0 $lno_e
733 $i tag add
$color $lno.0 $lno_e
735 $i tag add g
$cmit $lno.0 $lno_e
738 if {$highlight_column eq
$cur_w} {
739 if {$highlight_line == -1
740 && [lindex [$w_file yview
] 0] == 0} {
742 set highlight_line
$lno
744 if {$highlight_line == $lno} {
745 _showcommit
$this $cur_w $lno
756 $cmit eq
[lindex $line_data $lno 0]
757 && $file eq
[lindex $line_data $lno 1]
759 $cur_w delete
$lno.0 "$lno.0 lineend"
761 if {$lno == $first_lno} {
762 $cur_w insert
$lno.0 $commit_abbr $commit_type
763 } elseif
{$lno == [expr {$first_lno + 1}]} {
764 $cur_w insert
$lno.0 $author_abbr author_abbr
766 $cur_w insert
$lno.0 { |
}
769 if {$cur_w eq
$w_amov} {
770 foreach i
$w_columns {
772 {$g < [llength $group_colors]} \
774 $i tag remove color
$g $lno.0 $lno_e
776 $i tag add
$color $lno.0 $lno_e
783 } elseif
{[regexp {^
([a-z-
]+) (.
*)$} $line line key data
]} {
784 set header
($r_commit,$key) $data
787 $cur_w conf
-state disabled
791 if {$cur_w eq
$w_asim} {
792 # Switches for original location detection
793 set threshold
[get_config gui.copyblamethreshold
]
794 set original_options
[list "-C$threshold"]
796 if {![is_config_true gui.fastcopyblame
]} {
797 # thorough copy search; insert before the threshold
798 set original_options
[linsert $original_options 0 -C]
800 if {[git-version
>= 1.5.3]} {
801 lappend original_options
-w ; # ignore indentation changes
804 _exec_blame
$this $w_amov @amov_data
\
806 [mc
"Loading original location annotations..."]
809 $status stop
[mc
"Annotation complete."]
812 $status update $blame_lines $total_lines
814 } ifdeleted
{ catch {close $fd} }
816 method _find_commit_bound
{data_list start_idx delta
} {
817 upvar #0 $data_list line_data
819 set limit
[expr {[llength $line_data] - 1}]
820 set base_commit
[lindex $line_data $pos 0]
822 while {$pos > 0 && $pos < $limit} {
823 set new_pos
[expr {$pos + $delta}]
824 if {[lindex $line_data $new_pos 0] ne
$base_commit} {
834 method _fullcopyblame
{} {
835 if {$current_fd ne
{}} {
840 -message [mc
"Annotation process is already running."]
845 # Switches for original location detection
846 set threshold
[get_config gui.copyblamethreshold
]
847 set original_options
[list -C -C "-C$threshold"]
849 if {[git-version
>= 1.5.3]} {
850 lappend original_options
-w ; # ignore indentation changes
853 # Find the line range
854 set pos
@$::cursorX,$::cursorY
855 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
856 set min_amov_lno
[_find_commit_bound
$this @amov_data
$lno -1]
857 set max_amov_lno
[_find_commit_bound
$this @amov_data
$lno 1]
858 set min_asim_lno
[_find_commit_bound
$this @asim_data
$lno -1]
859 set max_asim_lno
[_find_commit_bound
$this @asim_data
$lno 1]
861 if {$min_asim_lno < $min_amov_lno} {
862 set min_amov_lno
$min_asim_lno
865 if {$max_asim_lno > $max_amov_lno} {
866 set max_amov_lno
$max_asim_lno
869 lappend original_options
-L "$min_amov_lno,$max_amov_lno"
872 for {set i
$min_amov_lno} {$i <= $max_amov_lno} {incr i
} {
873 lset amov_data
$i [list ]
876 # Start the back-end process
877 _exec_blame
$this $w_amov @amov_data
\
879 [mc
"Running thorough copy detection..."]
882 method _click
{cur_w pos
} {
883 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
884 _showcommit
$this $cur_w $lno
887 method _setencoding
{enc
} {
888 force_path_encoding
$path $enc
892 [lindex [$w_file xview
] 0] \
893 [lindex [$w_file yview
] 0] \
897 method _load_commit
{cur_w cur_d pos
} {
898 upvar #0 $cur_d line_data
899 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
900 set dat
[lindex $line_data $lno]
902 _load_new_commit
$this \
905 [list [lindex $dat 2]]
909 method _load_new_commit
{new_commit new_path jump
} {
910 lappend history [list \
914 [lindex [$w_file xview
] 0] \
915 [lindex [$w_file yview
] 0] \
918 set commit
$new_commit
923 method _showcommit
{cur_w lno
} {
925 variable active_color
927 if {$highlight_commit ne
{}} {
928 foreach i
$w_columns {
929 $i tag conf g
$highlight_commit -background {}
930 $i tag
lower g
$highlight_commit
934 if {$cur_w eq
$w_asim} {
935 set dat
[lindex $asim_data $lno]
936 set highlight_column
$w_asim
938 set dat
[lindex $amov_data $lno]
939 set highlight_column
$w_amov
942 $w_cviewer conf
-state normal
943 $w_cviewer delete
0.0 end
947 $w_cviewer insert end
[mc
"Loading annotation..."] still_loading
949 set cmit
[lindex $dat 0]
950 set file [lindex $dat 1]
952 foreach i
$w_columns {
953 $i tag conf g
$cmit -background $active_color
956 $w_file tag
raise found
964 catch {set author_name
$header($cmit,author
)}
965 catch {set author_email
$header($cmit,author-mail
)}
966 catch {set author_time
[format_date
$header($cmit,author-time
)]}
968 set committer_name
{}
969 set committer_email
{}
970 set committer_time
{}
971 catch {set committer_name
$header($cmit,committer
)}
972 catch {set committer_email
$header($cmit,committer-mail
)}
973 catch {set committer_time
[format_date
$header($cmit,committer-time
)]}
975 if {[catch {set msg
$header($cmit,message)}]} {
978 set fd
[git_read cat-file commit
$cmit]
979 fconfigure $fd -encoding binary -translation lf
980 # By default commits are assumed to be in utf-8
982 while {[gets $fd line
] > 0} {
983 if {[string match
{encoding *} $line]} {
984 set enc
[string tolower
[string range
$line 9 end
]]
990 set enc
[tcl_encoding
$enc]
992 set msg
[encoding convertfrom
$enc $msg]
994 set msg
[string trim
$msg]
996 set header
($cmit,message) $msg
999 $w_cviewer insert end
"commit $cmit\n" header_key
1000 $w_cviewer insert end
[strcat
[mc
"Author:"] "\t"] header_key
1001 $w_cviewer insert end
"$author_name $author_email" header_val
1002 $w_cviewer insert end
" $author_time\n" header_val
1004 $w_cviewer insert end
[strcat
[mc
"Committer:"] "\t"] header_key
1005 $w_cviewer insert end
"$committer_name $committer_email" header_val
1006 $w_cviewer insert end
" $committer_time\n" header_val
1008 if {$file ne
$path} {
1009 $w_cviewer insert end
[strcat
[mc
"Original File:"] "\t"] header_key
1010 $w_cviewer insert end
"[escape_path $file]\n" header_val
1013 $w_cviewer insert end
"\n$msg"
1015 $w_cviewer conf
-state disabled
1017 set highlight_line
$lno
1018 set highlight_commit
$cmit
1020 if {[lsearch -exact $tooltip_commit $highlight_commit] != -1} {
1025 method _get_click_amov_info
{} {
1026 set pos
@$::cursorX,$::cursorY
1027 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
1028 return [lindex $amov_data $lno]
1031 method _copycommit
{} {
1032 set dat
[_get_click_amov_info
$this]
1042 method _format_offset_date
{base offset
} {
1043 set exval
[expr {$base + $offset*24*60*60}]
1044 return [clock format $exval -format {%Y-
%m-
%d
}]
1047 method _gitkcommit
{} {
1050 set dat
[_get_click_amov_info
$this]
1052 set cmit
[lindex $dat 0]
1054 # If the line belongs to the working copy, use HEAD instead
1055 if {$cmit eq
$nullid} {
1056 if {[catch {set cmit
[git rev-parse
--verify HEAD
]} err
]} {
1057 error_popup
[strcat
[mc
"Cannot find HEAD commit:"] "\n\n$err"]
1062 set radius
[get_config gui.blamehistoryctx
]
1063 set cmdline
[list --select-commit
=$cmit]
1067 set committer_time
{}
1069 catch {set author_time
$header($cmit,author-time
)}
1070 catch {set committer_time
$header($cmit,committer-time
)}
1072 if {$committer_time eq
{}} {
1073 set committer_time
$author_time
1076 set after_time
[_format_offset_date
$this $committer_time [expr {-$radius}]]
1077 set before_time
[_format_offset_date
$this $committer_time $radius]
1079 lappend cmdline
--after=$after_time --before=$before_time
1082 lappend cmdline
$cmit
1085 if {$commit ne
{}} {
1086 set base_rev
$commit
1089 if {$base_rev ne
$cmit} {
1090 lappend cmdline
$base_rev
1097 method _blameparent
{} {
1100 set dat
[_get_click_amov_info
$this]
1102 set cmit
[lindex $dat 0]
1103 set new_path
[lindex $dat 1]
1105 # Allow using Blame Parent on lines modified in the working copy
1106 if {$cmit eq
$nullid} {
1107 set parent_ref
"HEAD"
1109 set parent_ref
"$cmit^"
1111 if {[catch {set cparent
[git rev-parse
--verify $parent_ref]} err
]} {
1112 error_popup
[strcat
[mc
"Cannot find parent commit:"] "\n\n$err"]
1118 # Generate a diff between the commit and its parent,
1119 # and use the hunks to update the line number.
1120 # Request zero context to simplify calculations.
1121 if {$cmit eq
$nullid} {
1122 set diffcmd
[list diff-index
--unified=0 $cparent -- $new_path]
1124 set diffcmd
[list diff-tree
--unified=0 $cparent $cmit -- $new_path]
1126 if {[catch {set fd
[eval git_read
$diffcmd]} err
]} {
1127 $status stop
[mc
"Unable to display parent"]
1128 error_popup
[strcat
[mc
"Error loading diff:"] "\n\n$err"]
1132 set r_orig_line
[lindex $dat 2]
1138 fileevent $fd readable
[cb _read_diff_load_commit
\
1139 $fd $cparent $new_path $r_orig_line]
1144 method _read_diff_load_commit
{fd cparent new_path tline
} {
1145 if {$fd ne
$current_fd} {
1150 while {[gets $fd line
] >= 0} {
1151 if {[regexp {^
@@ -(\d
+)(,(\d
+))?
\+(\d
+)(,(\d
+))?
@@} $line line
\
1152 old_line osz old_size new_line nsz new_size
]} {
1154 if {$osz eq
{}} { set old_size
1 }
1155 if {$nsz eq
{}} { set new_size
1 }
1157 if {$new_line <= $tline} {
1158 if {[expr {$new_line + $new_size}] > $tline} {
1159 # Target line within the hunk
1160 set line_shift
[expr {
1161 ($new_size-$old_size)*($tline-$new_line)/$new_size
1164 set line_shift
[expr {$new_size-$old_size}]
1167 set r_orig_line
[expr {$r_orig_line - $line_shift}]
1176 _load_new_commit
$this \
1181 } ifdeleted
{ catch {close $fd} }
1183 method _show_tooltip
{cur_w pos
} {
1184 if {$tooltip_wm ne
{}} {
1185 _open_tooltip
$this $cur_w
1186 } elseif
{$tooltip_timer eq
{}} {
1187 set tooltip_timer
[after 1000 [cb _open_tooltip
$cur_w]]
1191 method _open_tooltip
{cur_w
} {
1192 set tooltip_timer
{}
1193 set pos_x
[winfo pointerx
$cur_w]
1194 set pos_y
[winfo pointery
$cur_w]
1195 if {[winfo containing
$pos_x $pos_y] ne
$cur_w} {
1200 if {$tooltip_wm ne
"$cur_w.tooltip"} {
1203 set tooltip_wm
[toplevel $cur_w.tooltip
-borderwidth 1]
1204 catch {wm attributes
$tooltip_wm -type tooltip
}
1205 wm overrideredirect
$tooltip_wm 1
1206 wm transient
$tooltip_wm [winfo toplevel $cur_w]
1207 set tooltip_t
$tooltip_wm.
label
1210 -highlightthickness 0 \
1214 -background lightyellow
\
1216 $tooltip_t tag conf section_header
-font font_uibold
1219 $tooltip_t conf
-state normal
1220 $tooltip_t delete
0.0 end
1223 set pos
@[join [list \
1224 [expr {$pos_x - [winfo rootx
$cur_w]}] \
1225 [expr {$pos_y - [winfo rooty
$cur_w]}]] ,]
1226 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
1227 if {$cur_w eq
$w_amov} {
1228 set dat
[lindex $amov_data $lno]
1231 set dat
[lindex $asim_data $lno]
1232 set org
[lindex $amov_data $lno]
1240 set cmit
[lindex $dat 0]
1241 set tooltip_commit
[list $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
"commit $cmit\n"
1251 $tooltip_t insert end
"$author_name $author_time\n"
1252 $tooltip_t insert end
"$summary"
1254 if {$org ne
{} && [lindex $org 0] ne
$cmit} {
1255 set save
[$tooltip_t get
0.0 end
]
1256 $tooltip_t delete
0.0 end
1258 set cmit
[lindex $org 0]
1259 set file [lindex $org 1]
1260 lappend tooltip_commit
$cmit
1265 catch {set author_name
$header($cmit,author
)}
1266 catch {set summary
$header($cmit,summary
)}
1267 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1269 $tooltip_t insert end
[strcat
[mc
"Originally By:"] "\n"] section_header
1270 $tooltip_t insert end
"commit $cmit\n"
1271 $tooltip_t insert end
"$author_name $author_time\n"
1272 $tooltip_t insert end
"$summary\n"
1274 if {$file ne
$path} {
1275 $tooltip_t insert end
[strcat
[mc
"In File:"] " "] section_header
1276 $tooltip_t insert end
"$file\n"
1279 $tooltip_t insert end
"\n"
1280 $tooltip_t insert end
[strcat
[mc
"Copied Or Moved Here By:"] "\n"] section_header
1281 $tooltip_t insert end
$save
1284 $tooltip_t conf
-state disabled
1285 _position_tooltip
$this
1287 # On MacOS raising a window causes it to acquire focus.
1288 # Tk 8.5 on MacOS seems to properly support wm transient,
1289 # so we can safely counter the effect there.
1290 if {$::have_tk85 && [is_MacOSX
]} {
1300 method _position_tooltip
{} {
1301 set max_h
[lindex [split [$tooltip_t index end
] .
] 0]
1303 for {set i
1} {$i <= $max_h} {incr i
} {
1304 set c
[lindex [split [$tooltip_t index
"$i.0 lineend"] .
] 1]
1305 if {$c > $max_w} {set max_w
$c}
1307 $tooltip_t conf
-width $max_w -height $max_h
1309 set req_w
[winfo reqwidth
$tooltip_t]
1310 set req_h
[winfo reqheight
$tooltip_t]
1311 set pos_x
[expr {[winfo pointerx .
] + 5}]
1312 set pos_y
[expr {[winfo pointery .
] + 10}]
1314 set g
"${req_w}x${req_h}"
1315 if {[tk windowingsystem
] eq
"win32" ||
$pos_x >= 0} {append g
+}
1317 if {[tk windowingsystem
] eq
"win32" ||
$pos_y >= 0} {append g
+}
1320 wm geometry
$tooltip_wm $g
1326 method _hide_tooltip
{} {
1327 if {$tooltip_wm ne
{}} {
1330 set tooltip_commit
{}
1332 if {$tooltip_timer ne
{}} {
1333 after cancel
$tooltip_timer
1334 set tooltip_timer
{}
1338 method _resize
{new_height
} {
1339 set diff
[expr {$new_height - $old_height}]
1340 if {$diff == 0} return
1342 set my
[expr {[winfo height
$w.file_pane
] - 25}]
1343 set o
[$w.file_pane sash coord
0]
1344 set ox
[lindex $o 0]
1345 set oy
[expr {[lindex $o 1] + $diff}]
1346 if {$oy < 0} {set oy
0}
1347 if {$oy > $my} {set oy
$my}
1348 $w.file_pane sash
place 0 $ox $oy
1350 set old_height
$new_height
1353 method _show_finder
{} {
1354 linebar
::hide $gotoline
1355 searchbar
::show $finder
1358 method _show_linebar
{} {
1359 searchbar
::hide $finder
1360 linebar
::show $gotoline