Code

git-gui: Remove combined diff showing behavior.
authorShawn O. Pearce <spearce@spearce.org>
Sun, 21 Jan 2007 16:54:16 +0000 (11:54 -0500)
committerShawn O. Pearce <spearce@spearce.org>
Mon, 22 Jan 2007 03:47:53 +0000 (22:47 -0500)
The combined diff format can be very confusing, especially to new users
who may not even be familiar with a standard two way diff format.  So
for files which are already staged for commit and which are modifed in
the working directory we should show two different diffs, depending on
which side the user clicked on.

If the user clicks on the "Changes To Be Committed" side then we should
show them the PARENT<->index difference.  This is the set of changes they
will actually commit.

If the user clicks on the "Changed But Not Updated" side we should show
them the index<->working directory difference.  This is the set of changes
which will not be committed, as they have not been staged into the index.
This is especially useful when merging, as the "Changed But Not Updated"
files are the ones that need merge conflict resolution, and the diff here
is the conflict hunks and/or any evil merge created by the user.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
git-gui.sh

index 0bfd56051dc81d37816f149d37f385ad91d5cd96..64c2ae30e7c90b01683567637f5b765e2684b981 100755 (executable)
@@ -556,13 +556,14 @@ proc clear_diff {} {
 }
 
 proc reshow_diff {} {
-       global current_diff_path ui_status_value file_states
+       global ui_status_value file_states
+       global current_diff_path current_diff_side
 
        if {$current_diff_path eq {}
                || [catch {set s $file_states($current_diff_path)}]} {
                clear_diff
        } else {
-               show_diff $current_diff_path
+               show_diff $current_diff_path $current_diff_side
        }
 }
 
@@ -595,10 +596,11 @@ files list, to prevent possible confusion.
        display_file $path __
 }
 
-proc show_diff {path {w {}} {lno {}}} {
+proc show_diff {path w {lno {}}} {
        global file_states file_lists
        global is_3way_diff diff_active repo_config
-       global ui_diff current_diff_path ui_status_value
+       global ui_diff ui_status_value ui_index ui_workdir
+       global current_diff_path current_diff_side
 
        if {$diff_active || ![lock_index read]} return
 
@@ -621,20 +623,12 @@ proc show_diff {path {w {}} {lno {}}} {
        set is_3way_diff 0
        set diff_active 1
        set current_diff_path $path
+       set current_diff_side $w
        set ui_status_value "Loading diff of [escape_path $path]..."
 
-       set cmd [list | git diff-index]
-       lappend cmd --no-color
-       if {$repo_config(gui.diffcontext) > 0} {
-               lappend cmd "-U$repo_config(gui.diffcontext)"
-       }
-       lappend cmd -p
-
-       switch $m {
-       MM {
-               lappend cmd -c
-       }
-       _O {
+       # - Git won't give us the diff, there's nothing to compare to!
+       #
+       if {$m eq {_O}} {
                if {[catch {
                                set fd [open $path r]
                                set content [read $fd]
@@ -654,9 +648,23 @@ proc show_diff {path {w {}} {lno {}}} {
                set ui_status_value {Ready.}
                return
        }
+
+       set cmd [list | git]
+       if {$w eq $ui_index} {
+               lappend cmd diff-index
+               lappend cmd --cached
+       } elseif {$w eq $ui_workdir} {
+               lappend cmd diff-files
        }
 
-       lappend cmd [PARENT]
+       lappend cmd -p
+       lappend cmd --no-color
+       if {$repo_config(gui.diffcontext) > 0} {
+               lappend cmd "-U$repo_config(gui.diffcontext)"
+       }
+       if {$w eq $ui_index} {
+               lappend cmd [PARENT]
+       }
        lappend cmd --
        lappend cmd $path