[PATCH (GIT-GUI,GITK) 3/8] git-gui: Allow forcing display encoding for diffs using a submenu.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a submenu to allow dynamically changing the encoding to use
for diffs. Encoding settings are remembered while git-gui runs.
The rules are:

1) Encoding set for a specific file overrides gitattributes.
2) Last explicitly set value of the encoding overrides gui.encoding

Signed-off-by: Alexander Gavrilov <angavrilov@xxxxxxxxx>
---
 git-gui.sh       |    8 ++++++++
 lib/diff.tcl     |    9 +++++++++
 lib/encoding.tcl |   29 +++++++++++++++++++++++++++--
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/git-gui.sh b/git-gui.sh
index 444990b..3bbb4f1 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -2937,6 +2937,14 @@ proc create_common_diff_popup {ctxm} {
 		-command {incr_font_size font_diff 1}
 	lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
 	$ctxm add separator
+	set emenu $ctxm.enc
+	menu $emenu
+	build_encoding_menu $emenu [list force_diff_encoding]
+	$ctxm add cascade \
+		-label [mc "Encoding"] \
+		-menu $emenu
+	lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
+	$ctxm add separator
 	$ctxm add command -label [mc "Options..."] \
 		-command do_options
 }
diff --git a/lib/diff.tcl b/lib/diff.tcl
index 8fefc5d..b616296 100644
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
@@ -40,6 +40,15 @@ proc reshow_diff {} {
 	}
 }
 
+proc force_diff_encoding {enc} {
+	global current_diff_path
+	
+	if {$current_diff_path ne {}} {
+		force_path_encoding $current_diff_path $enc
+		reshow_diff
+	}
+}
+
 proc handle_empty_diff {} {
 	global current_diff_path file_states file_lists
 
diff --git a/lib/encoding.tcl b/lib/encoding.tcl
index 2c1eda3..b2ee38c 100644
--- a/lib/encoding.tcl
+++ b/lib/encoding.tcl
@@ -321,13 +321,38 @@ proc tcl_encoding {enc} {
     return {}
 }
 
+proc force_path_encoding {path enc} {
+	global path_encoding_overrides last_encoding_override
+
+	set enc [tcl_encoding $enc]
+	if {$enc eq {}} {
+		catch { unset last_encoding_override }
+		catch { unset path_encoding_overrides($path) }
+	} else {
+		set last_encoding_override $enc
+		if {$path ne {}} {
+			set path_encoding_overrides($path) $enc
+		}
+	}
+}
+
 proc get_path_encoding {path} {
-	set tcl_enc [tcl_encoding [get_config gui.encoding]]
+	global path_encoding_overrides last_encoding_override
+
+	if {[info exists last_encoding_override]} {
+		set tcl_enc $last_encoding_override
+	} else {
+		set tcl_enc [tcl_encoding [get_config gui.encoding]]
+	}
 	if {$tcl_enc eq {}} {
 		set tcl_enc [encoding system]
 	}
 	if {$path ne {}} {
-		set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
+		if {[info exists path_encoding_overrides($path)]} {
+			set enc2 $path_encoding_overrides($path)
+		} else {
+			set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
+		}
 		if {$enc2 ne {}} {
 			set tcl_enc $enc2
 		}
-- 
1.6.0.20.g6148bc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux