git-gui: Allow specifying an initial line for git gui blame.
[git/git.git] / lib / blame.tcl
CommitLineData
f522c9b5
SP
1# git-gui blame viewer
2# Copyright (C) 2006, 2007 Shawn Pearce
3
685caf9a
SP
4class blame {
5
22c6769d
SP
6image create photo ::blame::img_back_arrow -data {R0lGODlhGAAYAIUAAPwCBEzKXFTSZIz+nGzmhGzqfGTidIT+nEzGXHTqhGzmfGzifFzadETCVES+VARWDFzWbHzyjAReDGTadFTOZDSyRDyyTCymPARaFGTedFzSbDy2TCyqRCyqPARaDAyCHES6VDy6VCyiPAR6HCSeNByWLARyFARiDARqFGTifARiFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAYABgAAAajQIBwSCwaj8ikcsk0BppJwRPqHEypQwHBis0WDAdEFyBIKBaMAKLBdjQeSkFBYTBAIvgEoS6JmhUTEwIUDQ4VFhcMGEhyCgoZExoUaxsWHB0THkgfAXUGAhoBDSAVFR0XBnCbDRmgog0hpSIiDJpJIyEQhBUcJCIlwA22SSYVogknEg8eD82qSigdDSknY0IqJQXPYxIl1dZCGNvWw+Dm510GQQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7}
7
c17c1751
SP
8# Persistant data (survives loads)
9#
22c6769d 10field history {}; # viewer history: {commit path}
c17c1751 11field header ; # array commit,key -> header field
22c6769d 12
c17c1751
SP
13# Tk UI control paths
14#
22c6769d
SP
15field w ; # top window in this viewer
16field w_back ; # our back button
17field w_path ; # label showing the current file path
14c4dfd3 18field w_columns ; # list of all column widgets in the viewer
22c6769d 19field w_line ; # text column: all line numbers
fc816d7b 20field w_amov ; # text column: annotations + move tracking
172c92b4 21field w_asim ; # text column: annotations (simple computation)
22c6769d 22field w_file ; # text column: actual file data
fc816d7b 23field w_cviewer ; # pane showing commit message
b29bd5ca 24field status ; # status mega-widget instance
22c6769d
SP
25field old_height ; # last known height of $w.file_pane
26
c17c1751
SP
27# Tk UI colors
28#
5d198d67
SP
29variable active_color #c0edc5
30variable group_colors {
c17c1751
SP
31 #d6d6d6
32 #e1e1e1
33 #ececec
34}
35
36# Current blame data; cleared/reset on each load
37#
38field commit ; # input commit to blame
39field path ; # input filename to view in $commit
40
41field current_fd {} ; # background process running
42field highlight_line -1 ; # current line selected
172c92b4 43field highlight_column {} ; # current commit column selected
c17c1751 44field highlight_commit {} ; # sha1 of commit selected
685caf9a
SP
45
46field total_lines 0 ; # total length of file
47field blame_lines 0 ; # number of lines computed
fc816d7b 48field amov_data ; # list of {commit origfile origline}
172c92b4 49field asim_data ; # list of {commit origfile origline}
685caf9a 50
c17c1751
SP
51field r_commit ; # commit currently being parsed
52field r_orig_line ; # original line number
53field r_final_line ; # final line number
54field r_line_count ; # lines in this region
685caf9a 55
c17c1751 56field tooltip_wm {} ; # Current tooltip toplevel, if open
383d4e0f 57field tooltip_t {} ; # Text widget in $tooltip_wm
c17c1751 58field tooltip_timer {} ; # Current timer event for our tooltip
383d4e0f 59field tooltip_commit {} ; # Commit(s) in tooltip
f96cd7b6 60
f7078b40 61constructor new {i_commit i_path i_jump} {
37ebc93f 62 global cursor_ptr
5d198d67
SP
63 variable active_color
64 variable group_colors
37ebc93f 65
685caf9a
SP
66 set commit $i_commit
67 set path $i_path
68
69 make_toplevel top w
1ac17950 70 wm title $top [append "[appname] ([reponame]): " [mc "File Viewer"]]
f522c9b5 71
d80ded01 72 frame $w.header -background gold
22c6769d 73 label $w.header.commit_l \
1ac17950 74 -text [mc "Commit:"] \
d80ded01 75 -background gold \
c382fdd7 76 -foreground black \
f522c9b5 77 -anchor w \
22c6769d
SP
78 -justify left
79 set w_back $w.header.commit_b
08dda17e 80 label $w_back \
22c6769d
SP
81 -image ::blame::img_back_arrow \
82 -borderwidth 0 \
83 -relief flat \
84 -state disabled \
d80ded01 85 -background gold \
c382fdd7 86 -foreground black \
d80ded01 87 -activebackground gold
08dda17e
SP
88 bind $w_back <Button-1> "
89 if {\[$w_back cget -state\] eq {normal}} {
90 [cb _history_menu]
91 }
92 "
22c6769d
SP
93 label $w.header.commit \
94 -textvariable @commit \
d80ded01 95 -background gold \
c382fdd7 96 -foreground black \
22c6769d
SP
97 -anchor w \
98 -justify left
99 label $w.header.path_l \
1ac17950 100 -text [mc "File:"] \
d80ded01 101 -background gold \
c382fdd7 102 -foreground black \
22c6769d
SP
103 -anchor w \
104 -justify left
105 set w_path $w.header.path
106 label $w_path \
d80ded01 107 -background gold \
c382fdd7 108 -foreground black \
22c6769d
SP
109 -anchor w \
110 -justify left
111 pack $w.header.commit_l -side left
112 pack $w_back -side left
113 pack $w.header.commit -side left
114 pack $w_path -fill x -side right
115 pack $w.header.path_l -side right
f522c9b5 116
d0b741dc
SP
117 panedwindow $w.file_pane -orient vertical
118 frame $w.file_pane.out
119 frame $w.file_pane.cm
120 $w.file_pane add $w.file_pane.out \
121 -sticky nsew \
122 -minsize 100 \
123 -height 100 \
124 -width 100
125 $w.file_pane add $w.file_pane.cm \
126 -sticky nsew \
127 -minsize 25 \
128 -height 25 \
129 -width 100
130
d0b741dc 131 set w_line $w.file_pane.out.linenumber_t
d89a494f 132 text $w_line \
06325707
SP
133 -takefocus 0 \
134 -highlightthickness 0 \
135 -padx 0 -pady 0 \
c382fdd7
PH
136 -background white \
137 -foreground black \
138 -borderwidth 0 \
f522c9b5
SP
139 -state disabled \
140 -wrap none \
141 -height 40 \
375e1365 142 -width 6 \
f522c9b5 143 -font font_diff
06325707 144 $w_line tag conf linenumber -justify right -rmargin 5
f522c9b5 145
fc816d7b
SP
146 set w_amov $w.file_pane.out.amove_t
147 text $w_amov \
06325707
SP
148 -takefocus 0 \
149 -highlightthickness 0 \
150 -padx 0 -pady 0 \
c382fdd7
PH
151 -background white \
152 -foreground black \
153 -borderwidth 0 \
a46fe1c1
SP
154 -state disabled \
155 -wrap none \
156 -height 40 \
172c92b4 157 -width 5 \
a46fe1c1 158 -font font_diff
172c92b4 159 $w_amov tag conf author_abbr -justify right -rmargin 5
fc816d7b 160 $w_amov tag conf curr_commit
172c92b4 161 $w_amov tag conf prior_commit -foreground blue -underline 1
fc816d7b 162 $w_amov tag bind prior_commit \
22c6769d 163 <Button-1> \
172c92b4
SP
164 "[cb _load_commit $w_amov @amov_data @%x,%y];break"
165
166 set w_asim $w.file_pane.out.asimple_t
167 text $w_asim \
168 -takefocus 0 \
169 -highlightthickness 0 \
170 -padx 0 -pady 0 \
c382fdd7
PH
171 -background white \
172 -foreground black \
173 -borderwidth 0 \
172c92b4
SP
174 -state disabled \
175 -wrap none \
176 -height 40 \
177 -width 4 \
178 -font font_diff
179 $w_asim tag conf author_abbr -justify right
180 $w_asim tag conf curr_commit
181 $w_asim tag conf prior_commit -foreground blue -underline 1
182 $w_asim tag bind prior_commit \
183 <Button-1> \
184 "[cb _load_commit $w_asim @asim_data @%x,%y];break"
a46fe1c1 185
d0b741dc 186 set w_file $w.file_pane.out.file_t
d89a494f 187 text $w_file \
06325707
SP
188 -takefocus 0 \
189 -highlightthickness 0 \
190 -padx 0 -pady 0 \
c382fdd7
PH
191 -background white \
192 -foreground black \
193 -borderwidth 0 \
f522c9b5
SP
194 -state disabled \
195 -wrap none \
196 -height 40 \
197 -width 80 \
d0b741dc 198 -xscrollcommand [list $w.file_pane.out.sbx set] \
f522c9b5
SP
199 -font font_diff
200
172c92b4 201 set w_columns [list $w_amov $w_asim $w_line $w_file]
14c4dfd3 202
d0b741dc
SP
203 scrollbar $w.file_pane.out.sbx \
204 -orient h \
205 -command [list $w_file xview]
206 scrollbar $w.file_pane.out.sby \
207 -orient v \
14c4dfd3
SP
208 -command [list scrollbar2many $w_columns yview]
209 eval grid $w_columns $w.file_pane.out.sby -sticky nsew
210 grid conf \
211 $w.file_pane.out.sbx \
212 -column [expr {[llength $w_columns] - 1}] \
213 -sticky we
214 grid columnconfigure \
215 $w.file_pane.out \
216 [expr {[llength $w_columns] - 1}] \
217 -weight 1
d0b741dc 218 grid rowconfigure $w.file_pane.out 0 -weight 1
f522c9b5 219
fc816d7b
SP
220 set w_cviewer $w.file_pane.cm.t
221 text $w_cviewer \
c382fdd7
PH
222 -background white \
223 -foreground black \
224 -borderwidth 0 \
f522c9b5
SP
225 -state disabled \
226 -wrap none \
227 -height 10 \
228 -width 80 \
d0b741dc
SP
229 -xscrollcommand [list $w.file_pane.cm.sbx set] \
230 -yscrollcommand [list $w.file_pane.cm.sby set] \
f522c9b5 231 -font font_diff
debcd0fd
SP
232 $w_cviewer tag conf still_loading \
233 -font font_uiitalic \
234 -justify center
fc816d7b 235 $w_cviewer tag conf header_key \
74fe8985
SP
236 -tabs {3c} \
237 -background $active_color \
238 -font font_uibold
fc816d7b 239 $w_cviewer tag conf header_val \
74fe8985
SP
240 -background $active_color \
241 -font font_ui
fc816d7b 242 $w_cviewer tag raise sel
d0b741dc
SP
243 scrollbar $w.file_pane.cm.sbx \
244 -orient h \
fc816d7b 245 -command [list $w_cviewer xview]
d0b741dc
SP
246 scrollbar $w.file_pane.cm.sby \
247 -orient v \
fc816d7b 248 -command [list $w_cviewer yview]
d0b741dc
SP
249 pack $w.file_pane.cm.sby -side right -fill y
250 pack $w.file_pane.cm.sbx -side bottom -fill x
fc816d7b 251 pack $w_cviewer -expand 1 -fill both
f522c9b5 252
b29bd5ca 253 set status [::status_bar::new $w.status]
982cf98f 254
f522c9b5 255 menu $w.ctxm -tearoff 0
685caf9a 256 $w.ctxm add command \
1ac17950 257 -label [mc "Copy Commit"] \
685caf9a 258 -command [cb _copycommit]
a01fe996
AG
259 $w.ctxm add command \
260 -label [mc "Do Full Copy Detection"] \
261 -command [cb _fullcopyblame]
a9c80b83
AG
262 $w.ctxm add command \
263 -label [mc "Show History Context"] \
264 -command [cb _gitkcommit]
80fd76bd
AG
265 $w.ctxm add command \
266 -label [mc "Blame Parent Commit"] \
267 -command [cb _blameparent]
685caf9a 268
14c4dfd3 269 foreach i $w_columns {
5d198d67
SP
270 for {set g 0} {$g < [llength $group_colors]} {incr g} {
271 $i tag conf color$g -background [lindex $group_colors $g]
272 }
273
37ebc93f 274 $i conf -cursor $cursor_ptr
14c4dfd3
SP
275 $i conf -yscrollcommand [list many2scrollbar \
276 $w_columns yview $w.file_pane.out.sby]
b5a41224 277 bind $i <Button-1> "
41bf23d6
SP
278 [cb _hide_tooltip]
279 [cb _click $i @%x,%y]
280 focus $i
281 "
282 bind $i <Any-Motion> [cb _show_tooltip $i @%x,%y]
283 bind $i <Any-Enter> [cb _hide_tooltip]
284 bind $i <Any-Leave> [cb _hide_tooltip]
f522c9b5 285 bind_button3 $i "
41bf23d6 286 [cb _hide_tooltip]
f522c9b5
SP
287 set cursorX %x
288 set cursorY %y
289 set cursorW %W
290 tk_popup $w.ctxm %X %Y
291 "
fb626dc0
SP
292 bind $i <Shift-Tab> "[list focus $w_cviewer];break"
293 bind $i <Tab> "[list focus $w_cviewer];break"
f522c9b5
SP
294 }
295
fc816d7b 296 foreach i [concat $w_columns $w_cviewer] {
60aa065f
SP
297 bind $i <Key-Up> {catch {%W yview scroll -1 units};break}
298 bind $i <Key-Down> {catch {%W yview scroll 1 units};break}
299 bind $i <Key-Left> {catch {%W xview scroll -1 units};break}
300 bind $i <Key-Right> {catch {%W xview scroll 1 units};break}
301 bind $i <Key-k> {catch {%W yview scroll -1 units};break}
302 bind $i <Key-j> {catch {%W yview scroll 1 units};break}
303 bind $i <Key-h> {catch {%W xview scroll -1 units};break}
304 bind $i <Key-l> {catch {%W xview scroll 1 units};break}
305 bind $i <Control-Key-b> {catch {%W yview scroll -1 pages};break}
306 bind $i <Control-Key-f> {catch {%W yview scroll 1 pages};break}
307 }
308
fb626dc0
SP
309 bind $w_cviewer <Shift-Tab> "[list focus $w_file];break"
310 bind $w_cviewer <Tab> "[list focus $w_file];break"
fc816d7b 311 bind $w_cviewer <Button-1> [list focus $w_cviewer]
fb626dc0 312 bind $w_file <Visibility> [list focus $w_file]
f522c9b5 313
22c6769d 314 grid configure $w.header -sticky ew
d0b741dc
SP
315 grid configure $w.file_pane -sticky nsew
316 grid configure $w.status -sticky ew
317 grid columnconfigure $top 0 -weight 1
318 grid rowconfigure $top 0 -weight 0
319 grid rowconfigure $top 1 -weight 1
320 grid rowconfigure $top 2 -weight 0
321
322 set req_w [winfo reqwidth $top]
323 set req_h [winfo reqheight $top]
c1fd897a 324 set scr_h [expr {[winfo screenheight $top] - 100}]
d0b741dc 325 if {$req_w < 600} {set req_w 600}
c1fd897a 326 if {$req_h < $scr_h} {set req_h $scr_h}
d0b741dc
SP
327 set g "${req_w}x${req_h}"
328 wm geometry $top $g
329 update
330
331 set old_height [winfo height $w.file_pane]
332 $w.file_pane sash place 0 \
333 [lindex [$w.file_pane sash coord 0] 0] \
334 [expr {int($old_height * 0.70)}]
335 bind $w.file_pane <Configure> \
336 "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
337
e6131d30
AG
338 wm protocol $top WM_DELETE_WINDOW "destroy $top"
339 bind $top <Destroy> [cb _kill]
340
f7078b40 341 _load $this $i_jump
22c6769d
SP
342}
343
e6131d30
AG
344method _kill {} {
345 if {$current_fd ne {}} {
346 kill_file_process $current_fd
347 catch {close $current_fd}
348 set current_fd {}
349 }
350}
351
0dfed77b 352method _load {jump} {
5d198d67
SP
353 variable group_colors
354
22c6769d
SP
355 _hide_tooltip $this
356
357 if {$total_lines != 0 || $current_fd ne {}} {
e6131d30 358 _kill $this
22c6769d 359
14c4dfd3
SP
360 foreach i $w_columns {
361 $i conf -state normal
362 $i delete 0.0 end
5d198d67
SP
363 foreach g [$i tag names] {
364 if {[regexp {^g[0-9a-f]{40}$} $g]} {
365 $i tag delete $g
366 }
14c4dfd3
SP
367 }
368 $i conf -state disabled
369 }
370
0dfed77b
SP
371 $w_cviewer conf -state normal
372 $w_cviewer delete 0.0 end
373 $w_cviewer conf -state disabled
374
22c6769d 375 set highlight_line -1
172c92b4 376 set highlight_column {}
22c6769d
SP
377 set highlight_commit {}
378 set total_lines 0
22c6769d
SP
379 }
380
22c6769d
SP
381 if {$history eq {}} {
382 $w_back conf -state disabled
383 } else {
384 $w_back conf -state normal
385 }
22c6769d 386
2f85b7e4
SP
387 # Index 0 is always empty. There is never line 0 as
388 # we use only 1 based lines, as that matches both with
389 # git-blame output and with Tk's text widget.
390 #
fc816d7b 391 set amov_data [list [list]]
172c92b4 392 set asim_data [list [list]]
2f85b7e4 393
1ac17950 394 $status show [mc "Reading %s..." "$commit:[escape_path $path]"]
22c6769d 395 $w_path conf -text [escape_path $path]
a0db0d61
SP
396 if {$commit eq {}} {
397 set fd [open $path r]
6eb420ef 398 fconfigure $fd -eofchar {}
a0db0d61 399 } else {
0b812616 400 set fd [git_read cat-file blob "$commit:$path"]
a0db0d61 401 }
f522c9b5 402 fconfigure $fd -blocking 0 -translation lf -encoding binary
0dfed77b 403 fileevent $fd readable [cb _read_file $fd $jump]
22c6769d
SP
404 set current_fd $fd
405}
406
407method _history_menu {} {
408 set m $w.backmenu
409 if {[winfo exists $m]} {
410 $m delete 0 end
411 } else {
412 menu $m -tearoff 0
413 }
414
0dfed77b 415 for {set i [expr {[llength $history] - 1}]
22c6769d
SP
416 } {$i >= 0} {incr i -1} {
417 set e [lindex $history $i]
418 set c [lindex $e 0]
419 set f [lindex $e 1]
420
421 if {[regexp {^[0-9a-f]{40}$} $c]} {
422 set t [string range $c 0 8]...
c5db65ae
SP
423 } elseif {$c eq {}} {
424 set t {Working Directory}
22c6769d
SP
425 } else {
426 set t $c
427 }
428 if {![catch {set summary $header($c,summary)}]} {
429 append t " $summary"
b55a243d
SP
430 if {[string length $t] > 70} {
431 set t [string range $t 0 66]...
432 }
22c6769d
SP
433 }
434
0dfed77b 435 $m add command -label $t -command [cb _goback $i]
22c6769d
SP
436 }
437 set X [winfo rootx $w_back]
438 set Y [expr {[winfo rooty $w_back] + [winfo height $w_back]}]
439 tk_popup $m $X $Y
440}
441
0dfed77b
SP
442method _goback {i} {
443 set dat [lindex $history $i]
22c6769d 444 set history [lrange $history 0 [expr {$i - 1}]]
0dfed77b
SP
445 set commit [lindex $dat 0]
446 set path [lindex $dat 1]
447 _load $this [lrange $dat 2 5]
f522c9b5
SP
448}
449
0dfed77b 450method _read_file {fd jump} {
22c6769d
SP
451 if {$fd ne $current_fd} {
452 catch {close $fd}
453 return
454 }
455
14c4dfd3 456 foreach i $w_columns {$i conf -state normal}
f522c9b5
SP
457 while {[gets $fd line] >= 0} {
458 regsub "\r\$" $line {} line
685caf9a 459 incr total_lines
fc816d7b 460 lappend amov_data {}
172c92b4 461 lappend asim_data {}
a46fe1c1 462
bea39c2d 463 if {$total_lines > 1} {
14c4dfd3 464 foreach i $w_columns {$i insert end "\n"}
bea39c2d
SP
465 }
466
467 $w_line insert end "$total_lines" linenumber
468 $w_file insert end "$line"
f522c9b5 469 }
81fb7efe
SP
470
471 set ln_wc [expr {[string length $total_lines] + 2}]
472 if {[$w_line cget -width] < $ln_wc} {
473 $w_line conf -width $ln_wc
474 }
475
14c4dfd3 476 foreach i $w_columns {$i conf -state disabled}
f522c9b5
SP
477
478 if {[eof $fd]} {
479 close $fd
0dfed77b
SP
480
481 # If we don't force Tk to update the widgets *right now*
482 # none of our jump commands will cause a change in the UI.
483 #
484 update
485
486 if {[llength $jump] == 1} {
487 set highlight_line [lindex $jump 0]
488 $w_file see "$highlight_line.0"
489 } elseif {[llength $jump] == 4} {
490 set highlight_column [lindex $jump 0]
491 set highlight_line [lindex $jump 1]
492 $w_file xview moveto [lindex $jump 2]
493 $w_file yview moveto [lindex $jump 3]
494 }
495
949da61b
SP
496 _exec_blame $this $w_asim @asim_data \
497 [list] \
c8c4854b 498 [mc "Loading copy/move tracking annotations..."]
f522c9b5 499 }
685caf9a 500} ifdeleted { catch {close $fd} }
f522c9b5 501
172c92b4 502method _exec_blame {cur_w cur_d options cur_s} {
0b812616 503 lappend options --incremental
172c92b4 504 if {$commit eq {}} {
0b812616 505 lappend options --contents $path
172c92b4 506 } else {
0b812616 507 lappend options $commit
172c92b4 508 }
0b812616
SP
509 lappend options -- $path
510 set fd [eval git_read --nice blame $options]
172c92b4 511 fconfigure $fd -blocking 0 -translation lf -encoding binary
b29bd5ca 512 fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
172c92b4
SP
513 set current_fd $fd
514 set blame_lines 0
b29bd5ca
SP
515
516 $status start \
c8c4854b
MB
517 $cur_s \
518 [mc "lines annotated"]
172c92b4
SP
519}
520
b29bd5ca 521method _read_blame {fd cur_w cur_d} {
172c92b4 522 upvar #0 $cur_d line_data
5d198d67 523 variable group_colors
172c92b4 524
22c6769d
SP
525 if {$fd ne $current_fd} {
526 catch {close $fd}
527 return
528 }
529
172c92b4 530 $cur_w conf -state normal
f522c9b5
SP
531 while {[gets $fd line] >= 0} {
532 if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
533 cmit original_line final_line line_count]} {
685caf9a
SP
534 set r_commit $cmit
535 set r_orig_line $original_line
536 set r_final_line $final_line
537 set r_line_count $line_count
f522c9b5
SP
538 } elseif {[string match {filename *} $line]} {
539 set file [string range $line 9 end]
685caf9a
SP
540 set n $r_line_count
541 set lno $r_final_line
0dfed77b 542 set oln $r_orig_line
685caf9a 543 set cmit $r_commit
c9e6bfd8
SP
544
545 if {[regexp {^0{40}$} $cmit]} {
223475a7 546 set commit_abbr work
22c6769d
SP
547 set commit_type curr_commit
548 } elseif {$cmit eq $commit} {
549 set commit_abbr this
550 set commit_type curr_commit
c9e6bfd8 551 } else {
22c6769d 552 set commit_type prior_commit
172c92b4 553 set commit_abbr [string range $cmit 0 3]
c9e6bfd8
SP
554 }
555
223475a7
SP
556 set author_abbr {}
557 set a_name {}
558 catch {set a_name $header($cmit,author)}
559 while {$a_name ne {}} {
88dce86f
SP
560 if {$author_abbr ne {}
561 && [string index $a_name 0] eq {'}} {
562 regsub {^'[^']+'\s+} $a_name {} a_name
563 }
223475a7
SP
564 if {![regexp {^([[:upper:]])} $a_name _a]} break
565 append author_abbr $_a
566 unset _a
567 if {![regsub \
568 {^[[:upper:]][^\s]*\s+} \
569 $a_name {} a_name ]} break
570 }
571 if {$author_abbr eq {}} {
572 set author_abbr { |}
573 } else {
574 set author_abbr [string range $author_abbr 0 3]
c9e6bfd8 575 }
223475a7
SP
576 unset a_name
577
578 set first_lno $lno
579 while {
2f85b7e4 580 $first_lno > 1
172c92b4
SP
581 && $cmit eq [lindex $line_data [expr {$first_lno - 1}] 0]
582 && $file eq [lindex $line_data [expr {$first_lno - 1}] 1]
223475a7
SP
583 } {
584 incr first_lno -1
585 }
f522c9b5 586
5d198d67
SP
587 set color {}
588 if {$first_lno < $lno} {
589 foreach g [$w_file tag names $first_lno.0] {
590 if {[regexp {^color[0-9]+$} $g]} {
591 set color $g
592 break
593 }
594 }
595 } else {
596 set i [lsort [concat \
597 [$w_file tag names "[expr {$first_lno - 1}].0"] \
598 [$w_file tag names "[expr {$lno + $n}].0"] \
599 ]]
600 for {set g 0} {$g < [llength $group_colors]} {incr g} {
601 if {[lsearch -sorted -exact $i color$g] == -1} {
602 set color color$g
603 break
604 }
605 }
606 }
607 if {$color eq {}} {
608 set color color0
609 }
610
f522c9b5 611 while {$n > 0} {
0511798f 612 set lno_e "$lno.0 lineend + 1c"
172c92b4
SP
613 if {[lindex $line_data $lno] ne {}} {
614 set g [lindex $line_data $lno 0]
14c4dfd3
SP
615 foreach i $w_columns {
616 $i tag remove g$g $lno.0 $lno_e
617 }
f522c9b5 618 }
0dfed77b 619 lset line_data $lno [list $cmit $file $oln]
a46fe1c1 620
172c92b4 621 $cur_w delete $lno.0 "$lno.0 lineend"
223475a7 622 if {$lno == $first_lno} {
172c92b4 623 $cur_w insert $lno.0 $commit_abbr $commit_type
223475a7 624 } elseif {$lno == [expr {$first_lno + 1}]} {
172c92b4 625 $cur_w insert $lno.0 $author_abbr author_abbr
223475a7 626 } else {
172c92b4 627 $cur_w insert $lno.0 { |}
223475a7 628 }
a46fe1c1 629
14c4dfd3 630 foreach i $w_columns {
5d198d67
SP
631 if {$cur_w eq $w_amov} {
632 for {set g 0} \
633 {$g < [llength $group_colors]} \
634 {incr g} {
635 $i tag remove color$g $lno.0 $lno_e
636 }
637 $i tag add $color $lno.0 $lno_e
638 }
14c4dfd3
SP
639 $i tag add g$cmit $lno.0 $lno_e
640 }
f96cd7b6 641
172c92b4
SP
642 if {$highlight_column eq $cur_w} {
643 if {$highlight_line == -1
644 && [lindex [$w_file yview] 0] == 0} {
f522c9b5 645 $w_file see $lno.0
172c92b4
SP
646 set highlight_line $lno
647 }
648 if {$highlight_line == $lno} {
649 _showcommit $this $cur_w $lno
f522c9b5 650 }
f522c9b5
SP
651 }
652
653 incr n -1
654 incr lno
0dfed77b 655 incr oln
685caf9a 656 incr blame_lines
f522c9b5
SP
657 }
658
669fbc3d 659 while {
172c92b4
SP
660 $cmit eq [lindex $line_data $lno 0]
661 && $file eq [lindex $line_data $lno 1]
669fbc3d 662 } {
172c92b4 663 $cur_w delete $lno.0 "$lno.0 lineend"
223475a7
SP
664
665 if {$lno == $first_lno} {
172c92b4 666 $cur_w insert $lno.0 $commit_abbr $commit_type
223475a7 667 } elseif {$lno == [expr {$first_lno + 1}]} {
172c92b4 668 $cur_w insert $lno.0 $author_abbr author_abbr
223475a7 669 } else {
172c92b4 670 $cur_w insert $lno.0 { |}
c9e6bfd8 671 }
5d198d67
SP
672
673 if {$cur_w eq $w_amov} {
674 foreach i $w_columns {
675 for {set g 0} \
676 {$g < [llength $group_colors]} \
677 {incr g} {
678 $i tag remove color$g $lno.0 $lno_e
679 }
680 $i tag add $color $lno.0 $lno_e
681 }
682 }
683
223475a7 684 incr lno
c9e6bfd8 685 }
223475a7 686
685caf9a
SP
687 } elseif {[regexp {^([a-z-]+) (.*)$} $line line key data]} {
688 set header($r_commit,$key) $data
f522c9b5
SP
689 }
690 }
172c92b4 691 $cur_w conf -state disabled
f522c9b5
SP
692
693 if {[eof $fd]} {
694 close $fd
172c92b4 695 if {$cur_w eq $w_asim} {
57cae87b
AG
696 # Switches for original location detection
697 set threshold [get_config gui.copyblamethreshold]
698 set original_options [list "-C$threshold"]
699
700 if {![is_config_true gui.fastcopyblame]} {
701 # thorough copy search; insert before the threshold
702 set original_options [linsert $original_options 0 -C]
703 }
704 if {[git-version >= 1.5.3]} {
705 lappend original_options -w ; # ignore indentation changes
706 }
707
172c92b4 708 _exec_blame $this $w_amov @amov_data \
a8405667 709 $original_options \
c8c4854b 710 [mc "Loading original location annotations..."]
172c92b4
SP
711 } else {
712 set current_fd {}
c8c4854b 713 $status stop [mc "Annotation complete."]
172c92b4 714 }
f522c9b5 715 } else {
b29bd5ca 716 $status update $blame_lines $total_lines
f522c9b5 717 }
685caf9a 718} ifdeleted { catch {close $fd} }
f522c9b5 719
a01fe996
AG
720method _find_commit_bound {data_list start_idx delta} {
721 upvar #0 $data_list line_data
722 set pos $start_idx
723 set limit [expr {[llength $line_data] - 1}]
724 set base_commit [lindex $line_data $pos 0]
725
726 while {$pos > 0 && $pos < $limit} {
727 set new_pos [expr {$pos + $delta}]
728 if {[lindex $line_data $new_pos 0] ne $base_commit} {
729 return $pos
730 }
731
732 set pos $new_pos
733 }
734
735 return $pos
736}
737
738method _fullcopyblame {} {
739 if {$current_fd ne {}} {
740 tk_messageBox \
741 -icon error \
742 -type ok \
743 -title [mc "Busy"] \
744 -message [mc "Annotation process is already running."]
745
746 return
747 }
748
749 # Switches for original location detection
750 set threshold [get_config gui.copyblamethreshold]
751 set original_options [list -C -C "-C$threshold"]
752
753 if {[git-version >= 1.5.3]} {
754 lappend original_options -w ; # ignore indentation changes
755 }
756
757 # Find the line range
758 set pos @$::cursorX,$::cursorY
759 set lno [lindex [split [$::cursorW index $pos] .] 0]
760 set min_amov_lno [_find_commit_bound $this @amov_data $lno -1]
761 set max_amov_lno [_find_commit_bound $this @amov_data $lno 1]
762 set min_asim_lno [_find_commit_bound $this @asim_data $lno -1]
763 set max_asim_lno [_find_commit_bound $this @asim_data $lno 1]
764
765 if {$min_asim_lno < $min_amov_lno} {
766 set min_amov_lno $min_asim_lno
767 }
768
769 if {$max_asim_lno > $max_amov_lno} {
770 set max_amov_lno $max_asim_lno
771 }
772
773 lappend original_options -L "$min_amov_lno,$max_amov_lno"
774
775 # Clear lines
776 for {set i $min_amov_lno} {$i <= $max_amov_lno} {incr i} {
777 lset amov_data $i [list ]
778 }
779
780 # Start the back-end process
781 _exec_blame $this $w_amov @amov_data \
782 $original_options \
783 [mc "Running thorough copy detection..."]
784}
785
685caf9a 786method _click {cur_w pos} {
f522c9b5 787 set lno [lindex [split [$cur_w index $pos] .] 0]
172c92b4 788 _showcommit $this $cur_w $lno
f522c9b5
SP
789}
790
172c92b4
SP
791method _load_commit {cur_w cur_d pos} {
792 upvar #0 $cur_d line_data
793 set lno [lindex [split [$cur_w index $pos] .] 0]
794 set dat [lindex $line_data $lno]
2f85b7e4 795 if {$dat ne {}} {
80fd76bd
AG
796 _load_new_commit $this \
797 [lindex $dat 0] \
798 [lindex $dat 1] \
799 [list [lindex $dat 2]]
2f85b7e4 800 }
22c6769d
SP
801}
802
80fd76bd
AG
803method _load_new_commit {new_commit new_path jump} {
804 lappend history [list \
805 $commit $path \
806 $highlight_column \
807 $highlight_line \
808 [lindex [$w_file xview] 0] \
809 [lindex [$w_file yview] 0] \
810 ]
811
812 set commit $new_commit
813 set path $new_path
814 _load $this $jump
815}
816
172c92b4 817method _showcommit {cur_w lno} {
685caf9a 818 global repo_config
5d198d67 819 variable active_color
f522c9b5 820
685caf9a 821 if {$highlight_commit ne {}} {
14c4dfd3 822 foreach i $w_columns {
5d198d67 823 $i tag conf g$highlight_commit -background {}
383d4e0f 824 $i tag lower g$highlight_commit
14c4dfd3 825 }
f522c9b5
SP
826 }
827
0f32da53 828 if {$cur_w eq $w_asim} {
172c92b4
SP
829 set dat [lindex $asim_data $lno]
830 set highlight_column $w_asim
0f32da53
SP
831 } else {
832 set dat [lindex $amov_data $lno]
833 set highlight_column $w_amov
172c92b4
SP
834 }
835
fc816d7b
SP
836 $w_cviewer conf -state normal
837 $w_cviewer delete 0.0 end
2f85b7e4 838
2f85b7e4 839 if {$dat eq {}} {
f522c9b5 840 set cmit {}
c8c4854b 841 $w_cviewer insert end [mc "Loading annotation..."] still_loading
f522c9b5 842 } else {
2f85b7e4
SP
843 set cmit [lindex $dat 0]
844 set file [lindex $dat 1]
845
14c4dfd3
SP
846 foreach i $w_columns {
847 $i tag conf g$cmit -background $active_color
383d4e0f 848 $i tag raise g$cmit
14c4dfd3 849 }
f522c9b5
SP
850
851 set author_name {}
852 set author_email {}
853 set author_time {}
685caf9a
SP
854 catch {set author_name $header($cmit,author)}
855 catch {set author_email $header($cmit,author-mail)}
66c75a5c 856 catch {set author_time [format_date $header($cmit,author-time)]}
f522c9b5
SP
857
858 set committer_name {}
859 set committer_email {}
860 set committer_time {}
685caf9a
SP
861 catch {set committer_name $header($cmit,committer)}
862 catch {set committer_email $header($cmit,committer-mail)}
66c75a5c 863 catch {set committer_time [format_date $header($cmit,committer-time)]}
f522c9b5 864
685caf9a 865 if {[catch {set msg $header($cmit,message)}]} {
f522c9b5
SP
866 set msg {}
867 catch {
0b812616 868 set fd [git_read cat-file commit $cmit]
f522c9b5
SP
869 fconfigure $fd -encoding binary -translation lf
870 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
871 set enc utf-8
872 }
873 while {[gets $fd line] > 0} {
874 if {[string match {encoding *} $line]} {
875 set enc [string tolower [string range $line 9 end]]
876 }
877 }
c4638f66 878 set msg [read $fd]
f522c9b5
SP
879 close $fd
880
c4638f66
SP
881 set enc [tcl_encoding $enc]
882 if {$enc ne {}} {
883 set msg [encoding convertfrom $enc $msg]
884 set author_name [encoding convertfrom $enc $author_name]
885 set committer_name [encoding convertfrom $enc $committer_name]
886 set header($cmit,author) $author_name
887 set header($cmit,committer) $committer_name
888 set header($cmit,summary) \
889 [encoding convertfrom $enc $header($cmit,summary)]
890 }
891 set msg [string trim $msg]
f522c9b5 892 }
685caf9a 893 set header($cmit,message) $msg
f522c9b5
SP
894 }
895
fc816d7b 896 $w_cviewer insert end "commit $cmit\n" header_key
31bb1d1b 897 $w_cviewer insert end [strcat [mc "Author:"] "\t"] header_key
fc816d7b
SP
898 $w_cviewer insert end "$author_name $author_email" header_val
899 $w_cviewer insert end " $author_time\n" header_val
74fe8985 900
31bb1d1b 901 $w_cviewer insert end [strcat [mc "Committer:"] "\t"] header_key
fc816d7b
SP
902 $w_cviewer insert end "$committer_name $committer_email" header_val
903 $w_cviewer insert end " $committer_time\n" header_val
74fe8985 904
2f85b7e4 905 if {$file ne $path} {
31bb1d1b 906 $w_cviewer insert end [strcat [mc "Original File:"] "\t"] header_key
fc816d7b 907 $w_cviewer insert end "[escape_path $file]\n" header_val
74fe8985 908 }
0511798f 909
fc816d7b 910 $w_cviewer insert end "\n$msg"
f522c9b5 911 }
fc816d7b 912 $w_cviewer conf -state disabled
f522c9b5 913
685caf9a
SP
914 set highlight_line $lno
915 set highlight_commit $cmit
41bf23d6 916
383d4e0f 917 if {[lsearch -exact $tooltip_commit $highlight_commit] != -1} {
41bf23d6
SP
918 _hide_tooltip $this
919 }
f522c9b5
SP
920}
921
a9c80b83 922method _get_click_amov_info {} {
685caf9a
SP
923 set pos @$::cursorX,$::cursorY
924 set lno [lindex [split [$::cursorW index $pos] .] 0]
a9c80b83
AG
925 return [lindex $amov_data $lno]
926}
927
928method _copycommit {} {
929 set dat [_get_click_amov_info $this]
2f85b7e4 930 if {$dat ne {}} {
f522c9b5
SP
931 clipboard clear
932 clipboard append \
933 -format STRING \
934 -type STRING \
2f85b7e4 935 -- [lindex $dat 0]
f522c9b5
SP
936 }
937}
685caf9a 938
a9c80b83
AG
939method _format_offset_date {base offset} {
940 set exval [expr {$base + $offset*24*60*60}]
941 return [clock format $exval -format {%Y-%m-%d}]
942}
943
944method _gitkcommit {} {
945 set dat [_get_click_amov_info $this]
946 if {$dat ne {}} {
947 set cmit [lindex $dat 0]
948 set radius [get_config gui.blamehistoryctx]
949 set cmdline [list --select-commit=$cmit]
950
951 if {$radius > 0} {
952 set author_time {}
953 set committer_time {}
954
955 catch {set author_time $header($cmit,author-time)}
956 catch {set committer_time $header($cmit,committer-time)}
957
958 if {$committer_time eq {}} {
959 set committer_time $author_time
960 }
961
962 set after_time [_format_offset_date $this $committer_time [expr {-$radius}]]
963 set before_time [_format_offset_date $this $committer_time $radius]
964
965 lappend cmdline --after=$after_time --before=$before_time
966 }
967
968 lappend cmdline $cmit
969
970 set base_rev "HEAD"
971 if {$commit ne {}} {
972 set base_rev $commit
973 }
974
975 if {$base_rev ne $cmit} {
976 lappend cmdline $base_rev
977 }
978
979 do_gitk $cmdline
980 }
981}
982
80fd76bd
AG
983method _blameparent {} {
984 set dat [_get_click_amov_info $this]
985 if {$dat ne {}} {
986 set cmit [lindex $dat 0]
823f7cf8 987 set new_path [lindex $dat 1]
80fd76bd
AG
988
989 if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} {
990 error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
991 return;
992 }
993
823f7cf8
AG
994 _kill $this
995
996 # Generate a diff between the commit and its parent,
997 # and use the hunks to update the line number.
998 # Request zero context to simplify calculations.
999 if {[catch {set fd [eval git_read diff-tree \
1000 --unified=0 $cparent $cmit $new_path]} err]} {
1001 $status stop [mc "Unable to display parent"]
1002 error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
1003 return
1004 }
1005
1006 set r_orig_line [lindex $dat 2]
1007
1008 fconfigure $fd \
1009 -blocking 0 \
1010 -encoding binary \
1011 -translation binary
1012 fileevent $fd readable [cb _read_diff_load_commit \
1013 $fd $cparent $new_path $r_orig_line]
1014 set current_fd $fd
80fd76bd
AG
1015 }
1016}
1017
823f7cf8
AG
1018method _read_diff_load_commit {fd cparent new_path tline} {
1019 if {$fd ne $current_fd} {
1020 catch {close $fd}
1021 return
1022 }
1023
1024 while {[gets $fd line] >= 0} {
1025 if {[regexp {^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@} $line line \
1026 old_line osz old_size new_line nsz new_size]} {
1027
1028 if {$osz eq {}} { set old_size 1 }
1029 if {$nsz eq {}} { set new_size 1 }
1030
1031 if {$new_line <= $tline} {
1032 if {[expr {$new_line + $new_size}] > $tline} {
1033 # Target line within the hunk
1034 set line_shift [expr {
1035 ($new_size-$old_size)*($tline-$new_line)/$new_size
1036 }]
1037 } else {
1038 set line_shift [expr {$new_size-$old_size}]
1039 }
1040
1041 set r_orig_line [expr {$r_orig_line - $line_shift}]
1042 }
1043 }
1044 }
1045
1046 if {[eof $fd]} {
1047 close $fd;
1048 set current_fd {}
1049
1050 _load_new_commit $this \
1051 $cparent \
1052 $new_path \
1053 [list $r_orig_line]
1054 }
1055} ifdeleted { catch {close $fd} }
1056
41bf23d6 1057method _show_tooltip {cur_w pos} {
383d4e0f 1058 if {$tooltip_wm ne {}} {
41bf23d6
SP
1059 _open_tooltip $this $cur_w
1060 } elseif {$tooltip_timer eq {}} {
1061 set tooltip_timer [after 1000 [cb _open_tooltip $cur_w]]
1062 }
1063}
1064
1065method _open_tooltip {cur_w} {
1066 set tooltip_timer {}
1067 set pos_x [winfo pointerx $cur_w]
1068 set pos_y [winfo pointery $cur_w]
1069 if {[winfo containing $pos_x $pos_y] ne $cur_w} {
1070 _hide_tooltip $this
1071 return
1072 }
1073
383d4e0f
SP
1074 if {$tooltip_wm ne "$cur_w.tooltip"} {
1075 _hide_tooltip $this
1076
1077 set tooltip_wm [toplevel $cur_w.tooltip -borderwidth 1]
1078 wm overrideredirect $tooltip_wm 1
1079 wm transient $tooltip_wm [winfo toplevel $cur_w]
1080 set tooltip_t $tooltip_wm.label
1081 text $tooltip_t \
1082 -takefocus 0 \
1083 -highlightthickness 0 \
1084 -relief flat \
1085 -borderwidth 0 \
1086 -wrap none \
1087 -background lightyellow \
1088 -foreground black
1089 $tooltip_t tag conf section_header -font font_uibold
1090 pack $tooltip_t
1091 } else {
1092 $tooltip_t conf -state normal
1093 $tooltip_t delete 0.0 end
1094 }
1095
41bf23d6
SP
1096 set pos @[join [list \
1097 [expr {$pos_x - [winfo rootx $cur_w]}] \
1098 [expr {$pos_y - [winfo rooty $cur_w]}]] ,]
1099 set lno [lindex [split [$cur_w index $pos] .] 0]
172c92b4
SP
1100 if {$cur_w eq $w_amov} {
1101 set dat [lindex $amov_data $lno]
383d4e0f 1102 set org {}
172c92b4
SP
1103 } else {
1104 set dat [lindex $asim_data $lno]
383d4e0f 1105 set org [lindex $amov_data $lno]
172c92b4 1106 }
383d4e0f 1107
a4228962
SP
1108 if {$dat eq {}} {
1109 _hide_tooltip $this
1110 return
1111 }
1112
2f85b7e4 1113 set cmit [lindex $dat 0]
383d4e0f 1114 set tooltip_commit [list $cmit]
41bf23d6
SP
1115
1116 set author_name {}
383d4e0f 1117 set summary {}
41bf23d6
SP
1118 set author_time {}
1119 catch {set author_name $header($cmit,author)}
383d4e0f 1120 catch {set summary $header($cmit,summary)}
66c75a5c 1121 catch {set author_time [format_date $header($cmit,author-time)]}
41bf23d6 1122
383d4e0f
SP
1123 $tooltip_t insert end "commit $cmit\n"
1124 $tooltip_t insert end "$author_name $author_time\n"
1125 $tooltip_t insert end "$summary"
41bf23d6 1126
383d4e0f 1127 if {$org ne {} && [lindex $org 0] ne $cmit} {
0f32da53
SP
1128 set save [$tooltip_t get 0.0 end]
1129 $tooltip_t delete 0.0 end
1130
383d4e0f
SP
1131 set cmit [lindex $org 0]
1132 set file [lindex $org 1]
1133 lappend tooltip_commit $cmit
41bf23d6 1134
383d4e0f
SP
1135 set author_name {}
1136 set summary {}
1137 set author_time {}
1138 catch {set author_name $header($cmit,author)}
1139 catch {set summary $header($cmit,summary)}
cbf13d9e 1140 catch {set author_time [format_date $header($cmit,author-time)]}
41bf23d6 1141
31bb1d1b 1142 $tooltip_t insert end [strcat [mc "Originally By:"] "\n"] section_header
383d4e0f
SP
1143 $tooltip_t insert end "commit $cmit\n"
1144 $tooltip_t insert end "$author_name $author_time\n"
0f32da53 1145 $tooltip_t insert end "$summary\n"
79c50bf3 1146
383d4e0f 1147 if {$file ne $path} {
31bb1d1b 1148 $tooltip_t insert end [strcat [mc "In File:"] " "] section_header
0f32da53 1149 $tooltip_t insert end "$file\n"
383d4e0f 1150 }
0f32da53
SP
1151
1152 $tooltip_t insert end "\n"
31bb1d1b 1153 $tooltip_t insert end [strcat [mc "Copied Or Moved Here By:"] "\n"] section_header
0f32da53 1154 $tooltip_t insert end $save
79c50bf3
SP
1155 }
1156
383d4e0f 1157 $tooltip_t conf -state disabled
41bf23d6
SP
1158 _position_tooltip $this
1159}
1160
1161method _position_tooltip {} {
383d4e0f
SP
1162 set max_h [lindex [split [$tooltip_t index end] .] 0]
1163 set max_w 0
1164 for {set i 1} {$i <= $max_h} {incr i} {
1165 set c [lindex [split [$tooltip_t index "$i.0 lineend"] .] 1]
1166 if {$c > $max_w} {set max_w $c}
1167 }
1168 $tooltip_t conf -width $max_w -height $max_h
1169
1170 set req_w [winfo reqwidth $tooltip_t]
1171 set req_h [winfo reqheight $tooltip_t]
41bf23d6
SP
1172 set pos_x [expr {[winfo pointerx .] + 5}]
1173 set pos_y [expr {[winfo pointery .] + 10}]
1174
1175 set g "${req_w}x${req_h}"
1176 if {$pos_x >= 0} {append g +}
1177 append g $pos_x
1178 if {$pos_y >= 0} {append g +}
1179 append g $pos_y
1180
1181 wm geometry $tooltip_wm $g
1182 raise $tooltip_wm
1183}
1184
1185method _hide_tooltip {} {
1186 if {$tooltip_wm ne {}} {
1187 destroy $tooltip_wm
1188 set tooltip_wm {}
1189 set tooltip_commit {}
1190 }
1191 if {$tooltip_timer ne {}} {
1192 after cancel $tooltip_timer
1193 set tooltip_timer {}
1194 }
1195}
1196
d0b741dc
SP
1197method _resize {new_height} {
1198 set diff [expr {$new_height - $old_height}]
1199 if {$diff == 0} return
1200
1201 set my [expr {[winfo height $w.file_pane] - 25}]
1202 set o [$w.file_pane sash coord 0]
1203 set ox [lindex $o 0]
1204 set oy [expr {[lindex $o 1] + $diff}]
1205 if {$oy < 0} {set oy 0}
1206 if {$oy > $my} {set oy $my}
1207 $w.file_pane sash place 0 $ox $oy
1208
1209 set old_height $new_height
1210}
1211
685caf9a 1212}