45
field total_lines 0 ; # total length of file
46
field blame_lines 0 ; # number of lines computed
47
field have_commit ; # array commit -> 1
48
-field line_commit ; # array line -> sha1 commit
49
-field line_file ; # array line -> file name
48
+field line_data ; # list of {commit origfile origline}
49
50
field r_commit ; # commit currently being parsed
51
field r_orig_line ; # original line number
313
set total_lines 0
314
set blame_lines 0
315
array unset have_commit
317
- array unset line_commit
318
- array unset line_file
316
}
317
318
if {[winfo exists $w.status.c]} {
335
}
336
lappend history [list $commit $path]
337
338
+ # Index 0 is always empty. There is never line 0 as
339
+ # we use only 1 based lines, as that matches both with
340
+ # git-blame output and with Tk's text widget.
341
+ #
342
+ set line_data [list [list]]
343
+
344
set status "Loading $commit:[escape_path $path]..."
345
$w_path conf -text [escape_path $path]
346
if {$commit eq {}} {
404
while {[gets $fd line] >= 0} {
405
regsub "\r\$" $line {} line
406
incr total_lines
407
+ lappend line_data {}
408
409
if {$total_lines > 1} {
410
foreach i $w_columns {$i insert end "\n"}
503
504
set first_lno $lno
505
while {
502
- ![catch {set ncmit $line_commit([expr {$first_lno - 1}])}]
503
- && ![catch {set nfile $line_file([expr {$first_lno - 1}])}]
504
- && $ncmit eq $cmit
505
- && $nfile eq $file
506
+ $first_lno > 1
507
+ && $cmit eq [lindex $line_data [expr {$first_lno - 1}] 0]
508
+ && $file eq [lindex $line_data [expr {$first_lno - 1}] 1]
509
} {
510
incr first_lno -1
511
}
512
513
while {$n > 0} {
514
set lno_e "$lno.0 lineend + 1c"
512
- if {![catch {set g g$line_commit($lno)}]} {
515
+ if {[lindex $line_data $lno] ne {}} {
516
+ set g [lindex $line_data $lno 0]
517
foreach i $w_columns {
518
$i tag remove g$g $lno.0 $lno_e
519
}
520
}
517
-
518
- set line_commit($lno) $cmit
519
- set line_file($lno) $file
521
+ lset line_data $lno [list $cmit $file]
522
523
$w_cgrp delete $lno.0 "$lno.0 lineend"
524
if {$lno == $first_lno} {
548
}
549
550
while {
549
- ![catch {set ncmit $line_commit($lno)}]
550
- && ![catch {set nfile $line_file($lno)}]
551
- && $ncmit eq $cmit
552
- && $nfile eq $file
551
+ $cmit eq [lindex $line_data $lno 0]
552
+ && $file eq [lindex $line_data $lno 1]
553
} {
554
$w_cgrp delete $lno.0 "$lno.0 lineend"
555
599
600
method _load_commit {pos} {
601
set lno [lindex [split [$w_cgrp index $pos] .] 0]
602
- if {[catch {set cmit $line_commit($lno)}]} return
603
- if {[catch {set file $line_file($lno) }]} return
604
-
605
- set commit $cmit
606
- set path $file
607
- _load $this
602
+ set dat [lindex $line_data $lno]
603
+ if {$dat ne {}} {
604
+ set commit [lindex $dat 0]
605
+ set path [lindex $dat 1]
606
+ _load $this
607
+ }
608
}
609
610
method _showcommit {lno} {
618
619
$w_cmit conf -state normal
620
$w_cmit delete 0.0 end
621
- if {[catch {set cmit $line_commit($lno)}]} {
621
+
622
+ set dat [lindex $line_data $lno]
623
+ if {$dat eq {}} {
624
set cmit {}
625
$w_cmit insert end "Loading annotation..."
626
} else {
627
+ set cmit [lindex $dat 0]
628
+ set file [lindex $dat 1]
629
+
630
set old_bgcolor [$w_file tag cget g$cmit -background]
631
foreach i $w_columns {
632
$i tag conf g$cmit -background $active_color
687
$w_cmit insert end "$committer_name $committer_email" header_val
688
$w_cmit insert end "$committer_time\n" header_val
689
685
- if {$line_file($lno) ne $path} {
690
+ if {$file ne $path} {
691
$w_cmit insert end "Original File:\t" header_key
687
- $w_cmit insert end "[escape_path $line_file($lno)]\n" header_val
692
+ $w_cmit insert end "[escape_path $file]\n" header_val
693
}
694
695
$w_cmit insert end "\n$msg"
707
method _copycommit {} {
708
set pos @$::cursorX,$::cursorY
709
set lno [lindex [split [$::cursorW index $pos] .] 0]
705
- if {![catch {set commit $line_commit($lno)}]} {
710
+ set dat [lindex $line_data $lno]
711
+ if {$dat ne {}} {
712
clipboard clear
713
clipboard append \
714
-format STRING \
715
-type STRING \
710
- -- $commit
716
+ -- [lindex $dat 0]
717
}
718
}
719
720
method _show_tooltip {cur_w pos} {
721
set lno [lindex [split [$cur_w index $pos] .] 0]
716
- if {[catch {set cmit $line_commit($lno)}]} {
722
+ set dat [lindex $line_data $lno]
723
+ if {$dat eq {}} {
724
_hide_tooltip $this
725
return
726
}
727
+ set cmit [lindex $dat 0]
728
729
if {$cmit eq $highlight_commit} {
730
_hide_tooltip $this
753
[expr {$pos_x - [winfo rootx $cur_w]}] \
754
[expr {$pos_y - [winfo rooty $cur_w]}]] ,]
755
set lno [lindex [split [$cur_w index $pos] .] 0]
748
- set cmit $line_commit($lno)
756
+ set dat [lindex $line_data $lno]
757
+ set cmit [lindex $dat 0]
758
+ set file [lindex $dat 1]
759
760
set author_name {}
761
set author_email {}
785
$author_name $author_email $author_time
786
$summary"
787
778
- set file $line_file($lno)
788
if {$file ne $path} {
789
append tooltip_text "
790