git-gui: ensure the file in the diff pane is in the list of selected files
[gitweb.git] / lib / diff.tcl
index ec4405567a9b86a9bfd8bf50815b3c9c14e2df40..30bdd691ee0447a0498e0ec06c1bcaa3379c2d3c 100644 (file)
@@ -1,6 +1,19 @@
 # git-gui diff viewer
 # Copyright (C) 2006, 2007 Shawn Pearce
 
+proc apply_tab_size {{firsttab {}}} {
+       global have_tk85 repo_config ui_diff
+
+       set w [font measure font_diff "0"]
+       if {$have_tk85 && $firsttab != 0} {
+               $ui_diff configure -tabs [list [expr {$firsttab * $w}] [expr {($firsttab + $repo_config(gui.tabsize)) * $w}]]
+       } elseif {$have_tk85 || $repo_config(gui.tabsize) != 8} {
+               $ui_diff configure -tabs [expr {$repo_config(gui.tabsize) * $w}]
+       } else {
+               $ui_diff configure -tabs {}
+       }
+}
+
 proc clear_diff {} {
        global ui_diff current_diff_path current_diff_header
        global ui_index ui_workdir
@@ -105,6 +118,8 @@ proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} {
 
        set cont_info [list $scroll_pos $callback]
 
+       apply_tab_size 0
+
        if {[string first {U} $m] >= 0} {
                merge_load_stages $path [list show_unmerged_diff $cont_info]
        } elseif {$m eq {_O}} {
@@ -112,6 +127,9 @@ proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} {
        } else {
                start_show_diff $cont_info
        }
+
+       global current_diff_path selected_paths
+       set selected_paths($current_diff_path) 1
 }
 
 proc show_unmerged_diff {cont_info} {
@@ -287,6 +305,9 @@ proc start_show_diff {cont_info {add_opts {}}} {
        if {$w eq $ui_index} {
                lappend cmd diff-index
                lappend cmd --cached
+               if {[git-version >= "1.7.2"]} {
+                       lappend cmd --ignore-submodules=dirty
+               }
        } elseif {$w eq $ui_workdir} {
                if {[string first {U} $m] >= 0} {
                        lappend cmd diff
@@ -398,7 +419,10 @@ proc read_diff {fd conflict_size cont_info} {
 
                # -- Automatically detect if this is a 3 way diff.
                #
-               if {[string match {@@@ *} $line]} {set is_3way_diff 1}
+               if {[string match {@@@ *} $line]} {
+                       set is_3way_diff 1
+                       apply_tab_size 1
+               }
 
                if {$::current_diff_inheader} {
 
@@ -764,8 +788,15 @@ proc apply_range_or_line {x y} {
                                # context line
                                set ln [$ui_diff get $i_l $next_l]
                                set patch "$patch$pre_context$ln"
-                               set n [expr $n+1]
-                               set m [expr $m+1]
+                               # Skip the "\ No newline at end of
+                               # file". Depending on the locale setting
+                               # we don't know what this line looks
+                               # like exactly. The only thing we do
+                               # know is that it starts with "\ "
+                               if {![string match {\\ *} $ln]} {
+                                       set n [expr $n+1]
+                                       set m [expr $m+1]
+                               }
                                set pre_context {}
                        } elseif {$c1 eq $to_context} {
                                # turn change line into context line