@matheusbsbs / matheus-bagliano / commits / c2758a17cb
Fork 0

git-gui: Allow [gitdir ...] to act as [file join [gitdir] ...].

Because it is such a common idiom to use [gitdir] along with [file join] to locate the path of an item within the .git directory of the current repository we might as well allow gitdir to act as a wrapper for the file join operation. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 20, 2007 at 21:55 UTC c2758a17cb268fa2bb7ff46e27b571038a9eeb5d
1 file changed +20 -17
git-gui.sh
+20 -17
@@ -33,9 +33,12 @@ proc appname {} {
33 return $_appname
34 }
35
36 -proc gitdir {} {
36 +proc gitdir {args} {
37 global _gitdir
38 - return $_gitdir
38 + if {$args eq {}} {
39 + return $_gitdir
40 + }
41 + return [eval [concat [list file join $_gitdir] $args]]
42 }
43
44 proc reponame {} {
@@ -305,7 +308,7 @@ proc repository_state {ctvar hdvar mhvar} {
308 return
309 }
310
308 - set merge_head [file join [gitdir] MERGE_HEAD]
311 + set merge_head [gitdir MERGE_HEAD]
312 if {[file exists $merge_head]} {
313 set ct merge
314 set fd_mh [open $merge_head r]
@@ -392,7 +395,7 @@ proc rescan_stage2 {fd after} {
395
396 set ls_others [list | git ls-files --others -z \
397 --exclude-per-directory=.gitignore]
395 - set info_exclude [file join [gitdir] info exclude]
398 + set info_exclude [gitdir info exclude]
399 if {[file readable $info_exclude]} {
400 lappend ls_others "--exclude-from=$info_exclude"
401 }
@@ -418,7 +421,7 @@ proc rescan_stage2 {fd after} {
421 proc load_message {file} {
422 global ui_comm
423
421 - set f [file join [gitdir] $file]
424 + set f [gitdir $file]
425 if {[file isfile $f]} {
426 if {[catch {set fd [open $f r]}]} {
427 return 0
@@ -951,7 +954,7 @@ A good commit message has the following format:
954 proc commit_prehook {curHEAD msg} {
955 global ui_status_value pch_error
956
954 - set pchook [file join [gitdir] hooks pre-commit]
957 + set pchook [gitdir hooks pre-commit]
958
959 # On Cygwin [file executable] might lie so we need to ask
960 # the shell if the hook is executable. Yes that's annoying.
@@ -1060,20 +1063,20 @@ proc commit_committree {fd_wt curHEAD msg} {
1063
1064 # -- Cleanup after ourselves.
1065 #
1063 - catch {file delete [file join [gitdir] MERGE_HEAD]}
1064 - catch {file delete [file join [gitdir] MERGE_MSG]}
1065 - catch {file delete [file join [gitdir] SQUASH_MSG]}
1066 - catch {file delete [file join [gitdir] GITGUI_MSG]}
1066 + catch {file delete [gitdir MERGE_HEAD]}
1067 + catch {file delete [gitdir MERGE_MSG]}
1068 + catch {file delete [gitdir SQUASH_MSG]}
1069 + catch {file delete [gitdir GITGUI_MSG]}
1070
1071 # -- Let rerere do its thing.
1072 #
1070 - if {[file isdirectory [file join [gitdir] rr-cache]]} {
1073 + if {[file isdirectory [gitdir rr-cache]]} {
1074 catch {exec git rerere}
1075 }
1076
1077 # -- Run the post-commit hook.
1078 #
1076 - set pchook [file join [gitdir] hooks post-commit]
1079 + set pchook [gitdir hooks post-commit]
1080 if {[is_Windows] && [file isfile $pchook]} {
1081 set pchook [list sh -c [concat \
1082 "if test -x \"$pchook\";" \
@@ -1738,7 +1741,7 @@ proc load_all_remotes {} {
1741 set all_remotes [list]
1742 array unset tracking_branches
1743
1741 - set rm_dir [file join [gitdir] remotes]
1744 + set rm_dir [gitdir remotes]
1745 if {[file isdirectory $rm_dir]} {
1746 set all_remotes [glob \
1747 -types f \
@@ -1792,7 +1795,7 @@ proc populate_fetch_menu {m} {
1795 }
1796 } else {
1797 catch {
1795 - set fd [open [file join [gitdir] remotes $r] r]
1798 + set fd [open [gitdir remotes $r] r]
1799 while {[gets $fd n] >= 0} {
1800 if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
1801 set enable 1
@@ -1823,7 +1826,7 @@ proc populate_push_menu {m} {
1826 }
1827 } else {
1828 catch {
1826 - set fd [open [file join [gitdir] remotes $r] r]
1829 + set fd [open [gitdir remotes $r] r]
1830 while {[gets $fd n] >= 0} {
1831 if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
1832 set enable 1
@@ -1858,7 +1861,7 @@ proc populate_pull_menu {m} {
1861 }
1862 } else {
1863 catch {
1861 - set fd [open [file join [gitdir] remotes $remote] r]
1864 + set fd [open [gitdir remotes $remote] r]
1865 while {[gets $fd line] >= 0} {
1866 if {[regexp {^Pull:[ \t]*([^:]+):} $line line rb]} {
1867 lappend rb_list $rb
@@ -2264,7 +2267,7 @@ proc do_quit {} {
2267
2268 # -- Stash our current commit buffer.
2269 #
2267 - set save [file join [gitdir] GITGUI_MSG]
2270 + set save [gitdir GITGUI_MSG]
2271 set msg [string trim [$ui_comm get 0.0 end]]
2272 if {![string match amend* $commit_type]
2273 && [$ui_comm edit modified]