@@ -18,6 +18,7 @@ field w_path ; # label showing the current file path
18
18
field w_columns ; # list of all column widgets in the viewer
19
19
field w_line ; # text column: all line numbers
20
20
field w_amov ; # text column: annotations + move tracking
21
+ field w_asim ; # text column: annotations (simple computation)
21
22
field w_file ; # text column: actual file data
22
23
field w_cviewer ; # pane showing commit message
23
24
field status ; # text variable bound to status bar
@@ -39,13 +40,15 @@ field path ; # input filename to view in $commit
39
40
40
41
field current_fd {} ; # background process running
41
42
field highlight_line -1 ; # current line selected
43
+ field highlight_column {} ; # current commit column selected
42
44
field highlight_commit {} ; # sha1 of commit selected
43
45
field old_bgcolor {} ; # background of current selection
44
46
45
47
field total_lines 0 ; # total length of file
46
48
field blame_lines 0 ; # number of lines computed
47
49
field have_commit ; # array commit -> 1
48
50
field amov_data ; # list of {commit origfile origline}
51
+ field asim_data ; # list of {commit origfile origline}
49
52
50
53
field r_commit ; # commit currently being parsed
51
54
field r_orig_line ; # original line number
@@ -142,15 +145,32 @@ constructor new {i_commit i_path} {
142
145
-state disabled \
143
146
-wrap none \
144
147
-height 40 \
145
- -width 4 \
148
+ -width 5 \
146
149
-font font_diff
150
+ $w_amov tag conf author_abbr -justify right -rmargin 5
147
151
$w_amov tag conf curr_commit
148
- $w_amov tag conf prior_commit \
149
- -foreground blue \
150
- -underline 1
152
+ $w_amov tag conf prior_commit -foreground blue -underline 1
151
153
$w_amov tag bind prior_commit \
152
154
<Button-1> \
153
- " [ cb _load_commit @%x,%y] ;break"
155
+ " [ cb _load_commit $w_amov @amov_data @%x,%y] ;break"
156
+
157
+ set w_asim $w .file_pane.out.asimple_t
158
+ text $w_asim \
159
+ -takefocus 0 \
160
+ -highlightthickness 0 \
161
+ -padx 0 -pady 0 \
162
+ -background white -borderwidth 0 \
163
+ -state disabled \
164
+ -wrap none \
165
+ -height 40 \
166
+ -width 4 \
167
+ -font font_diff
168
+ $w_asim tag conf author_abbr -justify right
169
+ $w_asim tag conf curr_commit
170
+ $w_asim tag conf prior_commit -foreground blue -underline 1
171
+ $w_asim tag bind prior_commit \
172
+ <Button-1> \
173
+ " [ cb _load_commit $w_asim @asim_data @%x,%y] ;break"
154
174
155
175
set w_file $w .file_pane.out.file_t
156
176
text $w_file \
@@ -165,7 +185,7 @@ constructor new {i_commit i_path} {
165
185
-xscrollcommand [list $w .file_pane.out.sbx set] \
166
186
-font font_diff
167
187
168
- set w_columns [list $w_amov $w_line $w_file ]
188
+ set w_columns [list $w_amov $w_asim $ w_line $w_file ]
169
189
170
190
scrollbar $w .file_pane.out.sbx \
171
191
-orient h \
@@ -312,9 +332,9 @@ method _load {} {
312
332
}
313
333
314
334
set highlight_line -1
335
+ set highlight_column {}
315
336
set highlight_commit {}
316
337
set total_lines 0
317
- set blame_lines 0
318
338
array unset have_commit
319
339
}
320
340
@@ -343,6 +363,7 @@ method _load {} {
343
363
# git-blame output and with Tk's text widget.
344
364
#
345
365
set amov_data [list [list ]]
366
+ set asim_data [list [list ]]
346
367
347
368
set status " Loading $commit :[ escape_path $path ] ..."
348
369
$w_path conf -text [escape_path $path ]
@@ -410,6 +431,7 @@ method _read_file {fd} {
410
431
regsub "\r\$ " $line {} line
411
432
incr total_lines
412
433
lappend amov_data {}
434
+ lappend asim_data {}
413
435
414
436
if {$total_lines > 1} {
415
437
foreach i $w_columns {$i insert end " \n " }
@@ -428,29 +450,37 @@ method _read_file {fd} {
428
450
429
451
if {[eof $fd ]} {
430
452
close $fd
431
-
432
- _status $this
433
- set cmd {nice git blame -M -C --incremental}
434
- if {$commit eq {}} {
435
- lappend cmd --contents $path
436
- } else {
437
- lappend cmd $commit
438
- }
439
- lappend cmd -- $path
440
- set fd [open " | $cmd " r]
441
- fconfigure $fd -blocking 0 -translation lf -encoding binary
442
- fileevent $fd readable [cb _read_blame $fd ]
443
- set current_fd $fd
453
+ _exec_blame $this $w_asim @asim_data [list ] {}
444
454
}
445
455
} ifdeleted { catch {close $fd } }
446
456
447
- method _read_blame {fd} {
457
+ method _exec_blame {cur_w cur_d options cur_s} {
458
+ set cmd [list nice git blame]
459
+ set cmd [concat $cmd $options ]
460
+ lappend cmd --incremental
461
+ if {$commit eq {}} {
462
+ lappend cmd --contents $path
463
+ } else {
464
+ lappend cmd $commit
465
+ }
466
+ lappend cmd -- $path
467
+ set fd [open " | $cmd " r]
468
+ fconfigure $fd -blocking 0 -translation lf -encoding binary
469
+ fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d $cur_s ]
470
+ set current_fd $fd
471
+ set blame_lines 0
472
+ _status $this $cur_s
473
+ }
474
+
475
+ method _read_blame {fd cur_w cur_d cur_s} {
476
+ upvar #0 $cur_d line_data
477
+
448
478
if {$fd ne $current_fd } {
449
479
catch {close $fd }
450
480
return
451
481
}
452
482
453
- $w_amov conf -state normal
483
+ $cur_w conf -state normal
454
484
while {[gets $fd line] >= 0} {
455
485
if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
456
486
cmit original_line final_line line_count]} {
@@ -482,7 +512,7 @@ method _read_blame {fd} {
482
512
set commit_type curr_commit
483
513
} else {
484
514
set commit_type prior_commit
485
- set commit_abbr [string range $cmit 0 4 ]
515
+ set commit_abbr [string range $cmit 0 3 ]
486
516
}
487
517
488
518
set author_abbr {}
@@ -500,51 +530,50 @@ method _read_blame {fd} {
500
530
set author_abbr { |}
501
531
} else {
502
532
set author_abbr [string range $author_abbr 0 3]
503
- while {[string length $author_abbr ] < 4} {
504
- set author_abbr " $author_abbr "
505
- }
506
533
}
507
534
unset a_name
508
535
509
536
set first_lno $lno
510
537
while {
511
538
$first_lno > 1
512
- && $cmit eq [lindex $amov_data [expr {$first_lno - 1}] 0]
513
- && $file eq [lindex $amov_data [expr {$first_lno - 1}] 1]
539
+ && $cmit eq [lindex $line_data [expr {$first_lno - 1}] 0]
540
+ && $file eq [lindex $line_data [expr {$first_lno - 1}] 1]
514
541
} {
515
542
incr first_lno -1
516
543
}
517
544
518
545
while {$n > 0} {
519
546
set lno_e " $lno .0 lineend + 1c"
520
- if {[lindex $amov_data $lno ] ne {}} {
521
- set g [lindex $amov_data $lno 0]
547
+ if {[lindex $line_data $lno ] ne {}} {
548
+ set g [lindex $line_data $lno 0]
522
549
foreach i $w_columns {
523
550
$i tag remove g$g $lno .0 $lno_e
524
551
}
525
552
}
526
- lset amov_data $lno [list $cmit $file ]
553
+ lset line_data $lno [list $cmit $file ]
527
554
528
- $w_amov delete $lno .0 " $lno .0 lineend"
555
+ $cur_w delete $lno .0 " $lno .0 lineend"
529
556
if {$lno == $first_lno } {
530
- $w_amov insert $lno .0 $commit_abbr $commit_type
557
+ $cur_w insert $lno .0 $commit_abbr $commit_type
531
558
} elseif {$lno == [expr {$first_lno + 1}]} {
532
- $w_amov insert $lno .0 $author_abbr
559
+ $cur_w insert $lno .0 $author_abbr author_abbr
533
560
} else {
534
- $w_amov insert $lno .0 { |}
561
+ $cur_w insert $lno .0 { |}
535
562
}
536
563
537
564
foreach i $w_columns {
538
565
$i tag add g$cmit $lno .0 $lno_e
539
566
}
540
567
541
- if {$highlight_line == -1} {
542
- if {[lindex [$w_file yview] 0] == 0} {
568
+ if {$highlight_column eq $cur_w } {
569
+ if {$highlight_line == -1
570
+ && [lindex [$w_file yview] 0] == 0} {
543
571
$w_file see $lno .0
544
- _showcommit $this $lno
572
+ set highlight_line $lno
573
+ }
574
+ if {$highlight_line == $lno } {
575
+ _showcommit $this $cur_w $lno
545
576
}
546
- } elseif {$highlight_line == $lno } {
547
- _showcommit $this $lno
548
577
}
549
578
550
579
incr n -1
@@ -553,17 +582,17 @@ method _read_blame {fd} {
553
582
}
554
583
555
584
while {
556
- $cmit eq [lindex $amov_data $lno 0]
557
- && $file eq [lindex $amov_data $lno 1]
585
+ $cmit eq [lindex $line_data $lno 0]
586
+ && $file eq [lindex $line_data $lno 1]
558
587
} {
559
- $w_amov delete $lno .0 " $lno .0 lineend"
588
+ $cur_w delete $lno .0 " $lno .0 lineend"
560
589
561
590
if {$lno == $first_lno } {
562
- $w_amov insert $lno .0 $commit_abbr $commit_type
591
+ $cur_w insert $lno .0 $commit_abbr $commit_type
563
592
} elseif {$lno == [expr {$first_lno + 1}]} {
564
- $w_amov insert $lno .0 $author_abbr
593
+ $cur_w insert $lno .0 $author_abbr author_abbr
565
594
} else {
566
- $w_amov insert $lno .0 { |}
595
+ $cur_w insert $lno .0 { |}
567
596
}
568
597
incr lno
569
598
}
@@ -572,47 +601,53 @@ method _read_blame {fd} {
572
601
set header($r_commit ,$key ) $data
573
602
}
574
603
}
575
- $w_amov conf -state disabled
604
+ $cur_w conf -state disabled
576
605
577
606
if {[eof $fd ]} {
578
607
close $fd
579
- set current_fd {}
580
- set status {Annotation complete.}
581
- destroy $w .status.c
608
+ if {$cur_w eq $w_asim } {
609
+ _exec_blame $this $w_amov @amov_data \
610
+ [list -M -C -C] \
611
+ { move/copy tracking}
612
+ } else {
613
+ set current_fd {}
614
+ set status {Annotation complete.}
615
+ destroy $w .status.c
616
+ }
582
617
} else {
583
- _status $this
618
+ _status $this $cur_s
584
619
}
585
620
} ifdeleted { catch {close $fd } }
586
621
587
- method _status {} {
622
+ method _status {cur_s } {
588
623
set have $blame_lines
589
624
set total $total_lines
590
625
set pdone 0
591
626
if {$total } {set pdone [expr {100 * $have / $total }]}
592
627
593
628
set status [format \
594
- " Loading annotations... %i of %i lines annotated (%2i%%)" \
595
- $have $total $pdone ]
629
+ " Loading%s annotations... %i of %i lines annotated (%2i%%)" \
630
+ $cur_s $ have $total $pdone ]
596
631
$w .status.c coords bar 0 0 $pdone 20
597
632
}
598
633
599
634
method _click {cur_w pos} {
600
635
set lno [lindex [split [$cur_w index $pos ] .] 0]
601
- if {$lno eq {}} return
602
- _showcommit $this $lno
636
+ _showcommit $this $cur_w $lno
603
637
}
604
638
605
- method _load_commit {pos} {
606
- set lno [lindex [split [$w_amov index $pos ] .] 0]
607
- set dat [lindex $amov_data $lno ]
639
+ method _load_commit {cur_w cur_d pos} {
640
+ upvar #0 $cur_d line_data
641
+ set lno [lindex [split [$cur_w index $pos ] .] 0]
642
+ set dat [lindex $line_data $lno ]
608
643
if {$dat ne {}} {
609
644
set commit [lindex $dat 0]
610
645
set path [lindex $dat 1]
611
646
_load $this
612
647
}
613
648
}
614
649
615
- method _showcommit {lno} {
650
+ method _showcommit {cur_w lno} {
616
651
global repo_config
617
652
618
653
if {$highlight_commit ne {}} {
@@ -621,10 +656,17 @@ method _showcommit {lno} {
621
656
}
622
657
}
623
658
659
+ if {$cur_w eq $w_amov } {
660
+ set dat [lindex $amov_data $lno ]
661
+ set highlight_column $w_amov
662
+ } else {
663
+ set dat [lindex $asim_data $lno ]
664
+ set highlight_column $w_asim
665
+ }
666
+
624
667
$w_cviewer conf -state normal
625
668
$w_cviewer delete 0.0 end
626
669
627
- set dat [lindex $amov_data $lno ]
628
670
if {$dat eq {}} {
629
671
set cmit {}
630
672
$w_cviewer insert end " Loading annotation..." still_loading
@@ -724,7 +766,11 @@ method _copycommit {} {
724
766
725
767
method _show_tooltip {cur_w pos} {
726
768
set lno [lindex [split [$cur_w index $pos ] .] 0]
727
- set dat [lindex $amov_data $lno ]
769
+ if {$cur_w eq $w_amov } {
770
+ set dat [lindex $amov_data $lno ]
771
+ } else {
772
+ set dat [lindex $asim_data $lno ]
773
+ }
728
774
if {$dat eq {}} {
729
775
_hide_tooltip $this
730
776
return
@@ -758,7 +804,11 @@ method _open_tooltip {cur_w} {
758
804
[expr {$pos_x - [winfo rootx $cur_w ]}] \
759
805
[expr {$pos_y - [winfo rooty $cur_w ]}]] ,]
760
806
set lno [lindex [split [$cur_w index $pos ] .] 0]
761
- set dat [lindex $amov_data $lno ]
807
+ if {$cur_w eq $w_amov } {
808
+ set dat [lindex $amov_data $lno ]
809
+ } else {
810
+ set dat [lindex $asim_data $lno ]
811
+ }
762
812
set cmit [lindex $dat 0]
763
813
set file [lindex $dat 1]
764
814
0 commit comments