git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/8] gitk: simplify calculation of gitdir

From
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Date
Apr 5, 2011, 02:14 UTC
Message-ID
<1301969659-19703-8-git-send-email-martin.von.zweigbergk@gmail.com>
In-Reply-To
<1301969659-19703-1-git-send-email-martin.von.zweigbergk@gmail.com>

Since 5024baa ([PATCH] Make gitk work when launched in a subdirectory, 2007-01-09), gitk has used 'git rev-parse --git-dir' to find the .git directory. However, gitk still first checks for the $GIT_DIR environment variable and that the value returned from git-rev-parse does not point to a file. Since git-rev-parse does both of these checks already, the checks can safely be removed from gitk. This makes the gitdir procedure small enough to inline.

This cleanup introduces a UI regression in that the error message will now be "Cannot find a git repository here." even in the case where GIT_DIR points to a file, for which the error message was previously "Cannot find the git directory \"%s\".". It should be noted, though, that even before this patch, 'gitk --git-dir=path/to/some/file' would give the former error message.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
 gitk-git/gitk |   15 +--------------
 1 files changed, 1 insertions(+), 14 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 0c1c4df..232ea6e 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -9,15 +9,6 @@ exec wish "$0" -- "$@"
 
 package require Tk
 
-proc gitdir {} {
-    global env
-    if {[info exists env(GIT_DIR)]} {
-	return $env(GIT_DIR)
-    } else {
-	return [exec git rev-parse --git-dir]
-    }
-}
-
 # A simple scheduler for compute-intensive stuff.
 # The aim is to make sure that event handlers for GUI actions can
 # run at least every 50-100 ms.  Unfortunately fileevent handlers are
@@ -11507,14 +11498,10 @@ setui $uicolor
 setoptions
 
 # check that we can find a .git directory somewhere...
-if {[catch {set gitdir [gitdir]}]} {
+if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
     show_error {} . [mc "Cannot find a git repository here."]
     exit 1
 }
-if {![file isdirectory $gitdir]} {
-    show_error {} . [mc "Cannot find the git directory \"%s\"." $gitdir]
-    exit 1
-}
 
 set selecthead {}
 set selectheadid {}
-- 
1.7.4.79.gcbe20
Previous: Martin von ZweigbergkNext: Martin von Zweigbergk
Message 10 of 15 in “make gitk work better in non-top-level directory”
  1. 0/8 make gitk work better in non-top-level directoryMartin von Zweigbergk, Apr 5, 2011
  2. 1/8 gitk: fix file highlight when run in subdirectoryMartin von Zweigbergk, Apr 5, 2011
  3. Paul MackerrasApr 10, 2011
  4. Martin von ZweigbergkApr 10, 2011
  5. 2/8 gitk: fix "show origin of this line" with separate work treeMartin von Zweigbergk, Apr 5, 2011
  6. 3/8 gitk: fix "blame parent commit" with separate work treeMartin von Zweigbergk, Apr 5, 2011
  7. 4/8 gitk: fix "External diff" with separate work treeMartin von Zweigbergk, Apr 5, 2011
  8. 5/8 gitk: put temporary directory inside .gitMartin von Zweigbergk, Apr 5, 2011
  9. 6/8 gitk: run 'git rev-parse --git-dir' only onceMartin von Zweigbergk, Apr 5, 2011
  10. 7/8 gitk: simplify calculation of gitdirMartin von Zweigbergk, Apr 5, 2011
  11. 8/8 gitk: show modified files with separate work treeMartin von Zweigbergk, Apr 5, 2011
  12. Paul MackerrasApr 10, 2011
  13. Junio C HamanoApr 11, 2011
  14. 8/8 gitk: show modified files with separate work treeMartin von Zweigbergk, May 24, 2011
  15. Peter BaumannApr 5, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.