]> rtime.felk.cvut.cz Git - sojka/git-gui.git/commitdiff
git-gui: use textconv filter for diff and blame
authorClément Poulain <clement.poulain@ensimag.imag.fr>
Fri, 30 Jul 2010 08:11:02 +0000 (09:11 +0100)
committerPat Thoyts <patthoyts@users.sourceforge.net>
Fri, 30 Jul 2010 09:05:27 +0000 (10:05 +0100)
Create a checkbox "Use Textconv For Diffs and Blame" in git-gui options.
If checked and if the driver for the concerned file exists, git-gui calls diff
and blame with --textconv option

Signed-off-by: Clément Poulain <clement.poulain@ensimag.imag.fr>
Signed-off-by: Diane Gasselin <diane.gasselin@ensimag.imag.fr>
Signed-off-by: Axel Bonnet <axel.bonnet@ensimag.imag.fr>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
git-gui.sh
lib/blame.tcl
lib/diff.tcl
lib/option.tcl

index ed8bbe180446b136a6584f4a770ba378e469896f..88b3f8a0865170b98dbcea577d7e223627944b61 100755 (executable)
@@ -269,6 +269,17 @@ proc is_config_true {name} {
        }
 }
 
+proc is_config_false {name} {
+       global repo_config
+       if {[catch {set v $repo_config($name)}]} {
+               return 0
+       } elseif {$v eq {false} || $v eq {0} || $v eq {no}} {
+               return 1
+       } else {
+               return 0
+       }
+}
+
 proc get_config {name} {
        global repo_config
        if {[catch {set v $repo_config($name)}]} {
@@ -785,6 +796,7 @@ set default_config(user.email) {}
 
 set default_config(gui.encoding) [encoding system]
 set default_config(gui.matchtrackingbranch) false
+set default_config(gui.textconv) true
 set default_config(gui.pruneduringfetch) false
 set default_config(gui.trustmtime) false
 set default_config(gui.fastcopyblame) false
@@ -3411,6 +3423,19 @@ lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
 $ctxmsm add separator
 create_common_diff_popup $ctxmsm
 
+proc has_textconv {path} {
+       if {[is_config_false gui.textconv]} {
+               return 0
+       }
+       set filter [gitattr $path diff set]
+       set textconv [get_config [join [list diff $filter textconv] .]]
+       if {$filter ne {set} && $textconv ne {}} {
+               return 1
+       } else {
+               return 0
+       }
+}
+
 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
        global current_diff_path file_states
        set ::cursorX $x
@@ -3446,7 +3471,8 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
                        || {__} eq $state
                        || {_O} eq $state
                        || {_T} eq $state
-                       || {T_} eq $state} {
+                       || {T_} eq $state
+                       || [has_textconv $current_diff_path]} {
                        set s disabled
                } else {
                        set s normal
index 786b50b8c2b6f877d1d1a3a86d27368281ec2ae8..2137ec9684d0acdb386e6b50e1b41aa7705c9746 100644 (file)
@@ -449,11 +449,28 @@ method _load {jump} {
 
        $status show [mc "Reading %s..." "$commit:[escape_path $path]"]
        $w_path conf -text [escape_path $path]
+
+       set do_textconv 0
+       if {![is_config_false gui.textconv] && [git-version >= 1.7.2]} {
+               set filter [gitattr $path diff set]
+               set textconv [get_config [join [list diff $filter textconv] .]]
+               if {$filter ne {set} && $textconv ne {}} {
+                       set do_textconv 1
+               }
+       }
        if {$commit eq {}} {
-               set fd [open $path r]
+               if {$do_textconv ne 0} {
+                       set fd [open |[list $textconv $path] r]
+               } else {
+                       set fd [open $path r]
+               }
                fconfigure $fd -eofchar {}
        } else {
-               set fd [git_read cat-file blob "$commit:$path"]
+               if {$do_textconv ne 0} {
+                       set fd [git_read cat-file --textconv "$commit:$path"]
+               } else {
+                       set fd [git_read cat-file blob "$commit:$path"]
+               }
        }
        fconfigure $fd \
                -blocking 0 \
index ec8c11eeb7912e2e49e48f467ffc27fd9fc5f919..c628750276303fca620c9292463c4c59690c764f 100644 (file)
@@ -55,7 +55,7 @@ proc handle_empty_diff {} {
 
        set path $current_diff_path
        set s $file_states($path)
-       if {[lindex $s 0] ne {_M}} return
+       if {[lindex $s 0] ne {_M} || [has_textconv $path]} return
 
        # Prevent infinite rescan loops
        incr diff_empty_count
@@ -280,6 +280,9 @@ proc start_show_diff {cont_info {add_opts {}}} {
                        lappend cmd diff-files
                }
        }
+       if {![is_config_false gui.textconv] && [git-version >= 1.6.1]} {
+               lappend cmd --textconv
+       }
 
        if {[string match {160000 *} [lindex $s 2]]
         || [string match {160000 *} [lindex $s 3]]} {
index d4c5e45c8a7ade900753cb7eb5caf977e6e4ae2a..3807c8d28324a277204db9191e99ddb856041c22 100644 (file)
@@ -148,6 +148,7 @@ proc do_options {} {
                {b gui.trustmtime  {mc "Trust File Modification Timestamps"}}
                {b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
                {b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
+               {b gui.textconv {mc "Use Textconv For Diffs and Blames"}}
                {b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
                {i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
                {i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}