summaryrefslogtreecommitdiff
path: root/git-gui
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2006-11-19 07:46:52 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2006-11-19 07:46:52 (GMT)
commit38dbe273ffb86d8dc5c90403c27c561e683ade4a (patch)
treefed333eea9d471a5de7761dc335d1d3b41ac7014 /git-gui
parent0c70864b8506ea17cc0615ae4ba55b60fed6af58 (diff)
downloadgit-38dbe273ffb86d8dc5c90403c27c561e683ade4a.zip
git-38dbe273ffb86d8dc5c90403c27c561e683ade4a.tar.gz
git-38dbe273ffb86d8dc5c90403c27c561e683ade4a.tar.bz2
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>
Diffstat (limited to 'git-gui')
-rwxr-xr-xgit-gui80
1 files changed, 43 insertions, 37 deletions
diff --git a/git-gui b/git-gui
index 75d1640..a2a76c1 100755
--- a/git-gui
+++ b/git-gui
@@ -544,7 +544,7 @@ files list, to prevent possible confusion.
proc show_diff {path {w {}} {lno {}}} {
global file_states file_lists
- global diff_3way diff_active repo_config
+ global is_3way_diff diff_active repo_config
global ui_diff current_diff ui_status_value
if {$diff_active || ![lock_index read]} return
@@ -565,7 +565,7 @@ proc show_diff {path {w {}} {lno {}}} {
set s $file_states($path)
set m [lindex $s 0]
- set diff_3way 0
+ set is_3way_diff 0
set diff_active 1
set current_diff $path
set ui_status_value "Loading diff of [escape_path $path]..."
@@ -620,51 +620,52 @@ proc show_diff {path {w {}} {lno {}}} {
}
proc read_diff {fd} {
- global ui_diff ui_status_value diff_3way diff_active
+ global ui_diff ui_status_value is_3way_diff diff_active
global repo_config
+ $ui_diff conf -state normal
while {[gets $fd line] >= 0} {
- if {[string match {diff --git *} $line]} continue
+ # -- Cleanup uninteresting diff header lines.
+ #
+ if {[string match {diff --git *} $line]} continue
if {[string match {diff --combined *} $line]} continue
- if {[string match {--- *} $line]} continue
- if {[string match {+++ *} $line]} continue
+ if {[string match {--- *} $line]} continue
+ if {[string match {+++ *} $line]} continue
if {$line eq {deleted file mode 120000}} {
set line "deleted symlink"
}
- if {[string match index* $line]} {
- if {[string first , $line] >= 0} {
- set diff_3way 1
- }
- }
- $ui_diff conf -state normal
- if {!$diff_3way} {
- set x [string index $line 0]
- switch -- $x {
- "@" {set tags da}
- "+" {set tags dp}
- "-" {set tags dm}
+ # -- Automatically detect if this is a 3 way diff.
+ #
+ if {[string match {@@@ *} $line]} {set is_3way_diff 1}
+
+ # -- Reformat a 3 way diff, 'cause its too weird.
+ #
+ if {$is_3way_diff} {
+ set op [string range $line 0 1]
+ switch -- $op {
+ {@@} {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 line [string replace $line 0 1 $op]
} else {
- set x [string range $line 0 1]
- switch -- $x {
- default {set tags {}}
- "@@" {set tags da}
- "++" {set tags dp; set x " +"}
- " +" {set tags {di bold}; set x "++"}
- "+ " {set tags dni; set x "-+"}
- "--" {set tags dm; set x " -"}
- " -" {set tags {dm bold}; set x "--"}
- "- " {set tags di; set x "+-"}
+ switch -- [string index $line 0] {
+ @ {set tags d_@}
+ + {set tags d_+}
+ - {set tags d_-}
default {set tags {}}
}
- set line [string replace $line 0 1 $x]
}
$ui_diff insert end $line $tags
- $ui_diff insert end "\n"
- $ui_diff conf -state disabled
+ $ui_diff insert end "\n" $tags
}
+ $ui_diff conf -state disabled
if {[eof $fd]} {
close $fd
@@ -2987,12 +2988,17 @@ pack $ui_diff -side left -fill both -expand 1
pack .vpane.lower.diff.header -side top -fill x
pack .vpane.lower.diff.body -side bottom -fill both -expand 1
-$ui_diff tag conf dm -foreground red
-$ui_diff tag conf dp -foreground blue
-$ui_diff tag conf di -foreground {#00a000}
-$ui_diff tag conf dni -foreground {#a000a0}
-$ui_diff tag conf da -font font_diffbold
-$ui_diff tag conf bold -font font_diffbold
+$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_-+ \
+ -foreground blue \
+ -background azure2
# -- Diff Body Context Menu
#