3
4
class blame {
5
6
-field commit ; # input commit to blame
7
-field path ; # input filename to view in $commit
8
-
9
-field w
10
-field w_line
11
-field w_cgrp
12
-field w_load
13
-field w_file
14
-field w_cmit
15
-field status
16
-field old_height
17
-
6
+image create photo ::blame::img_back_arrow -data {R0lGODlhGAAYAIUAAPwCBEzKXFTSZIz+nGzmhGzqfGTidIT+nEzGXHTqhGzmfGzifFzadETCVES+VARWDFzWbHzyjAReDGTadFTOZDSyRDyyTCymPARaFGTedFzSbDy2TCyqRCyqPARaDAyCHES6VDy6VCyiPAR6HCSeNByWLARyFARiDARqFGTifARiFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAYABgAAAajQIBwSCwaj8ikcsk0BppJwRPqHEypQwHBis0WDAdEFyBIKBaMAKLBdjQeSkFBYTBAIvgEoS6JmhUTEwIUDQ4VFhcMGEhyCgoZExoUaxsWHB0THkgfAXUGAhoBDSAVFR0XBnCbDRmgog0hpSIiDJpJIyEQhBUcJCIlwA22SSYVogknEg8eD82qSigdDSknY0IqJQXPYxIl1dZCGNvWw+Dm510GQQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7}
7
+
8
+field commit ; # input commit to blame
9
+field path ; # input filename to view in $commit
10
+field history {}; # viewer history: {commit path}
11
+
12
+field w ; # top window in this viewer
13
+field w_back ; # our back button
14
+field w_path ; # label showing the current file path
15
+field w_line ; # text column: all line numbers
16
+field w_cgrp ; # text column: abbreviated commit SHA-1s
17
+field w_load ; # text column: loaded indicator
18
+field w_file ; # text column: actual file data
19
+field w_cmit ; # pane showing commit message
20
+field status ; # text variable bound to status bar
21
+field old_height ; # last known height of $w.file_pane
22
+
23
+field current_fd {} ; # background process running
24
field highlight_line -1 ; # current line selected
25
field highlight_commit {} ; # sha1 of commit selected
26
58
59
make_toplevel top w
60
wm title $top "[appname] ([reponame]): File Viewer"
55
- set status "Loading $commit:$path..."
61
57
- label $w.path -text "$commit:$path" \
62
+ frame $w.header -background orange
63
+ label $w.header.commit_l \
64
+ -text {Commit:} \
65
+ -background orange \
66
-anchor w \
59
- -justify left \
60
- -borderwidth 1 \
61
- -relief sunken \
62
- -font font_uibold
67
+ -justify left
68
+ set w_back $w.header.commit_b
69
+ button $w_back \
70
+ -command [cb _history_menu] \
71
+ -image ::blame::img_back_arrow \
72
+ -borderwidth 0 \
73
+ -relief flat \
74
+ -state disabled \
75
+ -background orange \
76
+ -activebackground orange
77
+ label $w.header.commit \
78
+ -textvariable @commit \
79
+ -background orange \
80
+ -anchor w \
81
+ -justify left
82
+ label $w.header.path_l \
83
+ -text {File:} \
84
+ -background orange \
85
+ -anchor w \
86
+ -justify left
87
+ set w_path $w.header.path
88
+ label $w_path \
89
+ -background orange \
90
+ -anchor w \
91
+ -justify left
92
+ pack $w.header.commit_l -side left
93
+ pack $w_back -side left
94
+ pack $w.header.commit -side left
95
+ pack $w_path -fill x -side right
96
+ pack $w.header.path_l -side right
97
98
panedwindow $w.file_pane -orient vertical
99
frame $w.file_pane.out
137
-height 40 \
138
-width 4 \
139
-font font_diff
140
+ $w_cgrp tag conf curr_commit
141
+ $w_cgrp tag conf prior_commit \
142
+ -foreground blue \
143
+ -underline 1
144
+ $w_cgrp tag bind prior_commit \
145
+ <Button-1> \
146
+ "[cb _load_commit @%x,%y];break"
147
148
set w_file $w.file_pane.out.file_t
149
text $w_file \
212
-textvariable @status \
213
-anchor w \
214
-justify left
174
- canvas $w.status.c \
175
- -width 100 \
176
- -height [expr {int([winfo reqheight $w.status.l] * 0.6)}] \
177
- -borderwidth 1 \
178
- -relief groove \
179
- -highlightt 0
180
- $w.status.c create rectangle 0 0 0 20 -tags bar -fill navy
215
pack $w.status.l -side left
182
- pack $w.status.c -side right
216
217
menu $w.ctxm -tearoff 0
218
$w.ctxm add command \
271
bind $top <Visibility> [list focus $top]
272
bind $w_file <Destroy> [list delete_this $this]
273
241
- grid configure $w.path -sticky ew
274
+ grid configure $w.header -sticky ew
275
grid configure $w.file_pane -sticky nsew
276
grid configure $w.status -sticky ew
277
grid columnconfigure $top 0 -weight 1
294
bind $w.file_pane <Configure> \
295
"if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
296
297
+ _load $this
298
+}
299
+
300
+method _load {} {
301
+ _hide_tooltip $this
302
+
303
+ if {$total_lines != 0 || $current_fd ne {}} {
304
+ if {$current_fd ne {}} {
305
+ catch {close $current_fd}
306
+ set current_fd {}
307
+ }
308
+
309
+ set highlight_line -1
310
+ set highlight_commit {}
311
+ set total_lines 0
312
+ set blame_lines 0
313
+ set commit_count 0
314
+ set commit_list {}
315
+ array unset order
316
+ array unset line_commit
317
+ array unset line_file
318
+
319
+ $w_load conf -state normal
320
+ $w_cgrp conf -state normal
321
+ $w_line conf -state normal
322
+ $w_file conf -state normal
323
+
324
+ $w_load delete 0.0 end
325
+ $w_cgrp delete 0.0 end
326
+ $w_line delete 0.0 end
327
+ $w_file delete 0.0 end
328
+
329
+ $w_load conf -state disabled
330
+ $w_cgrp conf -state disabled
331
+ $w_line conf -state disabled
332
+ $w_file conf -state disabled
333
+ }
334
+
335
+ if {[winfo exists $w.status.c]} {
336
+ $w.status.c coords bar 0 0 0 20
337
+ } else {
338
+ canvas $w.status.c \
339
+ -width 100 \
340
+ -height [expr {int([winfo reqheight $w.status.l] * 0.6)}] \
341
+ -borderwidth 1 \
342
+ -relief groove \
343
+ -highlightt 0
344
+ $w.status.c create rectangle 0 0 0 20 -tags bar -fill navy
345
+ pack $w.status.c -side right
346
+ }
347
+
348
+ if {$history eq {}} {
349
+ $w_back conf -state disabled
350
+ } else {
351
+ $w_back conf -state normal
352
+ }
353
+ lappend history [list $commit $path]
354
+
355
+ set status "Loading $commit:[escape_path $path]..."
356
+ $w_path conf -text [escape_path $path]
357
if {$commit eq {}} {
358
set fd [open $path r]
359
} else {
362
}
363
fconfigure $fd -blocking 0 -translation lf -encoding binary
364
fileevent $fd readable [cb _read_file $fd]
365
+ set current_fd $fd
366
+}
367
+
368
+method _history_menu {} {
369
+ set m $w.backmenu
370
+ if {[winfo exists $m]} {
371
+ $m delete 0 end
372
+ } else {
373
+ menu $m -tearoff 0
374
+ }
375
+
376
+ for {set i [expr {[llength $history] - 2}]
377
+ } {$i >= 0} {incr i -1} {
378
+ set e [lindex $history $i]
379
+ set c [lindex $e 0]
380
+ set f [lindex $e 1]
381
+
382
+ if {[regexp {^[0-9a-f]{40}$} $c]} {
383
+ set t [string range $c 0 8]...
384
+ } else {
385
+ set t $c
386
+ }
387
+ if {![catch {set summary $header($c,summary)}]} {
388
+ append t " $summary"
389
+ }
390
+
391
+ $m add command -label $t -command [cb _goback $i $c $f]
392
+ }
393
+ set X [winfo rootx $w_back]
394
+ set Y [expr {[winfo rooty $w_back] + [winfo height $w_back]}]
395
+ tk_popup $m $X $Y
396
+}
397
+
398
+method _goback {i c f} {
399
+ set history [lrange $history 0 [expr {$i - 1}]]
400
+ set commit $c
401
+ set path $f
402
+ _load $this
403
}
404
405
method _read_file {fd} {
406
+ if {$fd ne $current_fd} {
407
+ catch {close $fd}
408
+ return
409
+ }
410
+
411
$w_load conf -state normal
412
$w_cgrp conf -state normal
413
$w_line conf -state normal
434
if {[eof $fd]} {
435
close $fd
436
_status $this
301
- set cmd [list git blame -M -C --incremental]
437
+ set cmd {nice git blame -M -C --incremental}
438
if {$commit eq {}} {
439
lappend cmd --contents $path
440
} else {
444
set fd [open "| $cmd" r]
445
fconfigure $fd -blocking 0 -translation lf -encoding binary
446
fileevent $fd readable [cb _read_blame $fd]
447
+ set current_fd $fd
448
}
449
} ifdeleted { catch {close $fd} }
450
451
method _read_blame {fd} {
452
variable group_colors
453
454
+ if {$fd ne $current_fd} {
455
+ catch {close $fd}
456
+ return
457
+ }
458
+
459
$w_cgrp conf -state normal
460
while {[gets $fd line] >= 0} {
461
if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
486
487
if {[regexp {^0{40}$} $cmit]} {
488
set commit_abbr work
489
+ set commit_type curr_commit
490
+ } elseif {$cmit eq $commit} {
491
+ set commit_abbr this
492
+ set commit_type curr_commit
493
} else {
494
+ set commit_type prior_commit
495
set commit_abbr [string range $cmit 0 4]
496
}
497
543
544
$w_cgrp delete $lno.0 "$lno.0 lineend"
545
if {$lno == $first_lno} {
399
- $w_cgrp insert $lno.0 $commit_abbr
546
+ $w_cgrp insert $lno.0 $commit_abbr $commit_type
547
} elseif {$lno == [expr {$first_lno + 1}]} {
548
$w_cgrp insert $lno.0 $author_abbr
549
} else {
577
$w_cgrp delete $lno.0 "$lno.0 lineend"
578
579
if {$lno == $first_lno} {
433
- $w_cgrp insert $lno.0 $commit_abbr
580
+ $w_cgrp insert $lno.0 $commit_abbr $commit_type
581
} elseif {$lno == [expr {$first_lno + 1}]} {
582
$w_cgrp insert $lno.0 $author_abbr
583
} else {
594
595
if {[eof $fd]} {
596
close $fd
597
+ set current_fd {}
598
set status {Annotation complete.}
599
destroy $w.status.c
600
} else {
620
_showcommit $this $lno
621
}
622
623
+method _load_commit {pos} {
624
+ set lno [lindex [split [$w_cgrp index $pos] .] 0]
625
+ if {[catch {set cmit $line_commit($lno)}]} return
626
+ if {[catch {set file $line_file($lno) }]} return
627
+
628
+ set commit $cmit
629
+ set path $file
630
+ _load $this
631
+}
632
+
633
method _showcommit {lno} {
634
global repo_config
635
variable active_color