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
72 wm title
$top [append "[appname] ([reponame]): " [mc
"File Viewer"]]
74 set font_w
[font measure font_diff
"0"]
76 frame $w.header
-background gold
77 label $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 label $w.header.commit
\
98 -textvariable @commit
\
103 label $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 scrollbar $w.file_pane.out.sbx
\
214 -command [list $w_file xview
]
215 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 scrollbar $w.file_pane.cm.sbx
\
259 -command [list $w_cviewer xview
]
260 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
> "[list focus $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
> "[list focus $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
> [list focus $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 _kill
]
386 if {$current_fd ne
{}} {
387 kill_file_process
$current_fd
388 catch {close $current_fd}
393 method _load
{jump
} {
394 variable group_colors
398 if {$total_lines != 0 ||
$current_fd ne
{}} {
401 foreach i
$w_columns {
402 $i conf
-state normal
404 foreach g
[$i tag names
] {
405 if {[regexp {^g
[0-9a-f
]{40}$} $g]} {
409 $i conf
-state disabled
412 $w_cviewer conf
-state normal
413 $w_cviewer delete
0.0 end
414 $w_cviewer conf
-state disabled
416 set highlight_line
-1
417 set highlight_column
{}
418 set highlight_commit
{}
422 if {$history eq
{}} {
423 $w_back conf
-state disabled
425 $w_back conf
-state normal
428 # Index 0 is always empty. There is never line 0 as
429 # we use only 1 based lines, as that matches both with
430 # git-blame output and with Tk's text widget.
432 set amov_data
[list [list]]
433 set asim_data
[list [list]]
435 $status show
[mc
"Reading %s..." "$commit:[escape_path $path]"]
436 $w_path conf
-text [escape_path
$path]
438 set fd
[open $path r
]
439 fconfigure $fd -eofchar {}
441 set fd
[git_read cat-file blob
"$commit:$path"]
446 -encoding [get_path_encoding
$path]
447 fileevent $fd readable
[cb _read_file
$fd $jump]
451 method _history_menu
{} {
453 if {[winfo exists
$m]} {
459 for {set i
[expr {[llength $history] - 1}]
460 } {$i >= 0} {incr i
-1} {
461 set e
[lindex $history $i]
465 if {[regexp {^
[0-9a-f
]{40}$} $c]} {
466 set t
[string range
$c 0 8]...
467 } elseif
{$c eq
{}} {
468 set t
{Working Directory
}
472 if {![catch {set summary
$header($c,summary
)}]} {
474 if {[string length
$t] > 70} {
475 set t
[string range
$t 0 66]...
479 $m add command
-label $t -command [cb _goback
$i]
481 set X
[winfo rootx
$w_back]
482 set Y
[expr {[winfo rooty
$w_back] + [winfo height
$w_back]}]
487 set dat
[lindex $history $i]
488 set history [lrange $history 0 [expr {$i - 1}]]
489 set commit
[lindex $dat 0]
490 set path
[lindex $dat 1]
491 _load
$this [lrange $dat 2 5]
494 method _read_file
{fd jump
} {
495 if {$fd ne
$current_fd} {
500 foreach i
$w_columns {$i conf
-state normal
}
501 while {[gets $fd line
] >= 0} {
502 regsub "\r\$" $line {} line
507 if {$total_lines > 1} {
508 foreach i
$w_columns {$i insert end
"\n"}
511 $w_line insert end
"$total_lines" linenumber
512 $w_file insert end
"$line"
515 set ln_wc
[expr {[string length
$total_lines] + 2}]
516 if {[$w_line cget
-width] < $ln_wc} {
517 $w_line conf
-width $ln_wc
520 foreach i
$w_columns {$i conf
-state disabled
}
525 # If we don't force Tk to update the widgets *right now*
526 # none of our jump commands will cause a change in the UI.
530 if {[llength $jump] == 1} {
531 set highlight_line
[lindex $jump 0]
532 $w_file see
"$highlight_line.0"
533 } elseif
{[llength $jump] == 4} {
534 set highlight_column
[lindex $jump 0]
535 set highlight_line
[lindex $jump 1]
536 $w_file xview moveto
[lindex $jump 2]
537 $w_file yview moveto
[lindex $jump 3]
540 _exec_blame
$this $w_asim @asim_data
\
542 [mc
"Loading copy/move tracking annotations..."]
544 } ifdeleted
{ catch {close $fd} }
546 method _exec_blame
{cur_w cur_d
options cur_s
} {
547 lappend options --incremental
549 lappend options --contents $path
551 lappend options $commit
553 lappend options -- $path
554 set fd
[eval git_read
--nice blame
$options]
555 fconfigure $fd -blocking 0 -translation lf
-encoding utf-8
556 fileevent $fd readable
[cb _read_blame
$fd $cur_w $cur_d]
562 [mc
"lines annotated"]
565 method _read_blame
{fd cur_w cur_d
} {
566 upvar #0 $cur_d line_data
567 variable group_colors
569 if {$fd ne
$current_fd} {
574 $cur_w conf
-state normal
575 while {[gets $fd line
] >= 0} {
576 if {[regexp {^
([a-z0-9
]{40}) (\d
+) (\d
+) (\d
+)$} $line line
\
577 cmit original_line final_line line_count
]} {
579 set r_orig_line
$original_line
580 set r_final_line
$final_line
581 set r_line_count
$line_count
582 } elseif
{[string match
{filename *} $line]} {
583 set file [string range
$line 9 end
]
585 set lno
$r_final_line
589 if {[regexp {^
0{40}$} $cmit]} {
591 set commit_type curr_commit
592 } elseif
{$cmit eq
$commit} {
594 set commit_type curr_commit
596 set commit_type prior_commit
597 set commit_abbr
[string range
$cmit 0 3]
602 catch {set a_name
$header($cmit,author
)}
603 while {$a_name ne
{}} {
604 if {$author_abbr ne
{}
605 && [string index
$a_name 0] eq
{'
}} {
606 regsub {^'
[^'
]+'
\s
+} $a_name {} a_name
608 if {![regexp {^
([[:upper
:]])} $a_name _a
]} break
609 append author_abbr
$_a
612 {^
[[:upper
:]][^
\s
]*\s
+} \
613 $a_name {} a_name
]} break
615 if {$author_abbr eq
{}} {
618 set author_abbr
[string range
$author_abbr 0 3]
625 && $cmit eq
[lindex $line_data [expr {$first_lno - 1}] 0]
626 && $file eq
[lindex $line_data [expr {$first_lno - 1}] 1]
632 if {$first_lno < $lno} {
633 foreach g
[$w_file tag names
$first_lno.0] {
634 if {[regexp {^color
[0-9]+$} $g]} {
640 set i
[lsort [concat \
641 [$w_file tag names
"[expr {$first_lno - 1}].0"] \
642 [$w_file tag names
"[expr {$lno + $n}].0"] \
644 for {set g
0} {$g < [llength $group_colors]} {incr g
} {
645 if {[lsearch -sorted -exact $i color
$g] == -1} {
656 set lno_e
"$lno.0 lineend + 1c"
657 if {[lindex $line_data $lno] ne
{}} {
658 set g
[lindex $line_data $lno 0]
659 foreach i
$w_columns {
660 $i tag remove g
$g $lno.0 $lno_e
663 lset line_data
$lno [list $cmit $file $oln]
665 $cur_w delete
$lno.0 "$lno.0 lineend"
666 if {$lno == $first_lno} {
667 $cur_w insert
$lno.0 $commit_abbr $commit_type
668 } elseif
{$lno == [expr {$first_lno + 1}]} {
669 $cur_w insert
$lno.0 $author_abbr author_abbr
671 $cur_w insert
$lno.0 { |
}
674 foreach i
$w_columns {
675 if {$cur_w eq
$w_amov} {
677 {$g < [llength $group_colors]} \
679 $i tag remove color
$g $lno.0 $lno_e
681 $i tag add
$color $lno.0 $lno_e
683 $i tag add g
$cmit $lno.0 $lno_e
686 if {$highlight_column eq
$cur_w} {
687 if {$highlight_line == -1
688 && [lindex [$w_file yview
] 0] == 0} {
690 set highlight_line
$lno
692 if {$highlight_line == $lno} {
693 _showcommit
$this $cur_w $lno
704 $cmit eq
[lindex $line_data $lno 0]
705 && $file eq
[lindex $line_data $lno 1]
707 $cur_w delete
$lno.0 "$lno.0 lineend"
709 if {$lno == $first_lno} {
710 $cur_w insert
$lno.0 $commit_abbr $commit_type
711 } elseif
{$lno == [expr {$first_lno + 1}]} {
712 $cur_w insert
$lno.0 $author_abbr author_abbr
714 $cur_w insert
$lno.0 { |
}
717 if {$cur_w eq
$w_amov} {
718 foreach i
$w_columns {
720 {$g < [llength $group_colors]} \
722 $i tag remove color
$g $lno.0 $lno_e
724 $i tag add
$color $lno.0 $lno_e
731 } elseif
{[regexp {^
([a-z-
]+) (.
*)$} $line line key data
]} {
732 set header
($r_commit,$key) $data
735 $cur_w conf
-state disabled
739 if {$cur_w eq
$w_asim} {
740 # Switches for original location detection
741 set threshold
[get_config gui.copyblamethreshold
]
742 set original_options
[list "-C$threshold"]
744 if {![is_config_true gui.fastcopyblame
]} {
745 # thorough copy search; insert before the threshold
746 set original_options
[linsert $original_options 0 -C]
748 if {[git-version
>= 1.5.3]} {
749 lappend original_options
-w ; # ignore indentation changes
752 _exec_blame
$this $w_amov @amov_data
\
754 [mc
"Loading original location annotations..."]
757 $status stop
[mc
"Annotation complete."]
760 $status update $blame_lines $total_lines
762 } ifdeleted
{ catch {close $fd} }
764 method _find_commit_bound
{data_list start_idx delta
} {
765 upvar #0 $data_list line_data
767 set limit
[expr {[llength $line_data] - 1}]
768 set base_commit
[lindex $line_data $pos 0]
770 while {$pos > 0 && $pos < $limit} {
771 set new_pos
[expr {$pos + $delta}]
772 if {[lindex $line_data $new_pos 0] ne
$base_commit} {
782 method _fullcopyblame
{} {
783 if {$current_fd ne
{}} {
788 -message [mc
"Annotation process is already running."]
793 # Switches for original location detection
794 set threshold
[get_config gui.copyblamethreshold
]
795 set original_options
[list -C -C "-C$threshold"]
797 if {[git-version
>= 1.5.3]} {
798 lappend original_options
-w ; # ignore indentation changes
801 # Find the line range
802 set pos
@$::cursorX,$::cursorY
803 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
804 set min_amov_lno
[_find_commit_bound
$this @amov_data
$lno -1]
805 set max_amov_lno
[_find_commit_bound
$this @amov_data
$lno 1]
806 set min_asim_lno
[_find_commit_bound
$this @asim_data
$lno -1]
807 set max_asim_lno
[_find_commit_bound
$this @asim_data
$lno 1]
809 if {$min_asim_lno < $min_amov_lno} {
810 set min_amov_lno
$min_asim_lno
813 if {$max_asim_lno > $max_amov_lno} {
814 set max_amov_lno
$max_asim_lno
817 lappend original_options
-L "$min_amov_lno,$max_amov_lno"
820 for {set i
$min_amov_lno} {$i <= $max_amov_lno} {incr i
} {
821 lset amov_data
$i [list ]
824 # Start the back-end process
825 _exec_blame
$this $w_amov @amov_data
\
827 [mc
"Running thorough copy detection..."]
830 method _click
{cur_w pos
} {
831 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
832 _showcommit
$this $cur_w $lno
835 method _setencoding
{enc
} {
836 force_path_encoding
$path $enc
840 [lindex [$w_file xview
] 0] \
841 [lindex [$w_file yview
] 0] \
845 method _load_commit
{cur_w cur_d pos
} {
846 upvar #0 $cur_d line_data
847 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
848 set dat
[lindex $line_data $lno]
850 _load_new_commit
$this \
853 [list [lindex $dat 2]]
857 method _load_new_commit
{new_commit new_path jump
} {
858 lappend history [list \
862 [lindex [$w_file xview
] 0] \
863 [lindex [$w_file yview
] 0] \
866 set commit
$new_commit
871 method _showcommit
{cur_w lno
} {
873 variable active_color
875 if {$highlight_commit ne
{}} {
876 foreach i
$w_columns {
877 $i tag conf g
$highlight_commit -background {}
878 $i tag
lower g
$highlight_commit
882 if {$cur_w eq
$w_asim} {
883 set dat
[lindex $asim_data $lno]
884 set highlight_column
$w_asim
886 set dat
[lindex $amov_data $lno]
887 set highlight_column
$w_amov
890 $w_cviewer conf
-state normal
891 $w_cviewer delete
0.0 end
895 $w_cviewer insert end
[mc
"Loading annotation..."] still_loading
897 set cmit
[lindex $dat 0]
898 set file [lindex $dat 1]
900 foreach i
$w_columns {
901 $i tag conf g
$cmit -background $active_color
904 $w_file tag
raise found
912 catch {set author_name
$header($cmit,author
)}
913 catch {set author_email
$header($cmit,author-mail
)}
914 catch {set author_time
[format_date
$header($cmit,author-time
)]}
916 set committer_name
{}
917 set committer_email
{}
918 set committer_time
{}
919 catch {set committer_name
$header($cmit,committer
)}
920 catch {set committer_email
$header($cmit,committer-mail
)}
921 catch {set committer_time
[format_date
$header($cmit,committer-time
)]}
923 if {[catch {set msg
$header($cmit,message)}]} {
926 set fd
[git_read cat-file commit
$cmit]
927 fconfigure $fd -encoding binary -translation lf
928 if {[catch {set enc
$repo_config(i18n.commitencoding
)}]} {
931 while {[gets $fd line
] > 0} {
932 if {[string match
{encoding *} $line]} {
933 set enc
[string tolower
[string range
$line 9 end
]]
939 set enc
[tcl_encoding
$enc]
941 set msg
[encoding convertfrom
$enc $msg]
943 set msg
[string trim
$msg]
945 set header
($cmit,message) $msg
948 $w_cviewer insert end
"commit $cmit\n" header_key
949 $w_cviewer insert end
[strcat
[mc
"Author:"] "\t"] header_key
950 $w_cviewer insert end
"$author_name $author_email" header_val
951 $w_cviewer insert end
" $author_time\n" header_val
953 $w_cviewer insert end
[strcat
[mc
"Committer:"] "\t"] header_key
954 $w_cviewer insert end
"$committer_name $committer_email" header_val
955 $w_cviewer insert end
" $committer_time\n" header_val
957 if {$file ne
$path} {
958 $w_cviewer insert end
[strcat
[mc
"Original File:"] "\t"] header_key
959 $w_cviewer insert end
"[escape_path $file]\n" header_val
962 $w_cviewer insert end
"\n$msg"
964 $w_cviewer conf
-state disabled
966 set highlight_line
$lno
967 set highlight_commit
$cmit
969 if {[lsearch -exact $tooltip_commit $highlight_commit] != -1} {
974 method _get_click_amov_info
{} {
975 set pos
@$::cursorX,$::cursorY
976 set lno
[lindex [split [$::cursorW index
$pos] .
] 0]
977 return [lindex $amov_data $lno]
980 method _copycommit
{} {
981 set dat
[_get_click_amov_info
$this]
991 method _format_offset_date
{base offset
} {
992 set exval
[expr {$base + $offset*24*60*60}]
993 return [clock format $exval -format {%Y-
%m-
%d
}]
996 method _gitkcommit
{} {
999 set dat
[_get_click_amov_info
$this]
1001 set cmit
[lindex $dat 0]
1003 # If the line belongs to the working copy, use HEAD instead
1004 if {$cmit eq
$nullid} {
1005 if {[catch {set cmit
[git rev-parse
--verify HEAD
]} err
]} {
1006 error_popup
[strcat
[mc
"Cannot find HEAD commit:"] "\n\n$err"]
1011 set radius
[get_config gui.blamehistoryctx
]
1012 set cmdline
[list --select-commit
=$cmit]
1016 set committer_time
{}
1018 catch {set author_time
$header($cmit,author-time
)}
1019 catch {set committer_time
$header($cmit,committer-time
)}
1021 if {$committer_time eq
{}} {
1022 set committer_time
$author_time
1025 set after_time
[_format_offset_date
$this $committer_time [expr {-$radius}]]
1026 set before_time
[_format_offset_date
$this $committer_time $radius]
1028 lappend cmdline
--after=$after_time --before=$before_time
1031 lappend cmdline
$cmit
1034 if {$commit ne
{}} {
1035 set base_rev
$commit
1038 if {$base_rev ne
$cmit} {
1039 lappend cmdline
$base_rev
1046 method _blameparent
{} {
1049 set dat
[_get_click_amov_info
$this]
1051 set cmit
[lindex $dat 0]
1052 set new_path
[lindex $dat 1]
1054 # Allow using Blame Parent on lines modified in the working copy
1055 if {$cmit eq
$nullid} {
1056 set parent_ref
"HEAD"
1058 set parent_ref
"$cmit^"
1060 if {[catch {set cparent
[git rev-parse
--verify $parent_ref]} err
]} {
1061 error_popup
[strcat
[mc
"Cannot find parent commit:"] "\n\n$err"]
1067 # Generate a diff between the commit and its parent,
1068 # and use the hunks to update the line number.
1069 # Request zero context to simplify calculations.
1070 if {$cmit eq
$nullid} {
1071 set diffcmd
[list diff-index
--unified=0 $cparent -- $new_path]
1073 set diffcmd
[list diff-tree
--unified=0 $cparent $cmit -- $new_path]
1075 if {[catch {set fd
[eval git_read
$diffcmd]} err
]} {
1076 $status stop
[mc
"Unable to display parent"]
1077 error_popup
[strcat
[mc
"Error loading diff:"] "\n\n$err"]
1081 set r_orig_line
[lindex $dat 2]
1087 fileevent $fd readable
[cb _read_diff_load_commit
\
1088 $fd $cparent $new_path $r_orig_line]
1093 method _read_diff_load_commit
{fd cparent new_path tline
} {
1094 if {$fd ne
$current_fd} {
1099 while {[gets $fd line
] >= 0} {
1100 if {[regexp {^
@@ -(\d
+)(,(\d
+))?
\+(\d
+)(,(\d
+))?
@@} $line line
\
1101 old_line osz old_size new_line nsz new_size
]} {
1103 if {$osz eq
{}} { set old_size
1 }
1104 if {$nsz eq
{}} { set new_size
1 }
1106 if {$new_line <= $tline} {
1107 if {[expr {$new_line + $new_size}] > $tline} {
1108 # Target line within the hunk
1109 set line_shift
[expr {
1110 ($new_size-$old_size)*($tline-$new_line)/$new_size
1113 set line_shift
[expr {$new_size-$old_size}]
1116 set r_orig_line
[expr {$r_orig_line - $line_shift}]
1125 _load_new_commit
$this \
1130 } ifdeleted
{ catch {close $fd} }
1132 method _show_tooltip
{cur_w pos
} {
1133 if {$tooltip_wm ne
{}} {
1134 _open_tooltip
$this $cur_w
1135 } elseif
{$tooltip_timer eq
{}} {
1136 set tooltip_timer
[after 1000 [cb _open_tooltip
$cur_w]]
1140 method _open_tooltip
{cur_w
} {
1141 set tooltip_timer
{}
1142 set pos_x
[winfo pointerx
$cur_w]
1143 set pos_y
[winfo pointery
$cur_w]
1144 if {[winfo containing
$pos_x $pos_y] ne
$cur_w} {
1149 if {$tooltip_wm ne
"$cur_w.tooltip"} {
1152 set tooltip_wm
[toplevel $cur_w.tooltip
-borderwidth 1]
1153 wm overrideredirect
$tooltip_wm 1
1154 wm transient
$tooltip_wm [winfo toplevel $cur_w]
1155 set tooltip_t
$tooltip_wm.
label
1158 -highlightthickness 0 \
1162 -background lightyellow
\
1164 $tooltip_t tag conf section_header
-font font_uibold
1167 $tooltip_t conf
-state normal
1168 $tooltip_t delete
0.0 end
1171 set pos
@[join [list \
1172 [expr {$pos_x - [winfo rootx
$cur_w]}] \
1173 [expr {$pos_y - [winfo rooty
$cur_w]}]] ,]
1174 set lno
[lindex [split [$cur_w index
$pos] .
] 0]
1175 if {$cur_w eq
$w_amov} {
1176 set dat
[lindex $amov_data $lno]
1179 set dat
[lindex $asim_data $lno]
1180 set org
[lindex $amov_data $lno]
1188 set cmit
[lindex $dat 0]
1189 set tooltip_commit
[list $cmit]
1194 catch {set author_name
$header($cmit,author
)}
1195 catch {set summary
$header($cmit,summary
)}
1196 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1198 $tooltip_t insert end
"commit $cmit\n"
1199 $tooltip_t insert end
"$author_name $author_time\n"
1200 $tooltip_t insert end
"$summary"
1202 if {$org ne
{} && [lindex $org 0] ne
$cmit} {
1203 set save
[$tooltip_t get
0.0 end
]
1204 $tooltip_t delete
0.0 end
1206 set cmit
[lindex $org 0]
1207 set file [lindex $org 1]
1208 lappend tooltip_commit
$cmit
1213 catch {set author_name
$header($cmit,author
)}
1214 catch {set summary
$header($cmit,summary
)}
1215 catch {set author_time
[format_date
$header($cmit,author-time
)]}
1217 $tooltip_t insert end
[strcat
[mc
"Originally By:"] "\n"] section_header
1218 $tooltip_t insert end
"commit $cmit\n"
1219 $tooltip_t insert end
"$author_name $author_time\n"
1220 $tooltip_t insert end
"$summary\n"
1222 if {$file ne
$path} {
1223 $tooltip_t insert end
[strcat
[mc
"In File:"] " "] section_header
1224 $tooltip_t insert end
"$file\n"
1227 $tooltip_t insert end
"\n"
1228 $tooltip_t insert end
[strcat
[mc
"Copied Or Moved Here By:"] "\n"] section_header
1229 $tooltip_t insert end
$save
1232 $tooltip_t conf
-state disabled
1233 _position_tooltip
$this
1236 method _position_tooltip
{} {
1237 set max_h
[lindex [split [$tooltip_t index end
] .
] 0]
1239 for {set i
1} {$i <= $max_h} {incr i
} {
1240 set c
[lindex [split [$tooltip_t index
"$i.0 lineend"] .
] 1]
1241 if {$c > $max_w} {set max_w
$c}
1243 $tooltip_t conf
-width $max_w -height $max_h
1245 set req_w
[winfo reqwidth
$tooltip_t]
1246 set req_h
[winfo reqheight
$tooltip_t]
1247 set pos_x
[expr {[winfo pointerx .
] + 5}]
1248 set pos_y
[expr {[winfo pointery .
] + 10}]
1250 set g
"${req_w}x${req_h}"
1251 if {$pos_x >= 0} {append g
+}
1253 if {$pos_y >= 0} {append g
+}
1256 wm geometry
$tooltip_wm $g
1260 method _hide_tooltip
{} {
1261 if {$tooltip_wm ne
{}} {
1264 set tooltip_commit
{}
1266 if {$tooltip_timer ne
{}} {
1267 after cancel
$tooltip_timer
1268 set tooltip_timer
{}
1272 method _resize
{new_height
} {
1273 set diff
[expr {$new_height - $old_height}]
1274 if {$diff == 0} return
1276 set my
[expr {[winfo height
$w.file_pane
] - 25}]
1277 set o
[$w.file_pane sash coord
0]
1278 set ox
[lindex $o 0]
1279 set oy
[expr {[lindex $o 1] + $diff}]
1280 if {$oy < 0} {set oy
0}
1281 if {$oy > $my} {set oy
$my}
1282 $w.file_pane sash
place 0 $ox $oy
1284 set old_height
$new_height