544
545
proc show_diff {path {w {}} {lno {}}} {
546
global file_states file_lists
547
- global diff_3way diff_active repo_config
547
+ global is_3way_diff diff_active repo_config
548
global ui_diff current_diff ui_status_value
549
550
if {$diff_active || ![lock_index read]} return
565
566
set s $file_states($path)
567
set m [lindex $s 0]
568
- set diff_3way 0
568
+ set is_3way_diff 0
569
set diff_active 1
570
set current_diff $path
571
set ui_status_value "Loading diff of [escape_path $path]..."
620
}
621
622
proc read_diff {fd} {
623
- global ui_diff ui_status_value diff_3way diff_active
623
+ global ui_diff ui_status_value is_3way_diff diff_active
624
global repo_config
625
626
+ $ui_diff conf -state normal
627
while {[gets $fd line] >= 0} {
627
- if {[string match {diff --git *} $line]} continue
628
+ # -- Cleanup uninteresting diff header lines.
629
+ #
630
+ if {[string match {diff --git *} $line]} continue
631
if {[string match {diff --combined *} $line]} continue
629
- if {[string match {--- *} $line]} continue
630
- if {[string match {+++ *} $line]} continue
632
+ if {[string match {--- *} $line]} continue
633
+ if {[string match {+++ *} $line]} continue
634
if {$line eq {deleted file mode 120000}} {
635
set line "deleted symlink"
636
}
634
- if {[string match index* $line]} {
635
- if {[string first , $line] >= 0} {
636
- set diff_3way 1
637
- }
638
- }
637
640
- $ui_diff conf -state normal
641
- if {!$diff_3way} {
642
- set x [string index $line 0]
643
- switch -- $x {
644
- "@" {set tags da}
645
- "+" {set tags dp}
646
- "-" {set tags dm}
638
+ # -- Automatically detect if this is a 3 way diff.
639
+ #
640
+ if {[string match {@@@ *} $line]} {set is_3way_diff 1}
641
+
642
+ # -- Reformat a 3 way diff, 'cause its too weird.
643
+ #
644
+ if {$is_3way_diff} {
645
+ set op [string range $line 0 1]
646
+ switch -- $op {
647
+ {@@} {set tags d_@}
648
+ {++} {set tags d_+ ; set op { +}}
649
+ {--} {set tags d_- ; set op { -}}
650
+ { +} {set tags d_++; set op {++}}
651
+ { -} {set tags d_--; set op {--}}
652
+ {+ } {set tags d_-+; set op {-+}}
653
+ {- } {set tags d_+-; set op {+-}}
654
default {set tags {}}
655
}
656
+ set line [string replace $line 0 1 $op]
657
} else {
650
- set x [string range $line 0 1]
651
- switch -- $x {
652
- default {set tags {}}
653
- "@@" {set tags da}
654
- "++" {set tags dp; set x " +"}
655
- " +" {set tags {di bold}; set x "++"}
656
- "+ " {set tags dni; set x "-+"}
657
- "--" {set tags dm; set x " -"}
658
- " -" {set tags {dm bold}; set x "--"}
659
- "- " {set tags di; set x "+-"}
658
+ switch -- [string index $line 0] {
659
+ @ {set tags d_@}
660
+ + {set tags d_+}
661
+ - {set tags d_-}
662
default {set tags {}}
663
}
662
- set line [string replace $line 0 1 $x]
664
}
665
$ui_diff insert end $line $tags
665
- $ui_diff insert end "\n"
666
- $ui_diff conf -state disabled
666
+ $ui_diff insert end "\n" $tags
667
}
668
+ $ui_diff conf -state disabled
669
670
if {[eof $fd]} {
671
close $fd
2988
pack .vpane.lower.diff.header -side top -fill x
2989
pack .vpane.lower.diff.body -side bottom -fill both -expand 1
2990
2990
-$ui_diff tag conf dm -foreground red
2991
-$ui_diff tag conf dp -foreground blue
2992
-$ui_diff tag conf di -foreground {#00a000}
2993
-$ui_diff tag conf dni -foreground {#a000a0}
2994
-$ui_diff tag conf da -font font_diffbold
2995
-$ui_diff tag conf bold -font font_diffbold
2991
+$ui_diff tag conf d_@ -font font_diffbold
2992
+$ui_diff tag conf d_+ -foreground blue
2993
+$ui_diff tag conf d_- -foreground red
2994
+$ui_diff tag conf d_++ -foreground {#00a000}
2995
+$ui_diff tag conf d_-- -foreground {#a000a0}
2996
+$ui_diff tag conf d_+- \
2997
+ -foreground red \
2998
+ -background {light goldenrod yellow}
2999
+$ui_diff tag conf d_-+ \
3000
+ -foreground blue \
3001
+ -background azure2
3002
3003
# -- Diff Body Context Menu
3004
#