gitk: Honor TMPDIR when viewing external diffs

gitk fails to show diffs when browsing a read-only repository. This is due to gitk's assumption that the current directory is always writable. Teach gitk to honor either the GITK_TMPDIR or TMPDIR environment variables. This allows users to override the default location used when writing temporary files. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Paul Mackerras <paulus@samba.org>

David Aguilar committed Jun 13, 2014 at 14:13 UTC c7664f1a8c6d40acf8221ba620a3193dec411f8c
1 file changed +9 -2
gitk
+9 -2
@@ -3493,10 +3493,17 @@ proc flist_hl {only} {
3493 }
3494
3495 proc gitknewtmpdir {} {
3496 - global diffnum gitktmpdir gitdir
3496 + global diffnum gitktmpdir gitdir env
3497
3498 if {![info exists gitktmpdir]} {
3499 - set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3499 + if {[info exists env(GITK_TMPDIR)]} {
3500 + set tmpdir $env(GITK_TMPDIR)
3501 + } elseif {[info exists env(TMPDIR)]} {
3502 + set tmpdir $env(TMPDIR)
3503 + } else {
3504 + set tmpdir $gitdir
3505 + }
3506 + set gitktmpdir [file join $tmpdir [format ".gitk-tmp.%s" [pid]]]
3507 if {[catch {file mkdir $gitktmpdir} err]} {
3508 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3509 unset gitktmpdir