From c7664f1a8c6d40acf8221ba620a3193dec411f8c Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 13 Jun 2014 14:13:37 -0700 Subject: [PATCH 1/4] 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 Signed-off-by: Paul Mackerras --- gitk | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gitk b/gitk index 68a61dd7eb..c666435204 100755 --- a/gitk +++ b/gitk @@ -3493,10 +3493,17 @@ proc flist_hl {only} { } proc gitknewtmpdir {} { - global diffnum gitktmpdir gitdir + global diffnum gitktmpdir gitdir env if {![info exists gitktmpdir]} { - set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]] + if {[info exists env(GITK_TMPDIR)]} { + set tmpdir $env(GITK_TMPDIR) + } elseif {[info exists env(TMPDIR)]} { + set tmpdir $env(TMPDIR) + } else { + set tmpdir $gitdir + } + set gitktmpdir [file join $tmpdir [format ".gitk-tmp.%s" [pid]]] if {[catch {file mkdir $gitktmpdir} err]} { error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err" unset gitktmpdir From 105b5d3fbb1c00bb0aeaf9d3e0fbe26a7b1993fc Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 13 Jun 2014 14:43:48 -0700 Subject: [PATCH 2/4] gitk: Use mktemp -d to avoid predictable temporary directories gitk uses a predictable ".gitk-tmp.$PID" pattern when generating a temporary directory. Use "mktemp -d .gitk-tmp.XXXXXX" to harden gitk against someone seeding /tmp with files matching the pid pattern. Signed-off-by: David Aguilar Signed-off-by: Paul Mackerras --- gitk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitk b/gitk index c666435204..41e5071c4b 100755 --- a/gitk +++ b/gitk @@ -3503,7 +3503,8 @@ proc gitknewtmpdir {} { } else { set tmpdir $gitdir } - set gitktmpdir [file join $tmpdir [format ".gitk-tmp.%s" [pid]]] + set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"] + set gitktmpdir [exec mktemp -d $gitktmpformat] if {[catch {file mkdir $gitktmpdir} err]} { error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err" unset gitktmpdir From ac54a4b7715543a29cf72a49a3dd8add32796e86 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 18 Jun 2014 19:53:14 -0700 Subject: [PATCH 3/4] gitk: Catch mkdtemp errors 105b5d3f ("gitk: Use mktemp -d to avoid predictable temporary directories") introduced a dependency on mkdtemp, which is not available on Windows. Use the original temporary directory behavior when mkdtemp fails. This makes the code use mkdtemp when available and gracefully fallback to the existing behavior when it is not available. Helped-by: Junio C Hamano Helped-by: brian m. carlson Signed-off-by: David Aguilar Signed-off-by: Paul Mackerras --- gitk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gitk b/gitk index 41e5071c4b..9237830328 100755 --- a/gitk +++ b/gitk @@ -3504,7 +3504,9 @@ proc gitknewtmpdir {} { set tmpdir $gitdir } set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"] - set gitktmpdir [exec mktemp -d $gitktmpformat] + if {[catch {set gitktmpdir [exec mktemp -d $gitktmpformat]}]} { + set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]] + } if {[catch {file mkdir $gitktmpdir} err]} { error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err" unset gitktmpdir From bde4a0f9f3035d482a80c32b4a485333b9ed4875 Mon Sep 17 00:00:00 2001 From: Max Kirillov Date: Tue, 24 Jun 2014 08:19:44 +0300 Subject: [PATCH 4/4] gitk: Add visiblerefs option, which lists always-shown branches When many branches contain a commit, the branches used to be shown in the form "A, B and many more", where A, B can be master of current HEAD. But there are more which might be interesting to always know about. For example, "origin/master". The new option, visiblerefs, is stored in ~/.gitk. It contains a list of references which are always shown before "and many more" if they contain the commit. By default it is `{"master"}', which is compatible with previous behavior. Signed-off-by: Max Kirillov Signed-off-by: Paul Mackerras --- gitk | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gitk b/gitk index 9237830328..c8df35dee5 100755 --- a/gitk +++ b/gitk @@ -2787,7 +2787,7 @@ proc savestuff {w} { global mainheadcirclecolor workingfilescirclecolor indexcirclecolor global linkfgcolor circleoutlinecolor global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk - global hideremotes want_ttk maxrefs + global hideremotes want_ttk maxrefs visiblerefs global config_file config_file_tmp if {$stuffsaved} return @@ -2813,6 +2813,7 @@ proc savestuff {w} { puts $f [list set autosellen $autosellen] puts $f [list set showneartags $showneartags] puts $f [list set maxrefs $maxrefs] + puts $f [list set visiblerefs $visiblerefs] puts $f [list set hideremotes $hideremotes] puts $f [list set showlocalchanges $showlocalchanges] puts $f [list set datetimeformat $datetimeformat] @@ -7035,7 +7036,7 @@ proc viewnextline {dir} { # add a list of tag or branch names at position pos # returns the number of names inserted proc appendrefs {pos ids var} { - global ctext linknum curview $var maxrefs mainheadid + global ctext linknum curview $var maxrefs visiblerefs mainheadid if {[catch {$ctext index $pos}]} { return 0 @@ -7056,14 +7057,14 @@ proc appendrefs {pos ids var} { if {[llength $tags] > $maxrefs} { # If we are displaying heads, and there are too many, # see if there are some important heads to display. - # Currently this means "master" and the current head. + # Currently that are the current head and heads listed in $visiblerefs option set itags {} if {$var eq "idheads"} { set utags {} foreach ti $tags { set hname [lindex $ti 0] set id [lindex $ti 1] - if {($hname eq "master" || $id eq $mainheadid) && + if {([lsearch -exact $visiblerefs $hname] != -1 || $id eq $mainheadid) && [llength $itags] < $maxrefs} { lappend itags $ti } else { @@ -12045,6 +12046,7 @@ set wrapcomment "none" set showneartags 1 set hideremotes 0 set maxrefs 20 +set visiblerefs {"master"} set maxlinelen 200 set showlocalchanges 1 set limitdiffs 1