@matheusbsbs / matheus-bagliano / commits / 1fbaccad4d
Fork 0

git-gui: use textconv filter for diff and blame

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>

Clément Poulain committed Jul 30, 2010 at 09:11 UTC 1fbaccad4dd8d6a9a893843c73f3e47c4ba8b717
4 files changed +51 -4
git-gui.sh
+27 -1
@@ -269,6 +269,17 @@ proc is_config_true {name} {
269 }
270 }
271
272 +proc is_config_false {name} {
273 + global repo_config
274 + if {[catch {set v $repo_config($name)}]} {
275 + return 0
276 + } elseif {$v eq {false} || $v eq {0} || $v eq {no}} {
277 + return 1
278 + } else {
279 + return 0
280 + }
281 +}
282 +
283 proc get_config {name} {
284 global repo_config
285 if {[catch {set v $repo_config($name)}]} {
@@ -785,6 +796,7 @@ set default_config(user.email) {}
796
797 set default_config(gui.encoding) [encoding system]
798 set default_config(gui.matchtrackingbranch) false
799 +set default_config(gui.textconv) true
800 set default_config(gui.pruneduringfetch) false
801 set default_config(gui.trustmtime) false
802 set default_config(gui.fastcopyblame) false
@@ -3411,6 +3423,19 @@ lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3423 $ctxmsm add separator
3424 create_common_diff_popup $ctxmsm
3425
3426 +proc has_textconv {path} {
3427 + if {[is_config_false gui.textconv]} {
3428 + return 0
3429 + }
3430 + set filter [gitattr $path diff set]
3431 + set textconv [get_config [join [list diff $filter textconv] .]]
3432 + if {$filter ne {set} && $textconv ne {}} {
3433 + return 1
3434 + } else {
3435 + return 0
3436 + }
3437 +}
3438 +
3439 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3440 global current_diff_path file_states
3441 set ::cursorX $x
@@ -3446,7 +3471,8 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3471 || {__} eq $state
3472 || {_O} eq $state
3473 || {_T} eq $state
3449 - || {T_} eq $state} {
3474 + || {T_} eq $state
3475 + || [has_textconv $current_diff_path]} {
3476 set s disabled
3477 } else {
3478 set s normal
lib/blame.tcl
+19 -2
@@ -449,11 +449,28 @@ method _load {jump} {
449
450 $status show [mc "Reading %s..." "$commit:[escape_path $path]"]
451 $w_path conf -text [escape_path $path]
452 +
453 + set do_textconv 0
454 + if {![is_config_false gui.textconv] && [git-version >= 1.7.2]} {
455 + set filter [gitattr $path diff set]
456 + set textconv [get_config [join [list diff $filter textconv] .]]
457 + if {$filter ne {set} && $textconv ne {}} {
458 + set do_textconv 1
459 + }
460 + }
461 if {$commit eq {}} {
453 - set fd [open $path r]
462 + if {$do_textconv ne 0} {
463 + set fd [open |[list $textconv $path] r]
464 + } else {
465 + set fd [open $path r]
466 + }
467 fconfigure $fd -eofchar {}
468 } else {
456 - set fd [git_read cat-file blob "$commit:$path"]
469 + if {$do_textconv ne 0} {
470 + set fd [git_read cat-file --textconv "$commit:$path"]
471 + } else {
472 + set fd [git_read cat-file blob "$commit:$path"]
473 + }
474 }
475 fconfigure $fd \
476 -blocking 0 \
lib/diff.tcl
+4 -1
@@ -55,7 +55,7 @@ proc handle_empty_diff {} {
55
56 set path $current_diff_path
57 set s $file_states($path)
58 - if {[lindex $s 0] ne {_M}} return
58 + if {[lindex $s 0] ne {_M} || [has_textconv $path]} return
59
60 # Prevent infinite rescan loops
61 incr diff_empty_count
@@ -280,6 +280,9 @@ proc start_show_diff {cont_info {add_opts {}}} {
280 lappend cmd diff-files
281 }
282 }
283 + if {![is_config_false gui.textconv] && [git-version >= 1.6.1]} {
284 + lappend cmd --textconv
285 + }
286
287 if {[string match {160000 *} [lindex $s 2]]
288 || [string match {160000 *} [lindex $s 3]]} {
lib/option.tcl
+1
@@ -148,6 +148,7 @@ proc do_options {} {
148 {b gui.trustmtime {mc "Trust File Modification Timestamps"}}
149 {b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
150 {b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
151 + {b gui.textconv {mc "Use Textconv For Diffs and Blames"}}
152 {b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
153 {i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
154 {i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}