field w_asim ; # text column: annotations (simple computation)
field w_file ; # text column: actual file data
field w_cviewer ; # pane showing commit message
-field status ; # text variable bound to status bar
+field status ; # status mega-widget instance
field old_height ; # last known height of $w.file_pane
# Tk UI colors
#ececec
}
+# Switches for original location detection
+#
+variable original_options [list -C -C]
+if {[git-version >= 1.5.3]} {
+ lappend original_options -w ; # ignore indentation changes
+}
+
# Current blame data; cleared/reset on each load
#
field commit ; # input commit to blame
set path $i_path
make_toplevel top w
- wm title $top "[appname] ([reponame]): File Viewer"
+ wm title $top [append "[appname] ([reponame]): " [mc "File Viewer"]]
frame $w.header -background gold
label $w.header.commit_l \
- -text {Commit:} \
+ -text [mc "Commit:"] \
-background gold \
-anchor w \
-justify left
-anchor w \
-justify left
label $w.header.path_l \
- -text {File:} \
+ -text [mc "File:"] \
-background gold \
-anchor w \
-justify left
pack $w.file_pane.cm.sbx -side bottom -fill x
pack $w_cviewer -expand 1 -fill both
- frame $w.status \
- -borderwidth 1 \
- -relief sunken
- label $w.status.l \
- -textvariable @status \
- -anchor w \
- -justify left
- pack $w.status.l -side left
+ set status [::status_bar::new $w.status]
menu $w.ctxm -tearoff 0
$w.ctxm add command \
- -label "Copy Commit" \
+ -label [mc "Copy Commit"] \
-command [cb _copycommit]
foreach i $w_columns {
set cursorW %W
tk_popup $w.ctxm %X %Y
"
+ bind $i <Shift-Tab> "[list focus $w_cviewer];break"
+ bind $i <Tab> "[list focus $w_cviewer];break"
}
foreach i [concat $w_columns $w_cviewer] {
bind $i <Control-Key-f> {catch {%W yview scroll 1 pages};break}
}
+ bind $w_cviewer <Shift-Tab> "[list focus $w_file];break"
+ bind $w_cviewer <Tab> "[list focus $w_file];break"
bind $w_cviewer <Button-1> [list focus $w_cviewer]
- bind $top <Visibility> [list focus $top]
+ bind $w_file <Visibility> [list focus $w_file]
grid configure $w.header -sticky ew
grid configure $w.file_pane -sticky nsew
set req_w [winfo reqwidth $top]
set req_h [winfo reqheight $top]
+ set scr_h [expr {[winfo screenheight $top] - 100}]
if {$req_w < 600} {set req_w 600}
- if {$req_h < 400} {set req_h 400}
+ if {$req_h < $scr_h} {set req_h $scr_h}
set g "${req_w}x${req_h}"
wm geometry $top $g
update
set total_lines 0
}
- if {[winfo exists $w.status.c]} {
- $w.status.c coords bar 0 0 0 20
- } else {
- canvas $w.status.c \
- -width 100 \
- -height [expr {int([winfo reqheight $w.status.l] * 0.6)}] \
- -borderwidth 1 \
- -relief groove \
- -highlightt 0
- $w.status.c create rectangle 0 0 0 20 -tags bar -fill navy
- pack $w.status.c -side right
- }
-
if {$history eq {}} {
$w_back conf -state disabled
} else {
set amov_data [list [list]]
set asim_data [list [list]]
- set status "Loading $commit:[escape_path $path]..."
+ $status show [mc "Reading %s..." "$commit:[escape_path $path]"]
$w_path conf -text [escape_path $path]
if {$commit eq {}} {
set fd [open $path r]
+ fconfigure $fd -eofchar {}
} else {
- set cmd [list git cat-file blob "$commit:$path"]
- set fd [open "| $cmd" r]
+ set fd [git_read cat-file blob "$commit:$path"]
}
fconfigure $fd -blocking 0 -translation lf -encoding binary
fileevent $fd readable [cb _read_file $fd $jump]
_exec_blame $this $w_asim @asim_data \
[list] \
- { copy/move tracking}
+ [mc "Loading copy/move tracking annotations..."]
}
} ifdeleted { catch {close $fd} }
method _exec_blame {cur_w cur_d options cur_s} {
- set cmd [list nice git blame]
- set cmd [concat $cmd $options]
- lappend cmd --incremental
+ lappend options --incremental
if {$commit eq {}} {
- lappend cmd --contents $path
+ lappend options --contents $path
} else {
- lappend cmd $commit
+ lappend options $commit
}
- lappend cmd -- $path
- set fd [open "| $cmd" r]
+ lappend options -- $path
+ set fd [eval git_read --nice blame $options]
fconfigure $fd -blocking 0 -translation lf -encoding binary
- fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d $cur_s]
+ fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
set current_fd $fd
set blame_lines 0
- _status $this $cur_s
+
+ $status start \
+ $cur_s \
+ [mc "lines annotated"]
}
-method _read_blame {fd cur_w cur_d cur_s} {
+method _read_blame {fd cur_w cur_d} {
upvar #0 $cur_d line_data
variable group_colors
+ variable original_options
if {$fd ne $current_fd} {
catch {close $fd}
set a_name {}
catch {set a_name $header($cmit,author)}
while {$a_name ne {}} {
+ if {$author_abbr ne {}
+ && [string index $a_name 0] eq {'}} {
+ regsub {^'[^']+'\s+} $a_name {} a_name
+ }
if {![regexp {^([[:upper:]])} $a_name _a]} break
append author_abbr $_a
unset _a
close $fd
if {$cur_w eq $w_asim} {
_exec_blame $this $w_amov @amov_data \
- [list -M -C -C] \
- { original location}
+ $original_options \
+ [mc "Loading original location annotations..."]
} else {
set current_fd {}
- set status {Annotation complete.}
- destroy $w.status.c
+ $status stop [mc "Annotation complete."]
}
} else {
- _status $this $cur_s
+ $status update $blame_lines $total_lines
}
} ifdeleted { catch {close $fd} }
-method _status {cur_s} {
- set have $blame_lines
- set total $total_lines
- set pdone 0
- if {$total} {set pdone [expr {100 * $have / $total}]}
-
- set status [format \
- "Loading%s annotations... %i of %i lines annotated (%2i%%)" \
- $cur_s $have $total $pdone]
- $w.status.c coords bar 0 0 $pdone 20
-}
-
method _click {cur_w pos} {
set lno [lindex [split [$cur_w index $pos] .] 0]
_showcommit $this $cur_w $lno
if {$dat eq {}} {
set cmit {}
- $w_cviewer insert end "Loading annotation..." still_loading
+ $w_cviewer insert end [mc "Loading annotation..."] still_loading
} else {
set cmit [lindex $dat 0]
set file [lindex $dat 1]
set author_time {}
catch {set author_name $header($cmit,author)}
catch {set author_email $header($cmit,author-mail)}
- catch {set author_time [clock format \
- $header($cmit,author-time) \
- -format {%Y-%m-%d %H:%M:%S}
- ]}
+ catch {set author_time [format_date $header($cmit,author-time)]}
set committer_name {}
set committer_email {}
set committer_time {}
catch {set committer_name $header($cmit,committer)}
catch {set committer_email $header($cmit,committer-mail)}
- catch {set committer_time [clock format \
- $header($cmit,committer-time) \
- -format {%Y-%m-%d %H:%M:%S}
- ]}
+ catch {set committer_time [format_date $header($cmit,committer-time)]}
if {[catch {set msg $header($cmit,message)}]} {
set msg {}
catch {
- set fd [open "| git cat-file commit $cmit" r]
+ set fd [git_read cat-file commit $cmit]
fconfigure $fd -encoding binary -translation lf
if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
set enc utf-8
set enc [string tolower [string range $line 9 end]]
}
}
- set msg [encoding convertfrom $enc [read $fd]]
- set msg [string trim $msg]
+ set msg [read $fd]
close $fd
- set author_name [encoding convertfrom $enc $author_name]
- set committer_name [encoding convertfrom $enc $committer_name]
-
- set header($cmit,author) $author_name
- set header($cmit,committer) $committer_name
+ set enc [tcl_encoding $enc]
+ if {$enc ne {}} {
+ set msg [encoding convertfrom $enc $msg]
+ set author_name [encoding convertfrom $enc $author_name]
+ set committer_name [encoding convertfrom $enc $committer_name]
+ set header($cmit,author) $author_name
+ set header($cmit,committer) $committer_name
+ set header($cmit,summary) \
+ [encoding convertfrom $enc $header($cmit,summary)]
+ }
+ set msg [string trim $msg]
}
set header($cmit,message) $msg
}
$w_cviewer insert end "commit $cmit\n" header_key
- $w_cviewer insert end "Author:\t" header_key
+ $w_cviewer insert end [strcat [mc "Author:"] "\t"] header_key
$w_cviewer insert end "$author_name $author_email" header_val
$w_cviewer insert end " $author_time\n" header_val
- $w_cviewer insert end "Committer:\t" header_key
+ $w_cviewer insert end [strcat [mc "Committer:"] "\t"] header_key
$w_cviewer insert end "$committer_name $committer_email" header_val
$w_cviewer insert end " $committer_time\n" header_val
if {$file ne $path} {
- $w_cviewer insert end "Original File:\t" header_key
+ $w_cviewer insert end [strcat [mc "Original File:"] "\t"] header_key
$w_cviewer insert end "[escape_path $file]\n" header_val
}
set org [lindex $amov_data $lno]
}
+ if {$dat eq {}} {
+ _hide_tooltip $this
+ return
+ }
+
set cmit [lindex $dat 0]
set tooltip_commit [list $cmit]
set author_time {}
catch {set author_name $header($cmit,author)}
catch {set summary $header($cmit,summary)}
- catch {set author_time [clock format \
- $header($cmit,author-time) \
- -format {%Y-%m-%d %H:%M:%S}
- ]}
+ catch {set author_time [format_date $header($cmit,author-time)]}
$tooltip_t insert end "commit $cmit\n"
$tooltip_t insert end "$author_name $author_time\n"
set author_time {}
catch {set author_name $header($cmit,author)}
catch {set summary $header($cmit,summary)}
- catch {set author_time [clock format \
- $header($cmit,author-time) \
- -format {%Y-%m-%d %H:%M:%S}
- ]}
+ catch {set author_time [format_date $header($cmit,author-time)]}
- $tooltip_t insert end "Originally By:\n" section_header
+ $tooltip_t insert end [strcat [mc "Originally By:"] "\n"] section_header
$tooltip_t insert end "commit $cmit\n"
$tooltip_t insert end "$author_name $author_time\n"
$tooltip_t insert end "$summary\n"
if {$file ne $path} {
- $tooltip_t insert end "In File: " section_header
+ $tooltip_t insert end [strcat [mc "In File:"] " "] section_header
$tooltip_t insert end "$file\n"
}
$tooltip_t insert end "\n"
- $tooltip_t insert end "Copied Or Moved Here By:\n" section_header
+ $tooltip_t insert end [strcat [mc "Copied Or Moved Here By:"] "\n"] section_header
$tooltip_t insert end $save
}