@matheusbsbs / matheus-bagliano / commits / fec4a78590
Fork 0

git-gui: Improve diff --cc viewing for unmerged files.

Now that we are using 'git diff' to display unmerged working directory files we are getting 'diff --cc' output rather than 'diff --combined' output. Further the markers in the first two columns actually make sense here, we shouldn't attempt to rewrite them to something else. I've added 'diff --cc *' to the skip list in our diff viewer, as that particular line is not very interesting to display. I've completely refactored how we perform detection of the state of a line during diff parsing; we now report an error message if we don't understand the particular state of any given line. This way we know if we aren't tagging something we maybe should have tagged in the UI. I've also added special display of the standard conflict hunk markers (<<<<<<<, =======, >>>>>>>). These are formatted without a patch op as the patch op is always '+' or '++' (meaning the line has been added relative to the committed state) and are displayed in orange bold text, sort of like the @@ or @@@ marker line is at the start of each hunk. In a 3 way merge diff hunks which came from our HEAD are shown with a azure2 background, and hunks which came from the incoming MERGE_HEAD are displayed with a 'light goldenrod yellow' background. This makes the two different hunks clearly visible within the file. Hunks which are ++ or -- (added or deleted relative to both parents) are shown without any background at all. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 21, 2007 at 13:12 UTC fec4a78590229aab648e37195a071e3aae02bfe0
1 file changed +64 -24
git-gui.sh
+64 -24
@@ -693,6 +693,7 @@ proc read_diff {fd} {
693 # -- Cleanup uninteresting diff header lines.
694 #
695 if {[string match {diff --git *} $line]} continue
696 + if {[string match {diff --cc *} $line]} continue
697 if {[string match {diff --combined *} $line]} continue
698 if {[string match {--- *} $line]} continue
699 if {[string match {+++ *} $line]} continue
@@ -704,27 +705,49 @@ proc read_diff {fd} {
705 #
706 if {[string match {@@@ *} $line]} {set is_3way_diff 1}
707
707 - # -- Reformat a 3 way diff, 'cause its too weird.
708 - #
709 - if {$is_3way_diff} {
708 + if {[string match {index *} $line]} {
709 + set tags {}
710 + } elseif {$is_3way_diff} {
711 set op [string range $line 0 1]
712 switch -- $op {
713 + { } {set tags {}}
714 {@@} {set tags d_@}
713 - {++} {set tags d_+ ; set op { +}}
714 - {--} {set tags d_- ; set op { -}}
715 - { +} {set tags d_++; set op {++}}
716 - { -} {set tags d_--; set op {--}}
717 - {+ } {set tags d_-+; set op {-+}}
718 - {- } {set tags d_+-; set op {+-}}
719 - default {set tags {}}
715 + { +} {set tags d_s+}
716 + { -} {set tags d_s-}
717 + {+ } {set tags d_+s}
718 + {- } {set tags d_-s}
719 + {--} {set tags d_--}
720 + {++} {
721 + if {[regexp {^\+\+([<>]{7} |={7})} $line _g op]} {
722 + set line [string replace $line 0 1 { }]
723 + set tags d$op
724 + } else {
725 + set tags d_++
726 + }
727 + }
728 + default {
729 + puts "error: Unhandled 3 way diff marker: {$op}"
730 + set tags {}
731 + }
732 }
721 - set line [string replace $line 0 1 $op]
733 } else {
723 - switch -- [string index $line 0] {
724 - @ {set tags d_@}
725 - + {set tags d_+}
726 - - {set tags d_-}
727 - default {set tags {}}
734 + set op [string index $line 0]
735 + switch -- $op {
736 + { } {set tags {}}
737 + {@} {set tags d_@}
738 + {-} {set tags d_-}
739 + {+} {
740 + if {[regexp {^\+([<>]{7} |={7})} $line _g op]} {
741 + set line [string replace $line 0 0 { }]
742 + set tags d$op
743 + } else {
744 + set tags d_+
745 + }
746 + }
747 + default {
748 + puts "error: Unhandled 2 way diff marker: {$op}"
749 + set tags {}
750 + }
751 }
752 }
753 $ui_diff insert end $line $tags
@@ -3856,16 +3879,33 @@ pack .vpane.lower.diff.header -side top -fill x
3879 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3880
3881 $ui_diff tag conf d_@ -font font_diffbold
3859 -$ui_diff tag conf d_+ -foreground blue
3860 -$ui_diff tag conf d_- -foreground red
3861 -$ui_diff tag conf d_++ -foreground {#00a000}
3862 -$ui_diff tag conf d_-- -foreground {#a000a0}
3863 -$ui_diff tag conf d_+- \
3864 - -foreground red \
3865 - -background {light goldenrod yellow}
3866 -$ui_diff tag conf d_-+ \
3882 +$ui_diff tag conf d_+ -foreground blue
3883 +$ui_diff tag conf d_- -foreground red
3884 +
3885 +$ui_diff tag conf d_++ -foreground blue
3886 +$ui_diff tag conf d_-- -foreground red
3887 +$ui_diff tag conf d_+s \
3888 -foreground blue \
3889 -background azure2
3890 +$ui_diff tag conf d_-s \
3891 + -foreground red \
3892 + -background azure2
3893 +$ui_diff tag conf d_s+ \
3894 + -foreground blue \
3895 + -background {light goldenrod yellow}
3896 +$ui_diff tag conf d_s- \
3897 + -foreground red \
3898 + -background {light goldenrod yellow}
3899 +
3900 +$ui_diff tag conf d<<<<<<< \
3901 + -foreground orange \
3902 + -font font_diffbold
3903 +$ui_diff tag conf d======= \
3904 + -foreground orange \
3905 + -font font_diffbold
3906 +$ui_diff tag conf d>>>>>>> \
3907 + -foreground orange \
3908 + -font font_diffbold
3909
3910 # -- Diff Body Context Menu
3911 #