git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] gitk: Honor TMPDIR when viewing diffs externally
@ 2009-11-20  1:27 David Aguilar
  2009-12-30  3:13 ` Nanako Shiraishi
  0 siblings, 1 reply; 3+ messages in thread
From: David Aguilar @ 2009-11-20  1:27 UTC (permalink / raw)
  To: paulus; +Cc: peff, sam, git, David Aguilar

gitk's external diff fails when browsing read-only repositories.
This is due to gitk's assumption that the current directory is
always writable.  By honoring TMPDIR we avoid this problem and
allow users to define the location used for temporary files.

Signed-off-by: David Aguilar <davvid@gmail.com>
---

This version of the patch is more careful to ensure that
the temporary files and directories created by gitk are not
easily predictable.

 gitk |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/gitk b/gitk
index 364c7a8..84ea8a9 100755
--- a/gitk
+++ b/gitk
@@ -3292,17 +3292,21 @@ proc flist_hl {only} {
     set gdttype [mc "touching paths:"]
 }
 
+proc randstr {} {
+    global initial_rand
+    return [format "%f" [expr rand() + $initial_rand]]
+}
+
 proc gitknewtmpdir {} {
-    global diffnum gitktmpdir gitdir
+    global diffnum gitktmpdir gitdir env
 
     if {![info exists gitktmpdir]} {
-	set gitktmpdir [file join [file dirname $gitdir] \
-			    [format ".gitk-tmp.%s" [pid]]]
-	if {[catch {file mkdir $gitktmpdir} err]} {
-	    error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
-	    unset gitktmpdir
-	    return {}
+	if {[info exists env(TMPDIR)]} {
+	    set tmpdir $env(TMPDIR)
+	} else {
+	    set tmpdir [file dirname $gitdir]
 	}
+	set gitktmpdir [file join $tmpdir ".gitk-tmp.[pid].[randstr]"]
 	set diffnum 0
     }
     incr diffnum
@@ -3339,10 +3343,12 @@ proc external_diff_get_one_file {diffid filename diffdir} {
 	return $nullfile
     }
     if {$diffid == $nullid2} {
-        set difffile [file join $diffdir "\[index\] [file tail $filename]"]
+        set difffile [file join $diffdir \
+	       "\[index-[randstr]\] [file tail $filename]"]
         return [save_file_from_commit :$filename $difffile index]
     }
-    set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
+    set difffile [file join $diffdir \
+	       "\[$diffid-[randstr]\] [file tail $filename]"]
     return [save_file_from_commit $diffid:$filename $difffile \
 	       "revision $diffid"]
 }
@@ -8525,8 +8531,8 @@ proc diffcommits {a b} {
     global diffcontext diffids blobdifffd diffinhdr
 
     set tmpdir [gitknewtmpdir]
-    set fna [file join $tmpdir "commit-[string range $a 0 7]"]
-    set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
+    set fna [file join $tmpdir "commit-[string range $a 0 7]-[randstr]"]
+    set fnb [file join $tmpdir "commit-[string range $b 0 7]-[randstr]"]
     if {[catch {
 	exec git diff-tree -p --pretty $a >$fna
 	exec git diff-tree -p --pretty $b >$fnb
@@ -11321,6 +11327,7 @@ if {[tk windowingsystem] eq "aqua"} {
     set textfont {Courier 9}
     set uifont {Helvetica 9 bold}
 }
+set initial_rand [expr srand([clock scan now])]
 set tabstop 8
 set findmergefiles 0
 set maxgraphpct 50
-- 
1.6.5.3.171.ge36e

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-30  7:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-20  1:27 [PATCH v2] gitk: Honor TMPDIR when viewing diffs externally David Aguilar
2009-12-30  3:13 ` Nanako Shiraishi
2009-12-30  7:45   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).