@matheusbsbs / matheus-bagliano / commits / 38dbe273ff
Fork 0

git-gui: Refactored diff line display formatting logic.

The tags used for diff formatting (which I inherited from gitool) just didn't make a whole lot of sense, especially if you wanted to try to match them to the diff output you were seeing on screen. It did not help that the diff-index -c output's first two columns are also munged to make the diff output more user friendly. So this is a large refactoring of the tags used for diff display. Now our tag names match what we put in the left column of each line, which makes it easier to correlate presentation and implementation. I removed bold font usage from everything except the hunk headers as I really did not like the way bold font caused column alignments to become out of whack within the diff viewer. It also drew attention to the parts of the file which were identically changed in both the index and in the working directory, yet these are usually the parts I find myself caring the least about. So its very counter-intuitive. Lines which are changed differently by both the index and the working directory are now shown with background colors which span the entire line, making these lines easier to pick out of the diff. In general these are the lines that appear to be more interesting to me when looking at the 3-way diff as they are the ones which contain recent and quite different changes. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 19, 2006 at 02:46 UTC 38dbe273ffb86d8dc5c90403c27c561e683ade4a
1 file changed +43 -37
git-gui
+43 -37
@@ -544,7 +544,7 @@ files list, to prevent possible confusion.
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,7 +565,7 @@ proc show_diff {path {w {}} {lno {}}} {
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,51 +620,52 @@ proc show_diff {path {w {}} {lno {}}} {
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
@@ -2987,12 +2988,17 @@ pack $ui_diff -side left -fill both -expand 1
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 #