Skip to content

Commit 73b6a6c

Browse files
Junio C Hamanopaulusmack
authored andcommitted
[PATCH] gitk: Use GIT_DIR where appropriate.
Some places assumed .git is the GIT_DIR, resulting heads and tags not showing when it was run like "GIT_DIR=. gitk --all". This is not a contrived example --- I rely on it to verify my private copy of git.git repository before pushing it out. Define a single procedure "gitdir" and use it. Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 4ef1753 commit 73b6a6c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

gitk

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ exec wish "$0" -- "${1+$@}"
77
# and distributed under the terms of the GNU General Public Licence,
88
# either version 2, or (at your option) any later version.
99

10+
proc gitdir {} {
11+
global env
12+
if {[info exists env(GIT_DIR)]} {
13+
return $env(GIT_DIR)
14+
} else {
15+
return ".git"
16+
}
17+
}
18+
1019
proc getcommits {rargs} {
1120
global commits commfd phase canv mainfont env
1221
global startmsecs nextupdate
1322
global ctext maincursor textcursor leftover
1423

1524
# check that we can find a .git directory somewhere...
16-
if {[info exists env(GIT_DIR)]} {
17-
set gitdir $env(GIT_DIR)
18-
} else {
19-
set gitdir ".git"
20-
}
25+
set gitdir [gitdir]
2126
if {![file isdirectory $gitdir]} {
2227
error_popup "Cannot find the git directory \"$gitdir\"."
2328
exit 1
@@ -212,7 +217,7 @@ proc parsecommit {id contents listed} {
212217

213218
proc readrefs {} {
214219
global tagids idtags headids idheads
215-
set tags [glob -nocomplain -types f .git/refs/tags/*]
220+
set tags [glob -nocomplain -types f [gitdir]/refs/tags/*]
216221
foreach f $tags {
217222
catch {
218223
set fd [open $f r]
@@ -241,7 +246,7 @@ proc readrefs {} {
241246
close $fd
242247
}
243248
}
244-
set heads [glob -nocomplain -types f .git/refs/heads/*]
249+
set heads [glob -nocomplain -types f [gitdir]/refs/heads/*]
245250
foreach f $heads {
246251
catch {
247252
set fd [open $f r]
@@ -2752,10 +2757,7 @@ proc domktag {} {
27522757
return
27532758
}
27542759
if {[catch {
2755-
set dir ".git"
2756-
if {[info exists env(GIT_DIR)]} {
2757-
set dir $env(GIT_DIR)
2758-
}
2760+
set dir [gitdir]
27592761
set fname [file join $dir "refs/tags" $tag]
27602762
set f [open $fname w]
27612763
puts $f $id

0 commit comments

Comments
 (0)