Git 1.6.6.3
[gitweb.git] / git-gui / lib / diff.tcl
index abe502d97104cb62bed308b0f5025c9d014834fb..066755b864b587e073a820aa2eb729a6c930d7b0 100644 (file)
@@ -16,7 +16,7 @@ proc clear_diff {} {
        $ui_workdir tag remove in_diff 0.0 end
 }
 
-proc reshow_diff {} {
+proc reshow_diff {{after {}}} {
        global file_states file_lists
        global current_diff_path current_diff_side
        global ui_diff
@@ -30,13 +30,13 @@ proc reshow_diff {} {
                || [lsearch -sorted -exact $file_lists($current_diff_side) $p] == -1} {
 
                if {[find_next_diff $current_diff_side $p {} {[^O]}]} {
-                       next_diff
+                       next_diff $after
                } else {
                        clear_diff
                }
        } else {
                set save_pos [lindex [$ui_diff yview] 0]
-               show_diff $p $current_diff_side {} $save_pos
+               show_diff $p $current_diff_side {} $save_pos $after
        }
 }
 
@@ -51,11 +51,16 @@ proc force_diff_encoding {enc} {
 
 proc handle_empty_diff {} {
        global current_diff_path file_states file_lists
+       global diff_empty_count
 
        set path $current_diff_path
        set s $file_states($path)
        if {[lindex $s 0] ne {_M}} return
 
+       # Prevent infinite rescan loops
+       incr diff_empty_count
+       if {$diff_empty_count > 1} return
+
        info_popup [mc "No differences detected.
 
 %s has no changes.
@@ -117,22 +122,22 @@ proc show_unmerged_diff {cont_info} {
        if {$merge_stages(2) eq {}} {
                set is_conflict_diff 1
                lappend current_diff_queue \
-                       [list "LOCAL: deleted\nREMOTE:\n" d======= \
+                       [list [mc "LOCAL: deleted\nREMOTE:\n"] d======= \
                            [list ":1:$current_diff_path" ":3:$current_diff_path"]]
        } elseif {$merge_stages(3) eq {}} {
                set is_conflict_diff 1
                lappend current_diff_queue \
-                       [list "REMOTE: deleted\nLOCAL:\n" d======= \
+                       [list [mc "REMOTE: deleted\nLOCAL:\n"] d======= \
                            [list ":1:$current_diff_path" ":2:$current_diff_path"]]
        } elseif {[lindex $merge_stages(1) 0] eq {120000}
                || [lindex $merge_stages(2) 0] eq {120000}
                || [lindex $merge_stages(3) 0] eq {120000}} {
                set is_conflict_diff 1
                lappend current_diff_queue \
-                       [list "LOCAL:\n" d======= \
+                       [list [mc "LOCAL:\n"] d======= \
                            [list ":1:$current_diff_path" ":2:$current_diff_path"]]
                lappend current_diff_queue \
-                       [list "REMOTE:\n" d======= \
+                       [list [mc "REMOTE:\n"] d======= \
                            [list ":1:$current_diff_path" ":3:$current_diff_path"]]
        } else {
                start_show_diff $cont_info
@@ -164,7 +169,7 @@ proc show_other_diff {path w m cont_info} {
        # - Git won't give us the diff, there's nothing to compare to!
        #
        if {$m eq {_O}} {
-               set max_sz [expr {128 * 1024}]
+               set max_sz 100000
                set type unknown
                if {[catch {
                                set type [file type $path]
@@ -218,17 +223,17 @@ proc show_other_diff {path w m cont_info} {
                                d_@
                } else {
                        if {$sz > $max_sz} {
-                               $ui_diff insert end \
-"* Untracked file is $sz bytes.
-* Showing only first $max_sz bytes.
-" d_@
+                               $ui_diff insert end [mc \
+"* Untracked file is %d bytes.
+* Showing only first %d bytes.
+" $sz $max_sz] d_@
                        }
                        $ui_diff insert end $content
                        if {$sz > $max_sz} {
-                               $ui_diff insert end "
-* Untracked file clipped here by [appname].
+                               $ui_diff insert end [mc "
+* Untracked file clipped here by %s.
 * To see the entire file, use an external editor.
-" d_@
+" [appname]] d_@
                        }
                }
                $ui_diff conf -state disabled
@@ -250,7 +255,7 @@ proc show_other_diff {path w m cont_info} {
 
 proc start_show_diff {cont_info {add_opts {}}} {
        global file_states file_lists
-       global is_3way_diff diff_active repo_config
+       global is_3way_diff is_submodule_diff diff_active repo_config
        global ui_diff ui_index ui_workdir
        global current_diff_path current_diff_side current_diff_header
 
@@ -260,6 +265,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
        set s $file_states($path)
        set m [lindex $s 0]
        set is_3way_diff 0
+       set is_submodule_diff 0
        set diff_active 1
        set current_diff_header {}
 
@@ -290,6 +296,16 @@ proc start_show_diff {cont_info {add_opts {}}} {
                lappend cmd $path
        }
 
+       if {[string match {160000 *} [lindex $s 2]]
+        || [string match {160000 *} [lindex $s 3]]} {
+               set is_submodule_diff 1
+               if {$w eq $ui_index} {
+                       set cmd [list submodule summary --cached -- $path]
+               } else {
+                       set cmd [list submodule summary --files -- $path]
+               }
+       }
+
        if {[catch {set fd [eval git_read --nice $cmd]} err]} {
                set diff_active 0
                unlock_index
@@ -307,9 +323,10 @@ proc start_show_diff {cont_info {add_opts {}}} {
 }
 
 proc read_diff {fd cont_info} {
-       global ui_diff diff_active
+       global ui_diff diff_active is_submodule_diff
        global is_3way_diff is_conflict_diff current_diff_header
        global current_diff_queue
+       global diff_empty_count
 
        $ui_diff conf -state normal
        while {[gets $fd line] >= 0} {
@@ -368,6 +385,23 @@ proc read_diff {fd cont_info} {
                                set tags {}
                        }
                        }
+               } elseif {$is_submodule_diff} {
+                       if {$line == ""} continue
+                       if {[regexp {^\* } $line]} {
+                               set line [string replace $line 0 1 {Submodule }]
+                               set tags d_@
+                       } else {
+                               set op [string range $line 0 2]
+                               switch -- $op {
+                               {  <} {set tags d_-}
+                               {  >} {set tags d_+}
+                               {  W} {set tags {}}
+                               default {
+                                       puts "error: Unhandled submodule diff marker: {$op}"
+                                       set tags {}
+                               }
+                               }
+                       }
                } else {
                        set op [string index $line 0]
                        switch -- $op {
@@ -377,7 +411,6 @@ proc read_diff {fd cont_info} {
                        {+} {
                                if {[regexp {^\+([<>]{7} |={7})} $line _g op]} {
                                        set is_conflict_diff 1
-                                       set line [string replace $line 0 0 { }]
                                        set tags d$op
                                } else {
                                        set tags d_+
@@ -416,7 +449,10 @@ proc read_diff {fd cont_info} {
 
                if {[$ui_diff index end] eq {2.0}} {
                        handle_empty_diff
+               } else {
+                       set diff_empty_count 0
                }
+
                set callback [lindex $cont_info 1]
                if {$callback ne {}} {
                        eval $callback
@@ -628,6 +664,7 @@ proc apply_line {x y} {
                }
                set i_l $next_l
        }
+       set patch "$patch$pre_context"
        set patch "@@ -$hln,$n +$hln,[eval expr $n $sign 1] @@\n$patch"
 
        if {[catch {