Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 8f86339

Browse files
Astril Hayatopaulusmack
authored andcommitted
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 <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 786f15c commit 8f86339

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

gitk

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,14 +2787,17 @@ proc savestuff {w} {
27872787
global linkfgcolor circleoutlinecolor
27882788
global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
27892789
global hideremotes want_ttk maxrefs
2790+
global config_file config_file_tmp
27902791

27912792
if {$stuffsaved} return
27922793
if {![winfo viewable .]} return
27932794
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]
27962799
if {$::tcl_platform(platform) eq {windows}} {
2797-
file attributes "~/.gitk-new" -hidden true
2800+
file attributes $config_file_tmp -hidden true
27982801
}
27992802
puts $f [list set mainfont $mainfont]
28002803
puts $f [list set textfont $textfont]
@@ -2871,7 +2874,7 @@ proc savestuff {w} {
28712874
}
28722875
puts $f "}"
28732876
close $f
2874-
file rename -force "~/.gitk-new" "~/.gitk"
2877+
file rename -force $config_file_tmp $config_file
28752878
}
28762879
set stuffsaved 1
28772880
}
@@ -12084,7 +12087,29 @@ namespace import ::msgcat::mc
1208412087
## And eventually load the actual message catalog
1208512088
::msgcat::mcload $gitk_msgsdir
1208612089

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+
}
1208812113

1208912114
parsefont mainfont $mainfont
1209012115
eval font create mainfont [fontflags mainfont]

0 commit comments

Comments
 (0)