Skip to content

Commit 1fbacca

Browse files
Clément Poulainpatthoyts
authored andcommitted
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 <[email protected]> Signed-off-by: Diane Gasselin <[email protected]> Signed-off-by: Axel Bonnet <[email protected]> Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Pat Thoyts <[email protected]>
1 parent 8512354 commit 1fbacca

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

git-gui.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ proc is_config_true {name} {
269269
}
270270
}
271271

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+
272283
proc get_config {name} {
273284
global repo_config
274285
if {[catch {set v $repo_config($name)}]} {
@@ -785,6 +796,7 @@ set default_config(user.email) {}
785796
786797
set default_config(gui.encoding) [encoding system]
787798
set default_config(gui.matchtrackingbranch) false
799+
set default_config(gui.textconv) true
788800
set default_config(gui.pruneduringfetch) false
789801
set default_config(gui.trustmtime) false
790802
set default_config(gui.fastcopyblame) false
@@ -3411,6 +3423,19 @@ lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
34113423
$ctxmsm add separator
34123424
create_common_diff_popup $ctxmsm
34133425
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+
34143439
proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
34153440
global current_diff_path file_states
34163441
set ::cursorX $x
@@ -3446,7 +3471,8 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
34463471
|| {__} eq $state
34473472
|| {_O} eq $state
34483473
|| {_T} eq $state
3449-
|| {T_} eq $state} {
3474+
|| {T_} eq $state
3475+
|| [has_textconv $current_diff_path]} {
34503476
set s disabled
34513477
} else {
34523478
set s normal

lib/blame.tcl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,28 @@ method _load {jump} {
449449

450450
$status show [mc "Reading %s..." "$commit:[escape_path $path]"]
451451
$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+
}
452461
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+
}
454467
fconfigure $fd -eofchar {}
455468
} 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+
}
457474
}
458475
fconfigure $fd \
459476
-blocking 0 \

lib/diff.tcl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ proc handle_empty_diff {} {
5555

5656
set path $current_diff_path
5757
set s $file_states($path)
58-
if {[lindex $s 0] ne {_M}} return
58+
if {[lindex $s 0] ne {_M} || [has_textconv $path]} return
5959

6060
# Prevent infinite rescan loops
6161
incr diff_empty_count
@@ -280,6 +280,9 @@ proc start_show_diff {cont_info {add_opts {}}} {
280280
lappend cmd diff-files
281281
}
282282
}
283+
if {![is_config_false gui.textconv] && [git-version >= 1.6.1]} {
284+
lappend cmd --textconv
285+
}
283286

284287
if {[string match {160000 *} [lindex $s 2]]
285288
|| [string match {160000 *} [lindex $s 3]]} {

lib/option.tcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ proc do_options {} {
148148
{b gui.trustmtime {mc "Trust File Modification Timestamps"}}
149149
{b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
150150
{b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
151+
{b gui.textconv {mc "Use Textconv For Diffs and Blames"}}
151152
{b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
152153
{i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
153154
{i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}

0 commit comments

Comments
 (0)