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>
This commit is contained in:
Shawn O. Pearce 2007-01-21 13:12:02 -05:00
parent 3b4db3c1a3
commit fec4a78590

View File

@ -693,6 +693,7 @@ proc read_diff {fd} {
# -- Cleanup uninteresting diff header lines.
#
if {[string match {diff --git *} $line]} continue
if {[string match {diff --cc *} $line]} continue
if {[string match {diff --combined *} $line]} continue
if {[string match {--- *} $line]} continue
if {[string match {+++ *} $line]} continue
@ -704,27 +705,49 @@ proc read_diff {fd} {
#
if {[string match {@@@ *} $line]} {set is_3way_diff 1}
# -- Reformat a 3 way diff, 'cause its too weird.
#
if {$is_3way_diff} {
if {[string match {index *} $line]} {
set tags {}
} elseif {$is_3way_diff} {
set op [string range $line 0 1]
switch -- $op {
{ } {set tags {}}
{@@} {set tags d_@}
{++} {set tags d_+ ; set op { +}}
{--} {set tags d_- ; set op { -}}
{ +} {set tags d_++; set op {++}}
{ -} {set tags d_--; set op {--}}
{+ } {set tags d_-+; set op {-+}}
{- } {set tags d_+-; set op {+-}}
default {set tags {}}
{ +} {set tags d_s+}
{ -} {set tags d_s-}
{+ } {set tags d_+s}
{- } {set tags d_-s}
{--} {set tags d_--}
{++} {
if {[regexp {^\+\+([<>]{7} |={7})} $line _g op]} {
set line [string replace $line 0 1 { }]
set tags d$op
} else {
set tags d_++
}
}
default {
puts "error: Unhandled 3 way diff marker: {$op}"
set tags {}
}
}
set line [string replace $line 0 1 $op]
} else {
switch -- [string index $line 0] {
@ {set tags d_@}
+ {set tags d_+}
- {set tags d_-}
default {set tags {}}
set op [string index $line 0]
switch -- $op {
{ } {set tags {}}
{@} {set tags d_@}
{-} {set tags d_-}
{+} {
if {[regexp {^\+([<>]{7} |={7})} $line _g op]} {
set line [string replace $line 0 0 { }]
set tags d$op
} else {
set tags d_+
}
}
default {
puts "error: Unhandled 2 way diff marker: {$op}"
set tags {}
}
}
}
$ui_diff insert end $line $tags
@ -3856,16 +3879,33 @@ pack .vpane.lower.diff.header -side top -fill x
pack .vpane.lower.diff.body -side bottom -fill both -expand 1
$ui_diff tag conf d_@ -font font_diffbold
$ui_diff tag conf d_+ -foreground blue
$ui_diff tag conf d_- -foreground red
$ui_diff tag conf d_++ -foreground {#00a000}
$ui_diff tag conf d_-- -foreground {#a000a0}
$ui_diff tag conf d_+- \
-foreground red \
-background {light goldenrod yellow}
$ui_diff tag conf d_-+ \
$ui_diff tag conf d_+ -foreground blue
$ui_diff tag conf d_- -foreground red
$ui_diff tag conf d_++ -foreground blue
$ui_diff tag conf d_-- -foreground red
$ui_diff tag conf d_+s \
-foreground blue \
-background azure2
$ui_diff tag conf d_-s \
-foreground red \
-background azure2
$ui_diff tag conf d_s+ \
-foreground blue \
-background {light goldenrod yellow}
$ui_diff tag conf d_s- \
-foreground red \
-background {light goldenrod yellow}
$ui_diff tag conf d<<<<<<< \
-foreground orange \
-font font_diffbold
$ui_diff tag conf d======= \
-foreground orange \
-font font_diffbold
$ui_diff tag conf d>>>>>>> \
-foreground orange \
-font font_diffbold
# -- Diff Body Context Menu
#