git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
To: Paul Mackerras <paulus@samba.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org,
	Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Subject: [PATCH 8/8] gitk: show modified files with separate work tree
Date: Mon,  4 Apr 2011 22:14:19 -0400	[thread overview]
Message-ID: <1301969659-19703-9-git-send-email-martin.von.zweigbergk@gmail.com> (raw)
In-Reply-To: <1301969659-19703-1-git-send-email-martin.von.zweigbergk@gmail.com>

"git rev-parse --is-inside-work-tree" is currently used to determine
whether to show modified files in gitk (the red and green fake
commits). This does not work if the current directory is not inside
the work tree, as can be the case e.g. if GIT_WORK_TREE is
set. Instead, check if the repository is not bare and that we are not
inside the .git directory.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>

---
Is the test in proc hasworktree good?

Why do git commands that need a work tree not work under .git? Why
don't they show the same output as if they had been run from the work
tree? (Btw, the check for valid work tree does not work for aliases,
so e.g. 'git st', with 'st' as alias for 'status' will show all files
as deleted.)

How do I simplify the Tcl code to just return the boolean right away?

Why is the hasworktree variable reset in updatecommits? The only reason
I can think of is when 'core.worktree' is set/changed, but I don't
think that case worked very well before this series anyway. Should
gitdir also be recalculated?

 gitk-git/gitk |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 232ea6e..914de8d 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -9,6 +9,15 @@ exec wish "$0" -- "$@"
 
 package require Tk
 
+proc hasworktree {} {
+    if {[expr {[exec git rev-parse --is-bare-repository] == "false"}] &&
+	[expr {[exec git rev-parse --is-inside-git-dir] == "false"}]} {
+	return 1
+    } else {
+	return 0
+    }
+}
+
 # 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
@@ -459,11 +468,11 @@ proc updatecommits {} {
     global viewactive viewcomplete tclencoding
     global startmsecs showneartags showlocalchanges
     global mainheadid viewmainheadid viewmainheadid_orig pending_select
-    global isworktree
+    global hasworktree
     global varcid vposids vnegids vflags vrevs
     global show_notes
 
-    set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
+    set hasworktree [hasworktree]
     rereadrefs
     set view $curview
     if {$mainheadid ne $viewmainheadid_orig($view)} {
@@ -5025,9 +5034,9 @@ proc dohidelocalchanges {} {
 # spawn off a process to do git diff-index --cached HEAD
 proc dodiffindex {} {
     global lserial showlocalchanges vfilelimit curview
-    global isworktree
+    global hasworktree
 
-    if {!$showlocalchanges || !$isworktree} return
+    if {!$showlocalchanges || !$hasworktree} return
     incr lserial
     set cmd "|git diff-index --cached HEAD"
     if {$vfilelimit($curview) ne {}} {
@@ -11617,9 +11626,9 @@ set stopped 0
 set stuffsaved 0
 set patchnum 0
 set lserial 0
-set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
+set hasworktree [hasworktree]
 set cdup {}
-if {$isworktree} {
+if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
     set cdup [exec git rev-parse --show-cdup]
 }
 set worktree [exec git rev-parse --show-toplevel]
-- 
1.7.4.79.gcbe20

  parent reply	other threads:[~2011-04-05  2:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05  2:14 [PATCH 0/8] make gitk work better in non-top-level directory Martin von Zweigbergk
2011-04-05  2:14 ` [PATCH 1/8] gitk: fix file highlight when run in subdirectory Martin von Zweigbergk
2011-04-10  1:54   ` Paul Mackerras
2011-04-10 18:03     ` Martin von Zweigbergk
2011-04-05  2:14 ` [PATCH 2/8] gitk: fix "show origin of this line" with separate work tree Martin von Zweigbergk
2011-04-05  2:14 ` [PATCH 3/8] gitk: fix "blame parent commit" " Martin von Zweigbergk
2011-04-05  2:14 ` [PATCH 4/8] gitk: fix "External diff" " Martin von Zweigbergk
2011-04-05  2:14 ` [PATCH 5/8] gitk: put temporary directory inside .git Martin von Zweigbergk
2011-04-05  2:14 ` [PATCH 6/8] gitk: run 'git rev-parse --git-dir' only once Martin von Zweigbergk
2011-04-05  2:14 ` [PATCH 7/8] gitk: simplify calculation of gitdir Martin von Zweigbergk
2011-04-05  2:14 ` Martin von Zweigbergk [this message]
2011-04-10  2:03   ` [PATCH 8/8] gitk: show modified files with separate work tree Paul Mackerras
2011-04-11 19:15     ` Junio C Hamano
2011-05-24  2:44   ` [PATCH v2 " Martin von Zweigbergk
2011-04-05 18:48 ` [PATCH 0/8] make gitk work better in non-top-level directory Peter Baumann

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1301969659-19703-9-git-send-email-martin.von.zweigbergk@gmail.com \
    --to=martin.von.zweigbergk@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=paulus@samba.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).