gitk: Comply with XDG base directory specification
Write the gitk config data to $XDG_CONFIG_HOME/git/gitk ($HOME/.config/git/gitk by default) in line with the XDG specification. This makes it consistent with git which also follows the spec. If $HOME/.gitk already exists use that for backward compatibility, so only new installations are affected. Signed-off-by: Astril Hayato <astrilhayato@gmail.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Astril Hayato committed
Jan 21, 2014 at 19:10 UTC
8f86339858c1325645f8eaf6950dfd9d74cc9897
1 file changed
+30
-5
gitk
+30
-5
@@ -2787,14 +2787,17 @@ proc savestuff {w} {
2787
global linkfgcolor circleoutlinecolor
2788
global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2789
global hideremotes want_ttk maxrefs
2790
+ global config_file config_file_tmp
2791
2792
if {$stuffsaved} return
2793
if {![winfo viewable .]} return
2794
catch {
2794
- if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
2795
- set f [open "~/.gitk-new" w]
2795
+ if {[file exists $config_file_tmp]} {
2796
+ file delete -force $config_file_tmp
2797
+ }
2798
+ set f [open $config_file_tmp w]
2799
if {$::tcl_platform(platform) eq {windows}} {
2797
- file attributes "~/.gitk-new" -hidden true
2800
+ file attributes $config_file_tmp -hidden true
2801
}
2802
puts $f [list set mainfont $mainfont]
2803
puts $f [list set textfont $textfont]
@@ -2871,7 +2874,7 @@ proc savestuff {w} {
2874
}
2875
puts $f "}"
2876
close $f
2874
- file rename -force "~/.gitk-new" "~/.gitk"
2877
+ file rename -force $config_file_tmp $config_file
2878
}
2879
set stuffsaved 1
2880
}
@@ -12084,7 +12087,29 @@ namespace import ::msgcat::mc
12087
## And eventually load the actual message catalog
12088
::msgcat::mcload $gitk_msgsdir
12089
12087
-catch {source ~/.gitk}
12090
+catch {
12091
+ # follow the XDG base directory specification by default. See
12092
+ # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
12093
+ if {[info exists env(XDG_CONFIG_HOME)] && $env(XDG_CONFIG_HOME) ne ""} {
12094
+ # XDG_CONFIG_HOME environment variable is set
12095
+ set config_file [file join $env(XDG_CONFIG_HOME) git gitk]
12096
+ set config_file_tmp [file join $env(XDG_CONFIG_HOME) git gitk-tmp]
12097
+ } else {
12098
+ # default XDG_CONFIG_HOME
12099
+ set config_file "~/.config/git/gitk"
12100
+ set config_file_tmp "~/.config/git/gitk-tmp"
12101
+ }
12102
+ if {![file exists $config_file]} {
12103
+ # for backward compatibility use the old config file if it exists
12104
+ if {[file exists "~/.gitk"]} {
12105
+ set config_file "~/.gitk"
12106
+ set config_file_tmp "~/.gitk-tmp"
12107
+ } elseif {![file exists [file dirname $config_file]]} {
12108
+ file mkdir [file dirname $config_file]
12109
+ }
12110
+ }
12111
+ source $config_file
12112
+}
12113
12114
parsefont mainfont $mainfont
12115
eval font create mainfont [fontflags mainfont]