git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Aguilar <davvid@gmail.com>
To: paulus@samba.org
Cc: peff@peff.net, sam@vilain.net, git@vger.kernel.org,
	David Aguilar <davvid@gmail.com>
Subject: [PATCH v2] gitk: Honor TMPDIR when viewing diffs externally
Date: Thu, 19 Nov 2009 17:27:02 -0800	[thread overview]
Message-ID: <1258680422-42179-1-git-send-email-davvid@gmail.com> (raw)

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

             reply	other threads:[~2009-11-20  1:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-20  1:27 David Aguilar [this message]
2009-12-30  3:13 ` [PATCH v2] gitk: Honor TMPDIR when viewing diffs externally Nanako Shiraishi
2009-12-30  7:45   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1258680422-42179-1-git-send-email-davvid@gmail.com \
    --to=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=peff@peff.net \
    --cc=sam@vilain.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).