2 # Copyright (C) 2006, 2007 Shawn Pearce
6 image create
photo ::blame::img_back_arrow -data {R0lGODlhDgAPAMZkAAFRCAJTCgNTCgNVCgNVCwFYCQNYCwBaBQJZCgBaCARZCwZaDwhdEAheEAdfDwdfFghjEQdmFwdtExODIxaKJReQLxqVKx2ZLSKbMimfOCihOCeiOCmiOSakODGsQTKsQy6tRjGuRDOvQjOxQjSzQzeyRzm0ST25U0K7UT69TkK9UkG
/UULAUULAUkPBU0XDVEfDV0jDWEfFV0rEWUjFWEbGV0XHVknHWUnIWUvJW07IXlHMYVLNYlPPZ1TRZFfTa1nTaVzSbFrValrYcGPXc17ZblzabF7bbmHccV3dc1
/db2LccmDdcF
/dd2HecWbddmTgdmTidGTidWbidmbldmzjfGnleWrlem7lgmjof2
/of2rqe27qfnPqg3buh3juh3rwinzyjIn
/n4
//n
////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEKAH8ALAAAAAAOAA8AAAeHgH
+Cg385hIeDSIaIhD9jOIyDSlJiM5F
/S1pVTTcxKywqNQuCRlxTUUJhYF9YUFsQf0ddV09EPjopJh8aQw8eVFZTRUE7MCglIR1ODH8YRkxAPDIvJyQeGUkNghU9QDQjIBscFxY2DoMULi1eBwgBAwIABIQTIlkJl4ISLwX5ghEG
/AlSgCgQADs
=}
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 embed
{i_w i_status i_commit i_path i_jump
} {
69 _init
$this $i_commit $i_path
71 foreach i
[list $w $w_amov $w_asim $w_line $w_file $w_cviewer [$finder editor
] [$gotoline editor
]] {
72 bind $i <F7
> [cb _show_finder
]
73 bind $i <$::M1B-Key
-f
> [cb _show_finder
]
74 bind $i <Escape
> [list $finder hide
]
75 bind $i <F3
> [list $finder find_next
]
76 bind $i <Shift-F3
> [list $finder find_prev
]
77 bind $i <F8
> [cb _show_linebar
]
78 bind $i <$::M1B-Key
-g
> [cb _show_linebar
]
81 grid columnconfigure
$w 0 -weight 1
82 grid rowconfigure
$w 0 -weight 0
83 grid rowconfigure
$w 1 -weight 1
84 grid rowconfigure
$w 2 -weight 0
91 constructor new
{i_commit i_path i_jump
} {
95 wm title
$top [append "[appname] ([reponame]): " [mc
"File Viewer"]]
97 set status
[::status_bar::new $w.status
]
99 set font_w
[font measure font_diff
"0"]
101 _init
$this $i_commit $i_path
103 grid configure
$w.status
-sticky ew
104 grid columnconfigure
$top 0 -weight 1
105 grid rowconfigure
$top 0 -weight 0
106 grid rowconfigure
$top 1 -weight 1
107 grid rowconfigure
$top 2 -weight 0
109 bind $top <F7
> [cb _show_finder
]
110 bind $top <Key-slash
> [cb _show_finder
]
111 bind $top <$::M1B-Key
-s
> [cb _show_finder
]
112 bind $top <$::M1B-Key
-f
> [cb _show_finder
]
113 bind $top <Escape
> [list searchbar
::hide $finder]
114 bind $top <F3
> [list searchbar
::find_next $finder]
115 bind $top <Shift-F3
> [list searchbar
::find_prev $finder]
116 bind $top <F8
> [cb _show_linebar
]
117 bind $top <$::M1B-Key
-g
> [cb _show_linebar
]
118 catch { bind $top <Shift-Key-XF86_Switch_VT_3
> [list searchbar
::find_prev $finder] }
120 set req_w
[winfo reqwidth
$top]
121 set req_h
[winfo reqheight
$top]
122 set scr_w
[expr {[winfo screenwidth
$top] - 40}]
123 set scr_h
[expr {[winfo screenheight
$top] - 120}]
124 set opt_w
[expr {$font_w * (80 + 5*3 + 3)}]
125 if {$req_w < $opt_w} {set req_w
$opt_w}
126 if {$req_w > $scr_w} {set req_w
$scr_w}
127 set opt_h
[expr {$req_w*4/3}]
128 if {$req_h < $scr_h} {set req_h
$scr_h}
129 if {$req_h > $opt_h} {set req_h
$opt_h}
130 set g
"${req_w}x${req_h}"
135 set old_height
[winfo height
$w.file_pane
]
136 $w.file_pane sash
place 0 \
137 [lindex [$w.file_pane sash coord
0] 0] \
138 [expr {int
($old_height * 0.80)}]
139 bind $w.file_pane
<Configure
> \
140 "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
143 wm protocol
$top WM_DELETE_WINDOW
"destroy $top"
144 bind $top <Destroy
> [cb _handle_destroy
%W
]
149 method _init
{i_commit i_path
} {
150 global cursor_ptr M1B M1T have_tk85 use_ttk NS
151 variable active_color
152 variable group_colors
158 tlabel
$w.header.commit_l
\
159 -text [mc
"Commit:"] \
164 set w_back
$w.header.commit_b
166 -image ::blame::img_back_arrow \
172 -activebackground gold
173 bind $w_back <Button-1
> "
174 if {\[$w_back cget -state\] eq {normal}} {
178 tlabel
$w.header.commit
\
179 -textvariable @commit
\
184 tlabel
$w.header.path_l
\
190 set w_path
$w.header.path
196 pack $w.header.commit_l
-side left
197 pack $w_back -side left
198 pack $w.header.commit
-side left
199 pack $w_path -fill x
-side right
200 pack $w.header.path_l
-side right
202 ${NS
}::panedwindow $w.file_pane
-orient vertical
203 frame $w.file_pane.out
-relief flat
-borderwidth 1
204 frame $w.file_pane.cm
-relief sunken
-borderwidth 1
206 $w.file_pane add
$w.file_pane.out
\
208 $w.file_pane add
$w.file_pane.cm
\
211 $w.file_pane configure
-borderwidth 0 -sashwidth 3
212 $w.file_pane add
$w.file_pane.out
\
217 $w.file_pane add
$w.file_pane.cm
\
224 set w_line
$w.file_pane.out.linenumber_t
227 -highlightthickness 0 \
237 $w_line tag conf linenumber
-justify right
-rmargin 5
239 set w_amov
$w.file_pane.out.amove_t
242 -highlightthickness 0 \
252 $w_amov tag conf author_abbr
-justify right
-rmargin 5
253 $w_amov tag conf curr_commit
254 $w_amov tag conf prior_commit
-foreground blue
-underline 1
255 $w_amov tag
bind prior_commit
\
257 "[cb _load_commit $w_amov @amov_data @%x,%y];break"
259 set w_asim
$w.file_pane.out.asimple_t
262 -highlightthickness 0 \
272 $w_asim tag conf author_abbr
-justify right
273 $w_asim tag conf curr_commit
274 $w_asim tag conf prior_commit
-foreground blue
-underline 1
275 $w_asim tag
bind prior_commit
\
277 "[cb _load_commit $w_asim @asim_data @%x,%y];break"
279 set w_file
$w.file_pane.out.file_t
282 -highlightthickness 0 \
291 -xscrollcommand [list $w.file_pane.out.sbx
set] \
294 $w_file configure
-inactiveselectbackground darkblue
296 $w_file tag conf found
\
299 set w_columns
[list $w_amov $w_asim $w_line $w_file]
301 delegate_sel_to
$w_file [list $w_amov $w_asim $w_line]
303 ${NS
}::scrollbar $w.file_pane.out.sbx
\
305 -command [list $w_file xview
]
306 ${NS
}::scrollbar $w.file_pane.out.sby
\
308 -command [list scrollbar2many
$w_columns yview
]
309 eval grid $w_columns $w.file_pane.out.sby
-sticky nsew
311 $w.file_pane.out.sbx
\
313 -columnspan [expr {[llength $w_columns] + 1}] \
315 grid columnconfigure
\
317 [expr {[llength $w_columns] - 1}] \
319 grid rowconfigure
$w.file_pane.out
0 -weight 1
321 set finder
[::searchbar::new \
322 $w.file_pane.out.ff
$w_file $w_file \
324 -columnspan [expr {[llength $w_columns] + 1}] \
327 set gotoline
[::linebar::new \
328 $w.file_pane.out.lf
$w_file \
330 -columnspan [expr {[llength $w_columns] + 1}] \
333 set w_cviewer
$w.file_pane.cm.t
342 -xscrollcommand [list $w.file_pane.cm.sbx
set] \
343 -yscrollcommand [list $w.file_pane.cm.sby
set] \
345 $w_cviewer tag conf still_loading
\
346 -font font_uiitalic
\
348 $w_cviewer tag conf header_key
\
350 -background $active_color \
352 $w_cviewer tag conf header_val
\
353 -background $active_color \
355 $w_cviewer tag
raise sel
356 ${NS
}::scrollbar $w.file_pane.cm.sbx
\
358 -command [list $w_cviewer xview
]
359 ${NS
}::scrollbar $w.file_pane.cm.sby
\
361 -command [list $w_cviewer yview
]
362 pack $w.file_pane.cm.sby
-side right
-fill y
363 pack $w.file_pane.cm.sbx
-side bottom
-fill x
364 pack $w_cviewer -expand 1 -fill both
366 menu $w.ctxm
-tearoff 0
367 $w.ctxm add command
\
368 -label [mc
"Copy Commit"] \
369 -command [cb _copycommit
]
370 $w.ctxm add separator
371 $w.ctxm add command
\
372 -label [mc
"Find Text..."] \
374 -command [cb _show_finder
]
375 $w.ctxm add command
\
376 -label [mc
"Goto Line..."] \
377 -accelerator "Ctrl-G" \
378 -command [cb _show_linebar
]
380 build_encoding_menu
$w.ctxm.enc
[cb _setencoding
]
381 $w.ctxm add cascade
\
382 -label [mc
"Encoding"] \
384 $w.ctxm add command
\
385 -label [mc
"Do Full Copy Detection"] \
386 -command [cb _fullcopyblame
]
387 $w.ctxm add separator
388 $w.ctxm add command
\
389 -label [mc
"Show History Context"] \
390 -command [cb _gitkcommit
]
391 $w.ctxm add command
\
392 -label [mc
"Blame Parent Commit"] \
393 -command [cb _blameparent
]
395 foreach i
$w_columns {
396 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
397 $i tag conf color
$g -background [lindex $group_colors $g]
401 $w_file tag
raise found
405 $i conf
-cursor $cursor_ptr
406 $i conf
-yscrollcommand \
407 "[list $finder scrolled]
408 [list many2scrollbar $w_columns yview $w.file_pane.out.sby]"
412 set bind_cmd delegator_bind
414 $bind_cmd $i <Button-1
> "
416 [cb _click $i @%x,%y]
420 bind $i <Any-Motion
> [cb _show_tooltip
$i @%x
,%y
]
421 bind $i <Any-Enter
> [cb _hide_tooltip
]
422 bind $i <Any-Leave
> [cb _hide_tooltip
]
428 tk_popup $w.ctxm %X %Y
430 bind $i <Shift-Tab
> "[list focus $w_cviewer];break"
431 bind $i <Tab
> "[cb _focus_search $w_cviewer];break"
434 foreach i
[concat $w_columns $w_cviewer] {
435 bind $i <Key-Up
> {catch {%W yview scroll
-1 units
};break}
436 bind $i <Key-Down
> {catch {%W yview scroll
1 units
};break}
437 bind $i <Key-Left
> {catch {%W xview scroll
-1 units
};break}
438 bind $i <Key-Right
> {catch {%W xview scroll
1 units
};break}
439 bind $i <Key-k
> {catch {%W yview scroll
-1 units
};break}
440 bind $i <Key-j
> {catch {%W yview scroll
1 units
};break}
441 bind $i <Key-h
> {catch {%W xview scroll
-1 units
};break}
442 bind $i <Key-l
> {catch {%W xview scroll
1 units
};break}
443 bind $i <$::M1B-Key
-b
> {catch {%W yview scroll
-1 pages
};break}
444 bind $i <$::M1B-Key
-f
> {catch {%W yview scroll
1 pages
};break}
447 bind $w_cviewer <Shift-Tab
> "[cb _focus_search $w_file];break"
448 bind $w_cviewer <Tab
> "[list focus $w_file];break"
449 bind $w_cviewer <Button-1
> [list focus $w_cviewer]
450 bind $w_file <Visibility
> [cb _focus_search
$w_file]
452 grid configure
$w.header
-sticky ew
453 grid configure
$w.file_pane
-sticky nsew
456 method _focus_search
{win
} {
457 if {[searchbar
::visible $finder]} {
458 focus [searchbar
::editor $finder]
464 method _handle_destroy
{win
} {
472 if {$current_fd ne
{}} {
473 kill_file_process
$current_fd
474 catch {close $current_fd}
479 method _load
{jump
} {
480 variable group_colors
484 if {$total_lines != 0 ||
$current_fd ne
{}} {
487 foreach i
$w_columns {
488 $i conf
-state normal
490 foreach g
[$i tag names
] {
491 if {[regexp {^g
[0-9a-f
]{40}$} $g]} {
495 $i conf
-state disabled
498 $w_cviewer conf
-state normal
499 $w_cviewer delete
0.0 end
500 $w_cviewer conf
-state disabled
502 set highlight_line
-1
503 set highlight_column
{}
504 set highlight_commit
{}
508 if {$history eq
{}} {
509 $w_back conf
-state disabled
511 $w_back conf
-state normal
514 # Index 0 is always empty. There is never line 0 as
515 # we use only 1 based lines, as that matches both with
516 # git-blame output and with Tk's text widget.
518 set amov_data
[list [list]]
519 set asim_data
[list [list]]
521 $status show
[mc
"Reading %s..." "$commit:[escape_path $path]"]
522 $w_path conf
-text [escape_path
$path]
525 if {![is_config_false gui.textconv
] && [git-version
>= 1.7.2]} {
526 set filter
[gitattr
$path diff
set]
527 set textconv
[get_config
[join [list diff
$filter textconv
] .
]]
528 if {$filter ne
{set} && $textconv ne
{}} {
533 if {$do_textconv ne
0} {
534 set fd
[open_cmd_pipe
$textconv $path]
536 set fd
[open $path r
]
538 fconfigure $fd -eofchar {}
540 if {$do_textconv ne
0} {
541 set fd
[git_read cat-file
--textconv "$commit:$path"]
543 set fd
[git_read cat-file blob
"$commit:$path"]
549 -encoding [get_path_encoding
$path]
550 fileevent $fd readable
[cb _read_file
$fd $jump]
554 method _history_menu
{} {
556 if {[winfo exists
$m]} {
562 for {set i
[expr {[llength $history] - 1}]
563 } {$i >= 0} {incr i
-1} {
564 set e
[lindex $history $i]
568 if {[regexp {^
[0-9a-f
]{40}$} $c]} {
569 set t
[string range
$c 0 8]...
570 } elseif
{$c eq
{}} {
571 set t
{Working Directory
}
575 if {![catch {set summary
$header($c,summary
)}]} {
577 if {[string length
$t] > 70} {
578 set t
[string range
$t 0 66]...
582 $m add command
-label $t -command [cb _goback
$i]
584 set X
[winfo rootx
$w_back]
585 set Y
[expr {[winfo rooty
$w_back] + [winfo height
$w_back]}]
590 set dat
[lindex $history $i]
591 set history [lrange $history 0 [expr {$i - 1}]]
592 set commit
[lindex $dat 0]
593 set path
[lindex $dat 1]
594 _load
$this [lrange $dat 2 5]
597 method _read_file
{fd jump
} {
598 if {$fd ne
$current_fd} {
603 foreach i
$w_columns {$i conf
-state normal
}
604 while {[gets $fd line
] >= 0} {
605 regsub "\r\$" $line {} line
610 if {$total_lines > 1} {
611 foreach i
$w_columns {$i insert end
"\n"}
614 $w_line insert end
"$total_lines" linenumber
615 $w_file insert end
"$line"
618 set ln_wc
[expr {[string length
$total_lines] + 2}]
619 if {[$w_line cget
-width] < $ln_wc} {
620 $w_line conf
-width $ln_wc
623 foreach i
$w_columns {$i conf
-state disabled
}
626 fconfigure $fd -blocking 1; # enable error reporting on close
627 if {[catch {close $fd} err
]} {
628 tk_messageBox -icon error -title [mc Error
] \
632 # If we don't force Tk to update the widgets *right now*
633 # none of our jump commands will cause a change in the UI.
637 if {[llength $jump] == 1} {
638 set highlight_line
[lindex $jump 0]
639 $w_file see
"$highlight_line.0"
640 } elseif
{[llength $jump] == 4} {
641 set highlight_column
[lindex $jump 0]
642 set highlight_line
[lindex $jump 1]
643 $w_file xview moveto
[lindex $jump 2]
644 $w_file yview moveto
[lindex $jump 3]
647 _exec_blame
$this $w_asim @asim_data
\
649 [mc
"Loading copy/move tracking annotations..."]
651 } ifdeleted
{ catch {close $fd} }
653 method _exec_blame
{cur_w cur_d
options cur_s
} {
654 lappend options --incremental --encoding=utf-8
656 lappend options --contents $path
658 lappend options $commit
660 lappend options -- $path
661 set fd
[eval git_read
--nice blame
$options]
662 fconfigure $fd -blocking 0 -translation lf
-encoding utf-8
663 fileevent $fd readable
[cb _read_blame
$fd $cur_w $cur_d]
669 [mc
"lines annotated"]
672 method _read_blame
{fd cur_w cur_d
} {
673 upvar #0 $cur_d line_data
674 variable group_colors
676 if {$fd ne
$current_fd} {
681 $cur_w conf
-state normal
682 while {[gets $fd line
] >= 0} {
683 if {[regexp {^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$} $line line
\
684 cmit original_line final_line line_count
]} {
686 set r_orig_line
$original_line
687 set r_final_line
$final_line
688 set r_line_count
$line_count
689 } elseif
{[string match
{filename *} $line]} {
690 set file [string range
$line 9 end
]
692 set lno
$r_final_line
696 if {[regexp {^
0{40}$} $cmit]} {
698 set commit_type curr_commit
699 } elseif
{$cmit eq
$commit} {
701 set commit_type curr_commit
703 set commit_type prior_commit
704 set commit_abbr
[string range
$cmit 0 3]
709 catch {set a_name
$header($cmit,author
)}
710 while {$a_name ne
{}} {
711 if {$author_abbr ne
{}
712 && [string index
$a_name 0] eq
{'
}} {
713 regsub {^'
[^'
]+'
\s
+} $a_name {} a_name
715 if {![regexp {^
([[:upper
:]])} $a_name _a
]} break
716 append author_abbr
$_a
719 {^
[[:upper
:]][^
\s
]*\s
+} \
720 $a_name {} a_name
]} break
722 if {$author_abbr eq
{}} {
725 set author_abbr
[string range
$author_abbr 0 3]
732 && $cmit eq
[lindex $line_data [expr {$first_lno - 1}] 0]
733 && $file eq
[lindex $line_data [expr {$first_lno - 1}] 1]
739 if {$first_lno < $lno} {
740 foreach g
[$w_file tag names
$first_lno.0] {
741 if {[regexp {^color
[0-9]+$} $g]} {
747 set i
[lsort [concat \
748 [$w_file tag names
"[expr {$first_lno - 1}].0"] \
749 [$w_file tag names
"[expr {$lno + $n}].0"] \
751 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
752 if {[lsearch -sorted -exact $i color
$g] == -1} {
763 set lno_e
"$lno.0 lineend + 1c"
764 if {[lindex $line_data $lno] ne
{}} {
765 set g
[lindex $line_data $lno 0]
766 foreach i
$w_columns {
767 $i tag remove g
$g $lno.0 $lno_e
770 lset line_data
$lno [list $cmit $file $oln]
772 $cur_w delete
$lno.0 "$lno.0 lineend"
773 if {$lno == $first_lno} {
774 $cur_w insert
$lno.0 $commit_abbr $commit_type
775 } elseif
{$lno == [expr {$first_lno + 1}]} {
776 $cur_w insert
$lno.0 $author_abbr author_abbr
778 $cur_w insert
$lno.0 { |
}
781 foreach i
$w_columns {
782 if {$cur_w eq
$w_amov} {
784 {$g < [llength $group_colors]} \
786 $i tag remove color
$g $lno.0 $lno_e
788 $i tag add
$color $lno.0 $lno_e
790 $i tag add g
$cmit $lno.0 $lno_e
793 if {$highlight_column eq
$cur_w} {
794 if {$highlight_line == -1
795 && [lindex [$w_file yview
] 0] == 0} {
797 set highlight_line
$lno
799 if {$highlight_line == $lno} {
800 _showcommit
$this $cur_w $lno
811 $cmit eq
[lindex $line_data $lno 0]
812 && $file eq
[lindex $line_data $lno 1]
814 $cur_w delete
$lno.0 "$lno.0 lineend"
816 if {$lno == $first_lno} {
817 $cur_w insert
$lno.0 $commit_abbr $commit_type
818 } elseif
{$lno == [expr {$first_lno + 1}]} {
819 $cur_w insert
$lno.0 $author_abbr author_abbr
821 $cur_w insert
$lno.0 { |
}
824 if {$cur_w eq
$w_amov} {
825 foreach i
$w_columns {
827 {$g < [llength $group_colors]} \
829 $i tag remove color
$g $lno.0 $lno_e
831 $i tag add
$color $lno.0 $lno_e
838 } elseif
{[regexp {^
([a-z-
]+) (.
*)$} $line line key data
]} {
839 set header
($r_commit,$key) $data
842 $cur_w conf
-state disabled
846 if {$cur_w eq
$w_asim} {
847 # Switches for original location detection
848 set threshold
[get_config gui.copyblamethreshold
]
849 set original_options
[list "-C$threshold"]
851 if {![is_config_true gui.fastcopyblame
]} {
852 # thorough copy search; insert before the threshold
853 set original_options
[linsert $original_options 0 -C]
855 if {[git-version
>= 1.5.3]} {
856 lappend original_options
-w ; # ignore indentation changes
859 _exec_blame
$this $w_amov @amov_data
\
861 [mc
"Loading original location annotations..."]
864 $status stop
[mc
"Annotation complete."]
867 $status update $blame_lines $total_lines
869 } ifdeleted
{ catch {close $fd} }
871 method _find_commit_bound
{data_list start_idx delta
} {
872 upvar #0 $data_list line_data
874 set limit
[expr {[llength $line_data] - 1}]
875 set base_commit
[lindex $line_data $pos 0]
877 while {$pos > 0 && $pos < $limit} {
878 set new_pos
[expr {$pos + $delta}]
879 if {[lindex $line_data $new_pos 0] ne
$base_commit} {
889 method _fullcopyblame
{} {
890 if {$current_fd ne
{}} {
895 -message [mc
"Annotation process is already running."]
900 # Switches for original location detection
901 set threshold
[get_config gui.copyblamethreshold
]
902 set original_options
[list -C -C "-C$threshold"]
904 if {[git-version
>= 1.5.3]} {
905 lappend original_options
-w ; # ignore indentation changes
908 # Find the line range
909 set pos
@$::cursorX,$::cursorY
910 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
911 set min_amov_lno
[_find_commit_bound
$this @amov_data
$lno -1]
912 set max_amov_lno
[_find_commit_bound
$this @amov_data
$lno 1]
913 set min_asim_lno
[_find_commit_bound
$this @asim_data
$lno -1]
914 set max_asim_lno
[_find_commit_bound
$this @asim_data
$lno 1]
916 if {$min_asim_lno < $min_amov_lno} {
917 set min_amov_lno
$min_asim_lno
920 if {$max_asim_lno > $max_amov_lno} {
921 set max_amov_lno
$max_asim_lno
924 lappend original_options
-L "$min_amov_lno,$max_amov_lno"
927 for {set i
$min_amov_lno} {$i <= $max_amov_lno} {incr i
} {
928 lset amov_data
$i [list ]
931 # Start the back-end process
932 _exec_blame
$this $w_amov @amov_data
\
934 [mc
"Running thorough copy detection..."]
937 method _click
{cur_w pos
} {
938 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
939 _showcommit
$this $cur_w $lno
942 method _setencoding
{enc
} {
943 force_path_encoding
$path $enc
947 [lindex [$w_file xview
] 0] \
948 [lindex [$w_file yview
] 0] \
952 method _load_commit
{cur_w cur_d pos
} {
953 upvar #0 $cur_d line_data
954 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
955 set dat
[lindex $line_data $lno]
957 _load_new_commit
$this \
960 [list [lindex $dat 2]]
964 method _load_new_commit
{new_commit new_path jump
} {
965 lappend history [list \
969 [lindex [$w_file xview
] 0] \
970 [lindex [$w_file yview
] 0] \
973 set commit
$new_commit
978 method _showcommit
{cur_w lno
} {
980 variable active_color
982 if {$highlight_commit ne
{}} {
983 foreach i
$w_columns {
984 $i tag conf g
$highlight_commit -background {}
985 $i tag
lower g
$highlight_commit
989 if {$cur_w eq
$w_asim} {
990 set dat
[lindex $asim_data $lno]
991 set highlight_column
$w_asim
993 set dat
[lindex $amov_data $lno]
994 set highlight_column
$w_amov
997 $w_cviewer conf
-state normal
998 $w_cviewer delete
0.0 end
1002 $w_cviewer insert end
[mc
"Loading annotation..."] still_loading
1004 set cmit
[lindex $dat 0]
1005 set file [lindex $dat 1]
1007 foreach i
$w_columns {
1008 $i tag conf g
$cmit -background $active_color
1010 if {$i eq
$w_file} {
1011 $w_file tag
raise found
1019 catch {set author_name
$header($cmit,author
)}
1020 catch {set author_email
$header($cmit,author-mail
)}
1021 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1023 set committer_name
{}
1024 set committer_email
{}
1025 set committer_time
{}
1026 catch {set committer_name
$header($cmit,committer
)}
1027 catch {set committer_email
$header($cmit,committer-mail
)}
1028 catch {set committer_time
[format_date
$header($cmit,committer-time
)]}
1030 if {[catch {set msg
$header($cmit,message)}]} {
1033 set fd
[git_read cat-file commit
$cmit]
1034 fconfigure $fd -encoding binary -translation lf
1035 # By default commits are assumed to be in utf-8
1037 while {[gets $fd line
] > 0} {
1038 if {[string match
{encoding *} $line]} {
1039 set enc
[string tolower
[string range
$line 9 end
]]
1045 set enc
[tcl_encoding
$enc]
1047 set msg
[encoding convertfrom
$enc $msg]
1049 set msg
[string trim
$msg]
1051 set header
($cmit,message) $msg
1054 $w_cviewer insert end
"commit $cmit\n" header_key
1055 $w_cviewer insert end
[strcat
[mc
"Author:"] "\t"] header_key
1056 $w_cviewer insert end
"$author_name $author_email" header_val
1057 $w_cviewer insert end
" $author_time\n" header_val
1059 $w_cviewer insert end
[strcat
[mc
"Committer:"] "\t"] header_key
1060 $w_cviewer insert end
"$committer_name $committer_email" header_val
1061 $w_cviewer insert end
" $committer_time\n" header_val
1063 if {$file ne
$path} {
1064 $w_cviewer insert end
[strcat
[mc
"Original File:"] "\t"] header_key
1065 $w_cviewer insert end
"[escape_path $file]\n" header_val
1068 $w_cviewer insert end
"\n$msg"
1070 $w_cviewer conf
-state disabled
1072 set highlight_line
$lno
1073 set highlight_commit
$cmit
1075 if {[lsearch -exact $tooltip_commit $highlight_commit] != -1} {
1080 method _get_click_amov_info
{} {
1081 set pos
@$::cursorX,$::cursorY
1082 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
1083 return [lindex $amov_data $lno]
1086 method _copycommit
{} {
1087 set dat
[_get_click_amov_info
$this]
1097 method _format_offset_date
{base offset
} {
1098 set exval
[expr {$base + $offset*24*60*60}]
1099 return [clock format $exval -format {%Y-
%m-
%d
}]
1102 method _gitkcommit
{} {
1105 set dat
[_get_click_amov_info
$this]
1107 set cmit
[lindex $dat 0]
1109 # If the line belongs to the working copy, use HEAD instead
1110 if {$cmit eq
$nullid} {
1111 if {[catch {set cmit
[git rev-parse
--verify HEAD
]} err
]} {
1112 error_popup
[strcat
[mc
"Cannot find HEAD commit:"] "\n\n$err"]
1117 set radius
[get_config gui.blamehistoryctx
]
1118 set cmdline
[list --select-commit
=$cmit]
1122 set committer_time
{}
1124 catch {set author_time
$header($cmit,author-time
)}
1125 catch {set committer_time
$header($cmit,committer-time
)}
1127 if {$committer_time eq
{}} {
1128 set committer_time
$author_time
1131 set after_time
[_format_offset_date
$this $committer_time [expr {-$radius}]]
1132 set before_time
[_format_offset_date
$this $committer_time $radius]
1134 lappend cmdline
--after=$after_time --before=$before_time
1137 lappend cmdline
$cmit
1140 if {$commit ne
{}} {
1141 set base_rev
$commit
1144 if {$base_rev ne
$cmit} {
1145 lappend cmdline
$base_rev
1152 method _blameparent
{} {
1155 set dat
[_get_click_amov_info
$this]
1157 set cmit
[lindex $dat 0]
1158 set new_path
[lindex $dat 1]
1160 # Allow using Blame Parent on lines modified in the working copy
1161 if {$cmit eq
$nullid} {
1162 set parent_ref
"HEAD"
1164 set parent_ref
"$cmit^"
1166 if {[catch {set cparent
[git rev-parse
--verify $parent_ref]} err
]} {
1167 error_popup
[strcat
[mc
"Cannot find parent commit:"] "\n\n$err"]
1173 # Generate a diff between the commit and its parent,
1174 # and use the hunks to update the line number.
1175 # Request zero context to simplify calculations.
1176 if {$cmit eq
$nullid} {
1177 set diffcmd
[list diff-index
--unified=0 $cparent -- $new_path]
1179 set diffcmd
[list diff-tree
--unified=0 $cparent $cmit -- $new_path]
1181 if {[catch {set fd
[eval git_read
$diffcmd]} err
]} {
1182 $status stop
[mc
"Unable to display parent"]
1183 error_popup
[strcat
[mc
"Error loading diff:"] "\n\n$err"]
1187 set r_orig_line
[lindex $dat 2]
1193 fileevent $fd readable
[cb _read_diff_load_commit
\
1194 $fd $cparent $new_path $r_orig_line]
1199 method _read_diff_load_commit
{fd cparent new_path tline
} {
1200 if {$fd ne
$current_fd} {
1205 while {[gets $fd line
] >= 0} {
1206 if {[regexp {^
@@ -(\d
+)(,(\d
+))?
\+(\d
+)(,(\d
+))?
@@} $line line
\
1207 old_line osz old_size new_line nsz new_size
]} {
1209 if {$osz eq
{}} { set old_size
1 }
1210 if {$nsz eq
{}} { set new_size
1 }
1212 if {$new_line <= $tline} {
1213 if {[expr {$new_line + $new_size}] > $tline} {
1214 # Target line within the hunk
1215 set line_shift
[expr {
1216 ($new_size-$old_size)*($tline-$new_line)/$new_size
1219 set line_shift
[expr {$new_size-$old_size}]
1222 set r_orig_line
[expr {$r_orig_line - $line_shift}]
1231 _load_new_commit
$this \
1236 } ifdeleted
{ catch {close $fd} }
1238 method _show_tooltip
{cur_w pos
} {
1239 if {$tooltip_wm ne
{}} {
1240 _open_tooltip
$this $cur_w
1241 } elseif
{$tooltip_timer eq
{}} {
1242 set tooltip_timer
[after 1000 [cb _open_tooltip
$cur_w]]
1246 method _open_tooltip
{cur_w
} {
1247 set tooltip_timer
{}
1248 set pos_x
[winfo pointerx
$cur_w]
1249 set pos_y
[winfo pointery
$cur_w]
1250 if {[winfo containing
$pos_x $pos_y] ne
$cur_w} {
1255 if {$tooltip_wm ne
"$cur_w.tooltip"} {
1258 set tooltip_wm
[toplevel $cur_w.tooltip
-borderwidth 1]
1259 catch {wm attributes
$tooltip_wm -type tooltip
}
1260 wm overrideredirect
$tooltip_wm 1
1261 wm transient
$tooltip_wm [winfo toplevel $cur_w]
1262 set tooltip_t
$tooltip_wm.
label
1265 -highlightthickness 0 \
1269 -background lightyellow
\
1271 $tooltip_t tag conf section_header
-font font_uibold
1274 $tooltip_t conf
-state normal
1275 $tooltip_t delete
0.0 end
1278 set pos
@[join [list \
1279 [expr {$pos_x - [winfo rootx
$cur_w]}] \
1280 [expr {$pos_y - [winfo rooty
$cur_w]}]] ,]
1281 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
1282 if {$cur_w eq
$w_amov} {
1283 set dat
[lindex $amov_data $lno]
1286 set dat
[lindex $asim_data $lno]
1287 set org
[lindex $amov_data $lno]
1295 set cmit
[lindex $dat 0]
1296 set tooltip_commit
[list $cmit]
1301 catch {set author_name
$header($cmit,author
)}
1302 catch {set summary
$header($cmit,summary
)}
1303 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1305 $tooltip_t insert end
"commit $cmit\n"
1306 $tooltip_t insert end
"$author_name $author_time\n"
1307 $tooltip_t insert end
"$summary"
1309 if {$org ne
{} && [lindex $org 0] ne
$cmit} {
1310 set save
[$tooltip_t get
0.0 end
]
1311 $tooltip_t delete
0.0 end
1313 set cmit
[lindex $org 0]
1314 set file [lindex $org 1]
1315 lappend tooltip_commit
$cmit
1320 catch {set author_name
$header($cmit,author
)}
1321 catch {set summary
$header($cmit,summary
)}
1322 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1324 $tooltip_t insert end
[strcat
[mc
"Originally By:"] "\n"] section_header
1325 $tooltip_t insert end
"commit $cmit\n"
1326 $tooltip_t insert end
"$author_name $author_time\n"
1327 $tooltip_t insert end
"$summary\n"
1329 if {$file ne
$path} {
1330 $tooltip_t insert end
[strcat
[mc
"In File:"] " "] section_header
1331 $tooltip_t insert end
"$file\n"
1334 $tooltip_t insert end
"\n"
1335 $tooltip_t insert end
[strcat
[mc
"Copied Or Moved Here By:"] "\n"] section_header
1336 $tooltip_t insert end
$save
1339 $tooltip_t conf
-state disabled
1340 _position_tooltip
$this
1342 # On MacOS raising a window causes it to acquire focus.
1343 # Tk 8.5 on MacOS seems to properly support wm transient,
1344 # so we can safely counter the effect there.
1345 if {$::have_tk85 && [is_MacOSX
]} {
1355 method _position_tooltip
{} {
1356 set max_h
[lindex [split [$tooltip_t index end
] .
] 0]
1358 for {set i
1} {$i <= $max_h} {incr i
} {
1359 set c
[lindex [split [$tooltip_t index
"$i.0 lineend"] .
] 1]
1360 if {$c > $max_w} {set max_w
$c}
1362 $tooltip_t conf
-width $max_w -height $max_h
1364 set req_w
[winfo reqwidth
$tooltip_t]
1365 set req_h
[winfo reqheight
$tooltip_t]
1366 set pos_x
[expr {[winfo pointerx .
] + 5}]
1367 set pos_y
[expr {[winfo pointery .
] + 10}]
1369 set g
"${req_w}x${req_h}"
1370 if {[tk windowingsystem
] eq
"win32" ||
$pos_x >= 0} {append g
+}
1372 if {[tk windowingsystem
] eq
"win32" ||
$pos_y >= 0} {append g
+}
1375 wm geometry
$tooltip_wm $g
1381 method _hide_tooltip
{} {
1382 if {$tooltip_wm ne
{}} {
1385 set tooltip_commit
{}
1387 if {$tooltip_timer ne
{}} {
1388 after cancel
$tooltip_timer
1389 set tooltip_timer
{}
1393 method _resize
{new_height
} {
1394 set diff
[expr {$new_height - $old_height}]
1395 if {$diff == 0} return
1397 set my
[expr {[winfo height
$w.file_pane
] - 25}]
1398 set o
[$w.file_pane sash coord
0]
1399 set ox
[lindex $o 0]
1400 set oy
[expr {[lindex $o 1] + $diff}]
1401 if {$oy < 0} {set oy
0}
1402 if {$oy > $my} {set oy
$my}
1403 $w.file_pane sash
place 0 $ox $oy
1405 set old_height
$new_height
1408 method _show_finder
{} {
1409 linebar
::hide $gotoline
1410 searchbar
::show $finder
1413 method _show_linebar
{} {
1414 searchbar
::hide $finder
1415 linebar
::show $gotoline