git-gui: respect core.hooksPath, falling back to .git/hooks
cover git-gui: respect core.hooksPath, falling back to .git/hooks
This is yet another patch from Git for Windows.
Johannes Schindelin (1):
respect core.hooksPath, falling back to .git/hooks
git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
base-commit: 60c60b627e81bf84e1cb01729d2ae882178f079d
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-361%2Fdscho%2Fgit-gui-hooks-path-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-361/dscho/git-gui-hooks-path-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/361
Signature · 1 line
gitgitgadget
PATCH 1/1 respect core.hooksPath, falling back to .git/hooks
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the --git-path option respects that config variable, too, so we may just as well use that command.
For Git versions older than v2.5.0 (which was the first version to support the --git-path option for the rev-parse command), we simply fall back to the previous code.
This fixes https://github.com/git-for-windows/git/issues/1755
--- git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
git-gui.sh +5 -1
@@ -623,7 +623,11 @@ proc git_write {args} { } proc githook_read {hook_name args} { - set pchook [gitdir hooks $hook_name] + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set pchook [git rev-parse --git-path "hooks/$hook_name"] + } else { + set pchook [gitdir hooks $hook_name] + } lappend args 2>@1 # On Windows [file executable] might lie so we need to ask
Signature · 1 line
gitgitgadget
Re: [PATCH 1/1] respect core.hooksPath, falling back to .git/hooks
Hi,
Quoted 26 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the
--git-pathoption respects that config variable, too, so we may just as well use that command.For Git versions older than v2.5.0 (which was the first version to support the
--git-pathoption for therev-parsecommand), we simply fall back to the previous code.This fixes https://github.com/git-for-windows/git/issues/1755
Initial-patch-by Philipp Gortan <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>--- git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)git-gui.sh +0
-0
git-gui.sh proc git_write {args} { · line 630
Quoted 9 lines
git-gui.sh +5
-1@@ -623,7 +623,11 @@ proc git_write {args} { } proc githook_read {hook_name args} { - set pchook [gitdir hooks $hook_name] + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set pchook [git rev-parse --git-path "hooks/$hook_name"] + } else { + set pchook [gitdir hooks $hook_name] + }
gitdir is used in a lot of places, and I think all those would also benefit from using --git-path. So I think it is a better idea to move this to the procedure gitdir. It would have to be refactored to take any number of arguments, instead of the two it takes here.
Other than that, looks good. Thanks.
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH 1/1] respect core.hooksPath, falling back to .git/hooks
Quoted 32 lines · Pratyush Yadav
Hi,
Quoted 28 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the
--git-pathoption respects that config variable, too, so we may just as well use that command.For Git versions older than v2.5.0 (which was the first version to support the
--git-pathoption for therev-parsecommand), we simply fall back to the previous code.This fixes https://github.com/git-for-windows/git/issues/1755
Initial-patch-by Philipp Gortan <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>--- git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)git-gui.sh +0
-0@@ -623,7 +623,11 @@ proc git_write {args} { }
Quoted 12 lines
git-gui.sh proc git_write {args} { · line 630
Quoted 7 lines
git-gui.sh +5
-1proc githook_read {hook_name args} { - set pchook [gitdir hooks $hook_name] + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set pchook [git rev-parse --git-path "hooks/$hook_name"] + } else { + set pchook [gitdir hooks $hook_name] + }gitdir is used in a lot of places, and I think all those would also benefit from using --git-path. So I think it is a better idea to move this to the procedure gitdir. It would have to be refactored to take any number of arguments, instead of the two it takes here.
gitdir already takes an arbitrary number of arguments and joins them to a path. The more imminent challenge is, that gitdir caches the GIT_DIR, thus it tries to avoid calling "git rev-parse". Which works for most, but not for hooks.
We could either maintain a blacklist, for what we cache the result too, or always call "git rev-parse --git-dir".
This blacklist would need to be in sync with the one in Git's path.c::adjust_git_path() than.
Bert
Quoted 6 lines
Other than that, looks good. Thanks.
--
Regards,
Pratyush Yadav
Re: [PATCH 1/1] respect core.hooksPath, falling back to .git/hooks
Quoted 46 lines · Bert Wesarg
Quoted 32 lines · Pratyush Yadav
Hi,
Quoted 28 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the
--git-pathoption respects that config variable, too, so we may just as well use that command.For Git versions older than v2.5.0 (which was the first version to support the
--git-pathoption for therev-parsecommand), we simply fall back to the previous code.This fixes https://github.com/git-for-windows/git/issues/1755
Initial-patch-by Philipp Gortan <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>--- git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)git-gui.sh +0
-0@@ -623,7 +623,11 @@ proc git_write {args} { }Quoted 12 lines
git-gui.sh proc git_write {args} { · line 630
Quoted 7 lines
git-gui.sh +5
-1proc githook_read {hook_name args} { - set pchook [gitdir hooks $hook_name] + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set pchook [git rev-parse --git-path "hooks/$hook_name"] + } else { + set pchook [gitdir hooks $hook_name] + }gitdir is used in a lot of places, and I think all those would also benefit from using --git-path. So I think it is a better idea to move this to the procedure gitdir. It would have to be refactored to take any number of arguments, instead of the two it takes here.
Quoted 4 lines
gitdir already takes an arbitrary number of arguments and joins them to a path. The more imminent challenge is, that gitdir caches the
GIT_DIR, thus it tries to avoid calling "git rev-parse". Which works for most, but not for hooks.
What I was thinking of was something like this:
- If no args are passed, then just directly return $_gitdir. This is already being done. I assume the GIT_DIR relocation is already handled by git rev-parse --git-dir, so this would point to the correct location.
- If args are passed, then we want a subdirectory of GIT_DIR In this case, it is possible that this subdirectory has also been relocated (hooks/ being one of those subdirectories). So in this case, use git rev-parse --git-path instead.
So the gitdir procedure would look something like:
proc gitdir {args} {
global $_gitdir
if {$args eq {}} {
# Return the cached GIT_DIR
return $_gitdir
}
# Use `git rev-parse --git-path` to get the path instead of
# using the cached value.
}Am I missing something? Or does this fix the issue you describe?
Quoted 5 lines
We could either maintain a blacklist, for what we cache the result too, or always call "git rev-parse --git-dir".
This blacklist would need to be in sync with the one in Git's
path.c::adjust_git_path()than.
Is caching GIT_DIR that important in terms of performance? Otherwise, I'd say calling git rev-parse --git-path for _every_ subdirectory of GIT_DIR is a much simpler solution.
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH 1/1] respect core.hooksPath, falling back to .git/hooks
Hi,
Quoted 74 lines · Pratyush Yadav
Quoted 44 lines · Bert Wesarg
Quoted 30 lines · Pratyush Yadav
Quoted 28 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the
--git-pathoption respects that config variable, too, so we may just as well use that command.For Git versions older than v2.5.0 (which was the first version to support the
--git-pathoption for therev-parsecommand), we simply fall back to the previous code.This fixes https://github.com/git-for-windows/git/issues/1755
Initial-patch-by Philipp Gortan <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>--- git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)git-gui.sh +0
-0@@ -623,7 +623,11 @@ proc git_write {args} { }Quoted 12 lines
git-gui.sh proc git_write {args} { · line 630
Quoted 7 lines
git-gui.sh +5
-1proc githook_read {hook_name args} { - set pchook [gitdir hooks $hook_name] + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set pchook [git rev-parse --git-path "hooks/$hook_name"] + } else { + set pchook [gitdir hooks $hook_name] + }gitdir is used in a lot of places, and I think all those would also benefit from using --git-path. So I think it is a better idea to move this to the procedure gitdir. It would have to be refactored to take any number of arguments, instead of the two it takes here.
Quoted 4 lines
gitdir already takes an arbitrary number of arguments and joins them to a path. The more imminent challenge is, that gitdir caches the
GIT_DIR, thus it tries to avoid calling "git rev-parse". Which works for most, but not for hooks.What I was thinking of was something like this:
- If no args are passed, then just directly return $_gitdir. This is already being done. I assume the
GIT_DIRrelocation is already handled bygit rev-parse --git-dir, so this would point to the correct location.
- If args are passed, then we want a subdirectory ofGIT_DIRIn this case, it is possible that this subdirectory has also been relocated (hooks/ being one of those subdirectories). So in this case, usegit rev-parse --git-pathinstead.So the gitdir procedure would look something like:
proc gitdir {args} { global $_gitdir if {$args eq {}} { # Return the cached GIT_DIR return $_gitdir } # Use `git rev-parse --git-path` to get the path instead of # using the cached value. }
Quoted 1 line
Am I missing something? Or does this fix the issue you describe?
The gitdir function is called 13 times during startup alone, and who knows how many more times later.
So I am quite convinced that the original intention was to save on spawning processes left and right.
But since you are the Git GUI maintainer, and this was your suggestion, I made it so.
Ciao,
Johannes
Quoted 14 lines
Quoted 5 lines
We could either maintain a blacklist, for what we cache the result too, or always call "git rev-parse --git-dir".
This blacklist would need to be in sync with the one in Git's
path.c::adjust_git_path()than.Is caching
GIT_DIRthat important in terms of performance? Otherwise, I'd say callinggit rev-parse --git-pathfor _every_ subdirectory ofGIT_DIRis a much simpler solution.--
Regards,
Pratyush Yadav
v2 cover git-gui: respect core.hooksPath, falling back to .git/hooks
In reply to Johannes Schindelin via GitGitGadgetThis is yet another patch from Git for Windows.
Changes since v1:
* Rather than a fine-grained override of gitdir just for the hooks path, we now spawn git rev-parse --git-path [...] every time gitdir is called with arguments. This makes the code safer, although at the cost of potentially many spawned processes.
Johannes Schindelin (1):
respect core.hooksPath, falling back to .git/hooks
git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
base-commit: 60c60b627e81bf84e1cb01729d2ae882178f079d
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-361%2Fdscho%2Fgit-gui-hooks-path-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-361/dscho/git-gui-hooks-path-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/361
Range-diff vs v1:
1: eca193f91b < -: ---------- respect core.hooksPath, falling back to .git/hooks -: ---------- > 1: c101422936 respect core.hooksPath, falling back to .git/hooks
Signature · 1 line
gitgitgadget
PATCH v2 1/1 respect core.hooksPath, falling back to .git/hooks
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the --git-path option respects that config variable, too, so we may just as well use that command.
For Git versions older than v2.5.0 (which was the first version to support the --git-path option for the rev-parse command), we simply fall back to the previous code.
An original patch handled only the hooksPath setting (as the title of this commit message suggests), however, during the code submission it was deemed better to fix all call to the gitdir function.
With this change, we spawn git rev-parse --git-path [...] 13 times during Git GUI's startup.
This fixes https://github.com/git-for-windows/git/issues/1755
--- git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
git-gui.sh +5 -1
@@ -202,7 +202,11 @@ proc gitdir {args} { if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + if {[package vcompare $::_git_version 2.5.0] >= 0} { + return [git rev-parse --git-path [eval [list file join] $args]] + } else { + return [eval [list file join $_gitdir] $args] + } } proc gitexec {args} {
Signature · 1 line
gitgitgadget
Re: [PATCH 1/1] respect core.hooksPath, falling back to .git/hooks
In reply to Johannes SchindelinQuoted 9 lines · Johannes Schindelin
Quoted 7 lines · Pratyush Yadav
Quoted 6 lines · Bert Wesarg
Quoted 5 lines · Pratyush Yadav
gitdir is used in a lot of places, and I think all those would also
benefit from using --git-path. So I think it is a better idea to move this to the procedure gitdir. It would have to be refactored to take any number of arguments, instead of the two it takes here.
Quoted 8 lines
The
gitdirfunction is called 13 times during startup alone, and who knows how many more times later.So I am quite convinced that the original intention was to save on spawning processes left and right.
But since you are the Git GUI maintainer, and this was your suggestion, I made it so.
Yes, I am the maintainer, but I am not an all-knowing, all-seeing entity. Your, and every other contributors, suggestions are very valuable. And my suggestions aren't gospel. I would hate to see someone send in a patch they weren't sure was the best thing to do just because I suggested it. Please feel free to object my suggestions.
In this case, I didn't expect gitdir to be called this many times.
While I don't notice much of a performance difference on my system (Linux), a quick measurement tells me that the time spent in gitdir is about 16 ms. In contrast, the same measurement without the v2 patch gives out 0 ms (IOW, very fast). 16 ms sounds a bit much for something so simple. It might not be the same for everyone else. AFAIK, spawning a process is much slower on Windows.
So now I'm not so sure my suggestion was a good one. My original aim was to be sure everything was correct, and no incorrect directories were being used. But the current solution comes at a performance hit.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
We could either maintain a blacklist, for what we cache the result too, or always call "git rev-parse --git-dir".
This blacklist would need to be in sync with the one in Git's
path.c::adjust_git_path()than.
Bert's suggestion seems like a decent compromise. We run git rev-parse --git-path for the paths in the blacklist, and for the rest we use the cached value. This does run the risk of getting out of sync with git.git's list, but it might be better than spawing a process every time, and is very likely better than just doing it for hooks.
Thoughts?
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH 1/1] respect core.hooksPath, falling back to .git/hooks
Hi,
Quoted 41 lines · Pratyush Yadav
Quoted 9 lines · Johannes Schindelin
Quoted 7 lines · Pratyush Yadav
Quoted 6 lines · Bert Wesarg
Quoted 5 lines · Pratyush Yadav
gitdir is used in a lot of places, and I think all those would also
benefit from using --git-path. So I think it is a better idea to move this to the procedure gitdir. It would have to be refactored to take any number of arguments, instead of the two it takes here.Quoted 8 lines
The
gitdirfunction is called 13 times during startup alone, and who knows how many more times later.So I am quite convinced that the original intention was to save on spawning processes left and right.
But since you are the Git GUI maintainer, and this was your suggestion, I made it so.
Yes, I am the maintainer, but I am not an all-knowing, all-seeing entity. Your, and every other contributors, suggestions are very valuable. And my suggestions aren't gospel. I would hate to see someone send in a patch they weren't sure was the best thing to do just because I suggested it. Please feel free to object my suggestions.
In this case, I didn't expect gitdir to be called this many times.
While I don't notice much of a performance difference on my system (Linux), a quick measurement tells me that the time spent in gitdir is about 16 ms. In contrast, the same measurement without the v2 patch gives out 0 ms (IOW, very fast). 16 ms sounds a bit much for something so simple. It might not be the same for everyone else. AFAIK, spawning a process is much slower on Windows.
So now I'm not so sure my suggestion was a good one. My original aim was to be sure everything was correct, and no incorrect directories were being used. But the current solution comes at a performance hit.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
We could either maintain a blacklist, for what we cache the result too, or always call "git rev-parse --git-dir".
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This blacklist would need to be in sync with the one in Git's
path.c::adjust_git_path()than.Bert's suggestion seems like a decent compromise. We run
git rev-parse --git-pathfor the paths in the blacklist, and for the rest we use the cached value. This does run the risk of getting out of sync with git.git's list, but it might be better than spawing a process every time, and is very likely better than just doing it for hooks.
But what about this part of that function?
-- snip --
else if (repo->different_commondir)
update_common_dir(buf, git_dir_len, repo->commondir);
-- snap --
It might well turn out that this blacklist is neither easy to implement nor will it help much.
So let's look at all the call sites:
-- snip --
$ git grep -w gitdir | sed -ne 's|\].*||' -e 's|.*\[gitdir ||p' | sort | uniq
$file
$name
CHERRY_PICK_HEAD
FETCH_HEAD
GITGUI_BCK
GITGUI_EDITMSG
GITGUI_MSG
HEAD
hooks $hook_name
index.lock
info exclude
logs $name
MERGE_HEAD
MERGE_MSG
MERGE_RR
objects 4\[0-[expr {$ndirs-1}
objects info
objects info alternates
objects pack
packed-refs
PREPARE_COMMIT_MSG
rebase-merge head-name
remotes
remotes $r
rr-cache
rr-cache MERGE_RR
SQUASH_MSG
-- snap --The $file call looks for messages (probably commit, merge, tag messages and the likes), the $name one looks for refs.
Some of those arguments strike me as very good candidates to require the common directory while others require the real gitdir (remember, commondir != gitdir in worktrees other than the main worktree).
What _could_ be done (but we're certainly threatening to enter the realm of the ridiculous here) is to call git rev-parse --git-dir --git-path CHERRY_PICK_HEAD --git-path FETCH_HEAD [...], which will output one path per line, and then store the result in an associative array
(https://tcl.tk/man/tcl8.5/tutorial/Tcl22.html), and use that to look up paths based on their first component, caching as we go.
Something like this:
-- snipsnap --
git-gui.sh +42 -3
@@ -158,6 +158,7 @@ if {[tk windowingsystem] eq "aqua"} { set _appname {Git Gui} set _gitdir {} +array set _gitdir_cached {} set _gitworktree {} set _isbare {} set _gitexec {}
@@ -197,12 +198,50 @@ proc appname {} { return $_appname } +proc init_gitdir_cached {} { + global _gitdir _gitdir_cached + + set gitdir_keys [list \ + CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \ + GITGUI_MSG HEAD hooks index.lock info logs MERGE_HEAD \ + MERGE_MSG MERGE_RR objects packed-refs PREPARE_COMMIT_MSG \ + rebase-merge head-name remotes rr-cache SQUASH_MSG \ + ] + + set gitdir_cmd [list git rev-parse --git-dir] + foreach key $gitdir_keys { + lappend gitdir_cmd --git-path $key + } + + set i -1 + foreach path [split [eval $gitdir_cmd] "\n"] { + if {$i eq -1} { + set _gitdir $path + } else { + set _gitdir_cached([lindex $gitdir_keys $i]) $path + } + incr i + } +} + proc gitdir {args} { - global _gitdir + global _gitdir _gitdir_cached + if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + + set arg0 [lindex $args 0] + set args [lrange $args 1 end] + if {![info exists _gitdir_cached($arg0)]} { + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set _gitdir_cached($arg0) [git rev-parse --git-path $arg0] + } else { + set _gitdir_cached($arg0) [file join $_gitdir $arg0] + } + } + + return [eval [concat [list file join $_gitdir_cached($arg0)] $args]] } proc gitexec {args} {
@@ -1242,7 +1281,7 @@ if {[catch { && [catch { # beware that from the .git dir this sets _gitdir to . # and _prefix to the empty string - set _gitdir [git rev-parse --git-dir] + init_gitdir_cached set _prefix [git rev-parse --show-prefix] } err]} { load_config 1
Re: [PATCH 1/1] respect core.hooksPath, falling back to .git/hooks
Quoted 54 lines · Johannes Schindelin
Hi,
Quoted 41 lines · Pratyush Yadav
Quoted 9 lines · Johannes Schindelin
Quoted 7 lines · Pratyush Yadav
Quoted 6 lines · Bert Wesarg
Quoted 5 lines · Pratyush Yadav
gitdir is used in a lot of places, and I think all those would also
benefit from using --git-path. So I think it is a better idea to move this to the procedure gitdir. It would have to be refactored to take any number of arguments, instead of the two it takes here.Quoted 8 lines
The
gitdirfunction is called 13 times during startup alone, and who knows how many more times later.So I am quite convinced that the original intention was to save on spawning processes left and right.
But since you are the Git GUI maintainer, and this was your suggestion, I made it so.
Yes, I am the maintainer, but I am not an all-knowing, all-seeing entity. Your, and every other contributors, suggestions are very valuable. And my suggestions aren't gospel. I would hate to see someone send in a patch they weren't sure was the best thing to do just because I suggested it. Please feel free to object my suggestions.
In this case, I didn't expect gitdir to be called this many times.
While I don't notice much of a performance difference on my system (Linux), a quick measurement tells me that the time spent in gitdir is about 16 ms. In contrast, the same measurement without the v2 patch gives out 0 ms (IOW, very fast). 16 ms sounds a bit much for something so simple. It might not be the same for everyone else. AFAIK, spawning a process is much slower on Windows.
So now I'm not so sure my suggestion was a good one. My original aim was to be sure everything was correct, and no incorrect directories were being used. But the current solution comes at a performance hit.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
We could either maintain a blacklist, for what we cache the result too, or always call "git rev-parse --git-dir".
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This blacklist would need to be in sync with the one in Git's
path.c::adjust_git_path()than.Bert's suggestion seems like a decent compromise. We run
git rev-parse --git-pathfor the paths in the blacklist, and for the rest we use the cached value. This does run the risk of getting out of sync with git.git's list, but it might be better than spawing a process every time, and is very likely better than just doing it for hooks.
Quoted 6 lines
But what about this part of that function?
-- snip --
else if (repo->different_commondir)update_common_dir(buf, git_dir_len, repo->commondir);-- snap --
I'm afraid I'm a bit out of my depth on this. I have no idea what a "common directory" is, and how is it different from the "git directory". I can't find anything useful on Google about it. My guess is that it is something related to separate worktrees.
Quoted 2 lines
It might well turn out that this blacklist is neither easy to implement nor will it help much.
Am I correct in assuming that for other cases like "info", "grafts", "index", "objects", and "hooks" the blacklist would be simple to implement, and it is the "common directory" case that is problematic?
Quoted 33 lines
So let's look at all the call sites:
-- snip --
$ git grep -w gitdir | sed -ne 's|\].*||' -e 's|.*\[gitdir ||p' | sort | uniq $file $name CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG GITGUI_MSG HEAD hooks $hook_name index.lock info exclude logs $name MERGE_HEAD MERGE_MSG MERGE_RR objects 4\[0-[expr {$ndirs-1} objects info objects info alternates objects pack packed-refs PREPARE_COMMIT_MSG rebase-merge head-name remotes remotes $r rr-cache rr-cache MERGE_RR SQUASH_MSG -- snap --
Quoted 2 lines
The
$filecall looks for messages (probably commit, merge, tag messages and the likes), the$nameone looks for refs.
So they should always be inside the '.git' or GIT_DIR, correct?
Quoted 10 lines
Some of those arguments strike me as very good candidates to require the common directory while others require the real gitdir (remember, commondir != gitdir in worktrees other than the main worktree).
What _could_ be done (but we're certainly threatening to enter the realm of the ridiculous here) is to call
git rev-parse --git-dir --git-path CHERRY_PICK_HEAD --git-path FETCH_HEAD [...], which will output one path per line, and then store the result in an associative array
(https://tcl.tk/man/tcl8.5/tutorial/Tcl22.html), and use that to look up paths based on their first component, caching as we go.
Ah yes! That is certainly threatening to enter the realm of ridiculous. I'm not sure what benefit this will have. Right now, I don't think git-gui handles these cases. Have people complained? Is this a common problem?
I want to evaluate how much benefit we get doing something like this has over just using your original patch that works with hooks only.
Quoted 69 lines
Something like this:
-- snipsnap --
git-gui.sh +41
-2@@ -158,6 +158,7 @@ if {[tk windowingsystem] eq "aqua"} { set _appname {Git Gui} set _gitdir {} +array set _gitdir_cached {} set _gitworktree {} set _isbare {} set _gitexec {}@@ -197,12 +198,50 @@ proc appname {} { return $_appname } +proc init_gitdir_cached {} { + global _gitdir _gitdir_cached + + set gitdir_keys [list \ + CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \ + GITGUI_MSG HEAD hooks index.lock info logs MERGE_HEAD \ + MERGE_MSG MERGE_RR objects packed-refs PREPARE_COMMIT_MSG \ + rebase-merge head-name remotes rr-cache SQUASH_MSG \ + ] + + set gitdir_cmd [list git rev-parse --git-dir] + foreach key $gitdir_keys { + lappend gitdir_cmd --git-path $key + } + + set i -1 + foreach path [split [eval $gitdir_cmd] "\n"] { + if {$i eq -1} { + set _gitdir $path + } else { + set _gitdir_cached([lindex $gitdir_keys $i]) $path + } + incr i + } +} + proc gitdir {args} { - global _gitdir + global _gitdir _gitdir_cached + if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + + set arg0 [lindex $args 0] + set args [lrange $args 1 end] + if {![info exists _gitdir_cached($arg0)]} { + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set _gitdir_cached($arg0) [git rev-parse --git-path $arg0] + } else { + set _gitdir_cached($arg0) [file join $_gitdir $arg0] + } + } + + return [eval [concat [list file join $_gitdir_cached($arg0)] $args]] } proc gitexec {args} {
git-gui.sh if {[catch { · line 1287
Quoted 8 lines
git-gui.sh +1
-1@@ -1242,7 +1281,7 @@ if {[catch { && [catch { # beware that from the .git dir this sets _gitdir to . # and _prefix to the empty string - set _gitdir [git rev-parse --git-dir] + init_gitdir_cached set _prefix [git rev-parse --show-prefix] } err]} { load_config 1
A nice way of tackling this problem overall considering the challenges, but I'm worried about whether all this is _actually_ needed for real use cases, and what breaks if we don't.
Honestly, I'm not too sure how to tackle this problem. That is also the reason I took so long in writing this response. What would your suggestion be?
Also, if some other people interested in git-gui could chime in, it would be great.
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH 1/1] respect core.hooksPath, falling back to .git/hooks
Hi Pratyush,
Quoted 61 lines · Pratyush Yadav
Quoted 53 lines · Johannes Schindelin
Quoted 41 lines · Pratyush Yadav
Quoted 9 lines · Johannes Schindelin
Quoted 7 lines · Pratyush Yadav
Quoted 6 lines · Bert Wesarg
Quoted 5 lines · Pratyush Yadav
gitdir is used in a lot of places, and I think all those would also
benefit from using --git-path. So I think it is a better idea to move this to the procedure gitdir. It would have to be refactored to take any number of arguments, instead of the two it takes here.Quoted 8 lines
The
gitdirfunction is called 13 times during startup alone, and who knows how many more times later.So I am quite convinced that the original intention was to save on spawning processes left and right.
But since you are the Git GUI maintainer, and this was your suggestion, I made it so.
Yes, I am the maintainer, but I am not an all-knowing, all-seeing entity. Your, and every other contributors, suggestions are very valuable. And my suggestions aren't gospel. I would hate to see someone send in a patch they weren't sure was the best thing to do just because I suggested it. Please feel free to object my suggestions.
In this case, I didn't expect gitdir to be called this many times.
While I don't notice much of a performance difference on my system (Linux), a quick measurement tells me that the time spent in gitdir is about 16 ms. In contrast, the same measurement without the v2 patch gives out 0 ms (IOW, very fast). 16 ms sounds a bit much for something so simple. It might not be the same for everyone else. AFAIK, spawning a process is much slower on Windows.
So now I'm not so sure my suggestion was a good one. My original aim was to be sure everything was correct, and no incorrect directories were being used. But the current solution comes at a performance hit.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
We could either maintain a blacklist, for what we cache the result too, or always call "git rev-parse --git-dir".
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This blacklist would need to be in sync with the one in Git's
path.c::adjust_git_path()than.Bert's suggestion seems like a decent compromise. We run
git rev-parse --git-pathfor the paths in the blacklist, and for the rest we use the cached value. This does run the risk of getting out of sync with git.git's list, but it might be better than spawing a process every time, and is very likely better than just doing it for hooks.Quoted 6 lines
But what about this part of that function?
-- snip --
else if (repo->different_commondir)update_common_dir(buf, git_dir_len, repo->commondir);-- snap --
Quoted 4 lines
I'm afraid I'm a bit out of my depth on this. I have no idea what a "common directory" is, and how is it different from the "git directory". I can't find anything useful on Google about it. My guess is that it is something related to separate worktrees.
It is indeed related to worktrees. If you create a secondary worktree via git worktree add [...], that work tree will get its own git directory under .git/worktrees/<name> in the main worktree. That git directory will not, however, contain all contents of a regular git directory. Most refs, for example, are stored in the main worktree's git directory. That is what the "common dir" is.
Quoted 6 lines
Quoted 2 lines
It might well turn out that this blacklist is neither easy to implement nor will it help much.
Am I correct in assuming that for other cases like "info", "grafts", "index", "objects", and "hooks" the blacklist would be simple to implement, and it is the "common directory" case that is problematic?
Indeed, for the other, simple cases, the list would be unproblematic to implement. Problematic to maintain, though, especially given that Git GUI is _supposed_ to support even very old Git versions.
And those simple cases don't include _all_ interesting cases. Take logs/ for example. The git directory will contain the reflogs for HEAD, but unless you're on an unnamed branch (AKA "detached HEAD"), the reflogs for the current branch are _in the commondir_.
Quoted 33 lines
Quoted 33 lines
So let's look at all the call sites:
-- snip --
$ git grep -w gitdir | sed -ne 's|\].*||' -e 's|.*\[gitdir ||p' | sort | uniq $file $name CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG GITGUI_MSG HEAD hooks $hook_name index.lock info exclude logs $name MERGE_HEAD MERGE_MSG MERGE_RR objects 4\[0-[expr {$ndirs-1} objects info objects info alternates objects pack packed-refs PREPARE_COMMIT_MSG rebase-merge head-name remotes remotes $r rr-cache rr-cache MERGE_RR SQUASH_MSG -- snap --
Quoted 4 lines
Quoted 2 lines
The
$filecall looks for messages (probably commit, merge, tag messages and the likes), the$nameone looks for refs.So they should always be inside the '.git' or
GIT_DIR, correct?
They should be inside the git directory. Note that .git in worktrees is just a file that contains gitdir: <path>. The indicated path is the actual git directory. Inside that git directory, the file commondir contains the path to the main worktree's git directory.
Quoted 11 lines
Quoted 10 lines
Some of those arguments strike me as very good candidates to require the common directory while others require the real gitdir (remember, commondir != gitdir in worktrees other than the main worktree).
What _could_ be done (but we're certainly threatening to enter the realm of the ridiculous here) is to call
git rev-parse --git-dir --git-path CHERRY_PICK_HEAD --git-path FETCH_HEAD [...], which will output one path per line, and then store the result in an associative array
(https://tcl.tk/man/tcl8.5/tutorial/Tcl22.html), and use that to look up paths based on their first component, caching as we go.
Quoted 4 lines
Ah yes! That is certainly threatening to enter the realm of ridiculous. I'm not sure what benefit this will have. Right now, I don't think git-gui handles these cases. Have people complained? Is this a common problem?
Well, we know that people complained about the hooks directory. And that did not even involve worktrees.
I see that e.g. packed-refs is queried by Git GUI. And that file lives in the main worktree's git directory, i.e. in the commondir.
So either users don't use Git GUI in secondary worktrees, or they did not even notice the bug.
Quoted 2 lines
I want to evaluate how much benefit we get doing something like this has over just using your original patch that works with hooks only.
Since I already have that ridiculous approach essentially implemented, and since it fixes very real bugs in Git GUI ever since git worktree was introduced, I'd say that you'd be better off taking the ridiculous patch than not.
Quoted 67 lines
Quoted 67 lines
Something like this:
-- snipsnap --
git-gui.sh +41
-2@@ -158,6 +158,7 @@ if {[tk windowingsystem] eq "aqua"} { set _appname {Git Gui} set _gitdir {} +array set _gitdir_cached {} set _gitworktree {} set _isbare {} set _gitexec {}@@ -197,12 +198,50 @@ proc appname {} { return $_appname } +proc init_gitdir_cached {} { + global _gitdir _gitdir_cached + + set gitdir_keys [list \ + CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \ + GITGUI_MSG HEAD hooks index.lock info logs MERGE_HEAD \ + MERGE_MSG MERGE_RR objects packed-refs PREPARE_COMMIT_MSG \ + rebase-merge head-name remotes rr-cache SQUASH_MSG \ + ] + + set gitdir_cmd [list git rev-parse --git-dir] + foreach key $gitdir_keys { + lappend gitdir_cmd --git-path $key + } + + set i -1 + foreach path [split [eval $gitdir_cmd] "\n"] { + if {$i eq -1} { + set _gitdir $path + } else { + set _gitdir_cached([lindex $gitdir_keys $i]) $path + } + incr i + } +} + proc gitdir {args} { - global _gitdir + global _gitdir _gitdir_cached + if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + + set arg0 [lindex $args 0] + set args [lrange $args 1 end] + if {![info exists _gitdir_cached($arg0)]} { + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set _gitdir_cached($arg0) [git rev-parse --git-path $arg0] + } else { + set _gitdir_cached($arg0) [file join $_gitdir $arg0] + } + } + + return [eval [concat [list file join $_gitdir_cached($arg0)] $args]] }
Quoted 14 lines
git-gui.sh if {[catch { · line 1287
Quoted 10 lines
git-gui.sh +1
-1proc gitexec {args} {@@ -1242,7 +1281,7 @@ if {[catch { && [catch { # beware that from the .git dir this sets _gitdir to . # and _prefix to the empty string - set _gitdir [git rev-parse --git-dir] + init_gitdir_cached set _prefix [git rev-parse --show-prefix] } err]} { load_config 1A nice way of tackling this problem overall considering the challenges, but I'm worried about whether all this is _actually_ needed for real use cases, and what breaks if we don't.
Why don't you try using Git GUI in a worktree for a while? I am sure you will encounter the issues sooner or later.
Quoted 3 lines
Honestly, I'm not too sure how to tackle this problem. That is also the reason I took so long in writing this response. What would your suggestion be?
I would actually go for the ridiculous patch, as it provides the safest bet we have on fixing the gitdir-related bugs.
Quoted 2 lines
Also, if some other people interested in git-gui could chime in, it would be great.
Sure.
Ciao,
Johannes
PATCH v3 1/1 Fix gitdir e.g. to respect core.hooksPath
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the --git-path option respects that config variable, too, so we may just as well use that command.
For Git versions older than v2.5.0 (which was the first version to support the --git-path option for the rev-parse command), we simply fall back to the previous code.
An original patch handled only the hooksPath setting, however, during the code submission it was deemed better to fix all call to the gitdir function.
To avoid spawning a gazillion git rev-parse --git-path instances, we cache the returned paths, priming the cache upon startup in a single git rev-parse invocation with the known entries.
This fixes https://github.com/git-for-windows/git/issues/1755
--- git-gui.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-)
git-gui.sh +49 -3
@@ -158,6 +158,7 @@ if {[tk windowingsystem] eq "aqua"} { set _appname {Git Gui} set _gitdir {} +array set _gitdir_cache {} set _gitworktree {} set _isbare {} set _gitexec {}
@@ -197,12 +198,57 @@ proc appname {} { return $_appname } +proc prime_gitdir_cache {} { + global _gitdir _gitdir_cache + + set gitdir_cmd [list git rev-parse --git-dir] + + # `--git-path` is only supported since Git v2.5.0 + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set gitdir_keys [list \ + CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \ + GITGUI_MSG HEAD hooks hooks/prepare-commit-msg \ + index.lock info info/exclude logs MERGE_HEAD MERGE_MSG \ + MERGE_RR objects "objects/4\[0-1\]/*" \ + "objects/4\[0-3\]/*" objects/info \ + objects/info/alternates objects/pack packed-refs \ + PREPARE_COMMIT_MSG rebase-merge/head-name remotes \ + rr-cache rr-cache/MERGE_RR SQUASH_MSG \ + ] + + foreach key $gitdir_keys { + lappend gitdir_cmd --git-path $key + } + } + + set i -1 + foreach path [split [eval $gitdir_cmd] "\n"] { + if {$i eq -1} { + set _gitdir $path + } else { + set _gitdir_cache([lindex $gitdir_keys $i]) $path + } + incr i + } +} + proc gitdir {args} { - global _gitdir + global _gitdir _gitdir_cache + if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + + set args [eval [list file join] $args] + if {![info exists _gitdir_cache($args)]} { + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set _gitdir_cache($args) [git rev-parse --git-path $args] + } else { + set _gitdir_cache($args) [file join $_gitdir $args] + } + } + + return $_gitdir_cache($args) } proc gitexec {args} {
@@ -1242,7 +1288,7 @@ if {[catch { && [catch { # beware that from the .git dir this sets _gitdir to . # and _prefix to the empty string - set _gitdir [git rev-parse --git-dir] + prime_gitdir_cache set _prefix [git rev-parse --show-prefix] } err]} { load_config 1
Signature · 1 line
gitgitgadget
v3 cover git-gui: respect core.hooksPath, falling back to .git/hooks
In reply to Johannes Schindelin via GitGitGadgetThis is yet another patch from Git for Windows.
Changes since v2:
* The paths returned by git rev-parse --git-path are now cached, and the cache is primed with the most common paths.
Changes since v1:
* Rather than a fine-grained override of gitdir just for the hooks path, we now spawn git rev-parse --git-path [...] every time gitdir is called with arguments. This makes the code safer, although at the cost of potentially many spawned processes.
Johannes Schindelin (1):
Fix gitdir e.g. to respect core.hooksPath
git-gui.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-)
base-commit: 60c60b627e81bf84e1cb01729d2ae882178f079d
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-361%2Fdscho%2Fgit-gui-hooks-path-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-361/dscho/git-gui-hooks-path-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/361
Range-diff vs v2:
1: c101422936 < -: ---------- respect core.hooksPath, falling back to .git/hooks -: ---------- > 1: 65c2fa33e1 Fix gitdir e.g. to respect core.hooksPath
Signature · 1 line
gitgitgadget
Re: [PATCH v3 1/1] Fix gitdir e.g. to respect core.hooksPath
In reply to Johannes Schindelin via GitGitGadgetHi Johannes,
Could you please change the commit subject to more clearly state that we are caching all paths. This is not something just related to hooks any more.
Quoted 13 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the
--git-pathoption respects that config variable, too, so we may just as well use that command.For Git versions older than v2.5.0 (which was the first version to support the
--git-pathoption for therev-parsecommand), we simply fall back to the previous code.
Quoted 7 lines
An original patch handled only the hooksPath setting, however, during the code submission it was deemed better to fix all call to the
gitdirfunction.To avoid spawning a gazillion
git rev-parse --git-pathinstances, we cache the returned paths, priming the cache upon startup in a singlegit rev-parse invocationwith the known entries.
I think it would also be a good idea to mention that we are fixing worktree paths not being correct.
Quoted 21 lines
This fixes https://github.com/git-for-windows/git/issues/1755
Initial-patch-by Philipp Gortan <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>--- git-gui.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-)git-gui.sh +1
-0@@ -158,6 +158,7 @@ if {[tk windowingsystem] eq "aqua"} { set _appname {Git Gui} set _gitdir {} +array set _gitdir_cache {} set _gitworktree {} set _isbare {} set _gitexec {}
git-gui.sh proc appname {} { · line 207
Quoted 10 lines
git-gui.sh +7
-0@@ -197,12 +198,57 @@ proc appname {} { return $_appname } +proc prime_gitdir_cache {} { + global _gitdir _gitdir_cache + + set gitdir_cmd [list git rev-parse --git-dir] + + # `--git-path` is only supported since Git v2.5.0 + if {[package vcompare $::_git_version 2.5.0] >= 0} {
I think we should mention the source of the list of "magic" keys. A comment mentioning this list came from looking at the common calls to gitdir in the rest of the git-gui code would explain this function to a future reader better.
Quoted 8 lines
git-gui.sh +8
-0+ set gitdir_keys [list \ + CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \ + GITGUI_MSG HEAD hooks hooks/prepare-commit-msg \ + index.lock info info/exclude logs MERGE_HEAD MERGE_MSG \ + MERGE_RR objects "objects/4\[0-1\]/*" \ + "objects/4\[0-3\]/*" objects/info \ + objects/info/alternates objects/pack packed-refs \ + PREPARE_COMMIT_MSG rebase-merge/head-name remotes \
git-gui.sh proc appname {} { · line 225
Quoted 10 lines
git-gui.sh +10
-0+ rr-cache rr-cache/MERGE_RR SQUASH_MSG \ + ] + + foreach key $gitdir_keys { + lappend gitdir_cmd --git-path $key + } + } + + set i -1 + foreach path [split [eval $gitdir_cmd] "\n"] {
A call to the procedure 'git' is wrapped in a 'catch' in a lot of places. But it is also not wrapped in 'catch' in a lot of other places.
I'm not sure how something like this would fail, so I'm not sure if wrapping this call in a catch is a good idea. But it is something to consider.
Quoted 32 lines
git-gui.sh +22
-2+ if {$i eq -1} { + set _gitdir $path + } else { + set _gitdir_cache([lindex $gitdir_keys $i]) $path + } + incr i + } +} + proc gitdir {args} { - global _gitdir + global _gitdir _gitdir_cache + if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + + set args [eval [list file join] $args] + if {![info exists _gitdir_cache($args)]} { + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set _gitdir_cache($args) [git rev-parse --git-path $args] + } else { + set _gitdir_cache($args) [file join $_gitdir $args] + } + } + + return $_gitdir_cache($args) } proc gitexec {args} {
git-gui.sh if {[catch { · line 1294
Quoted 8 lines
git-gui.sh +1
-1@@ -1242,7 +1288,7 @@ if {[catch { && [catch { # beware that from the .git dir this sets _gitdir to . # and _prefix to the empty string - set _gitdir [git rev-parse --git-dir] + prime_gitdir_cache set _prefix [git rev-parse --show-prefix] } err]} { load_config 1
Can these paths we cache change while git-gui is running, say by a command run by the user in the terminal? In that case, we should refresh the list when the user rescans.
Other than some minor comments, looks good. Thanks.
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH v3 1/1] Fix gitdir e.g. to respect core.hooksPath
Hi Pratyush,
Quoted 3 lines · Pratyush Yadav
Could you please change the commit subject to more clearly state that we are caching all paths. This is not something just related to hooks any more.
It is related, but not exclusively so. Changed accordingly.
Quoted 18 lines · Johannes Schindelin via GitGitGadget
Quoted 17 lines
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the
--git-pathoption respects that config variable, too, so we may just as well use that command.For Git versions older than v2.5.0 (which was the first version to support the
--git-pathoption for therev-parsecommand), we simply fall back to the previous code.An original patch handled only the hooksPath setting, however, during the code submission it was deemed better to fix all call to the
gitdirfunction.
Quoted 6 lines
Quoted 3 lines
To avoid spawning a gazillion
git rev-parse --git-pathinstances, we cache the returned paths, priming the cache upon startup in a singlegit rev-parse invocationwith the known entries.I think it would also be a good idea to mention that we are fixing worktree paths not being correct.
Done.
Quoted 24 lines
Quoted 24 lines
This fixes https://github.com/git-for-windows/git/issues/1755
Initial-patch-by Philipp Gortan <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>--- git-gui.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-)git-gui.sh +1
-0@@ -158,6 +158,7 @@ if {[tk windowingsystem] eq "aqua"} { set _appname {Git Gui} set _gitdir {} +array set _gitdir_cache {} set _gitworktree {} set _isbare {} set _gitexec {}@@ -197,12 +198,57 @@ proc appname {} { return $_appname }
Quoted 12 lines
git-gui.sh proc appname {} { · line 207
Quoted 7 lines
git-gui.sh +7
-0+proc prime_gitdir_cache {} { + global _gitdir _gitdir_cache + + set gitdir_cmd [list git rev-parse --git-dir] + + # `--git-path` is only supported since Git v2.5.0 + if {[package vcompare $::_git_version 2.5.0] >= 0} {I think we should mention the source of the list of "magic" keys. A comment mentioning this list came from looking at the common calls to
gitdirin the rest of the git-gui code would explain this function to a future reader better.
Makes sense.
Quoted 22 lines
Quoted 8 lines
git-gui.sh +8
-0+ set gitdir_keys [list \ + CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \ + GITGUI_MSG HEAD hooks hooks/prepare-commit-msg \ + index.lock info info/exclude logs MERGE_HEAD MERGE_MSG \ + MERGE_RR objects "objects/4\[0-1\]/*" \ + "objects/4\[0-3\]/*" objects/info \ + objects/info/alternates objects/pack packed-refs \ + PREPARE_COMMIT_MSG rebase-merge/head-name remotes \git-gui.sh proc appname {} { · line 225
Quoted 10 lines
git-gui.sh +10
-0+ rr-cache rr-cache/MERGE_RR SQUASH_MSG \ + ] + + foreach key $gitdir_keys { + lappend gitdir_cmd --git-path $key + } + } + + set i -1 + foreach path [split [eval $gitdir_cmd] "\n"] {A call to the procedure 'git' is wrapped in a 'catch' in a lot of places. But it is also not wrapped in 'catch' in a lot of other places.
Quoted 3 lines
I'm not sure how something like this would fail, so I'm not sure if wrapping this call in a catch is a good idea. But it is something to consider.
If that call fails, we lack a gitdir, which is a rather fundamental prerequisite to running Git GUI. I'd rather show an (ugly, but also highly unexpected) exception.
In other words, I think the patch should stay "catch-less".
Quoted 30 lines
Quoted 30 lines
git-gui.sh +22
-2+ if {$i eq -1} { + set _gitdir $path + } else { + set _gitdir_cache([lindex $gitdir_keys $i]) $path + } + incr i + } +} + proc gitdir {args} { - global _gitdir + global _gitdir _gitdir_cache + if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + + set args [eval [list file join] $args] + if {![info exists _gitdir_cache($args)]} { + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set _gitdir_cache($args) [git rev-parse --git-path $args] + } else { + set _gitdir_cache($args) [file join $_gitdir $args] + } + } + + return $_gitdir_cache($args) }
Quoted 14 lines
git-gui.sh if {[catch { · line 1294
Quoted 10 lines
git-gui.sh +1
-1proc gitexec {args} {@@ -1242,7 +1288,7 @@ if {[catch { && [catch { # beware that from the .git dir this sets _gitdir to . # and _prefix to the empty string - set _gitdir [git rev-parse --git-dir] + prime_gitdir_cache set _prefix [git rev-parse --show-prefix] } err]} { load_config 1Can these paths we cache change while git-gui is running, say by a command run by the user in the terminal? In that case, we should refresh the list when the user rescans.
I guess it can. A user could configure core.hooksPath while Git GUI is open, after all. Or rewrite the .git file of a worktree.
I won't touch the .git file part, but I changed the rescan code to re-prime the gitdir cache.
Thanks for the review,
Johannes
Quoted 7 lines
Other than some minor comments, looks good. Thanks.
--
Regards,
Pratyush Yadav
v4 cover git-gui: respect core.hooksPath, falling back to .git/hooks
In reply to Johannes Schindelin via GitGitGadgetThis is yet another patch from Git for Windows.
Changes since v3:
* Adjusted the commit message to reflect that this is no longer only about the hooks directory.
* Added a code comment to indicate how the list of keys was determined that are used for the gitdir priming.
* The gitdir cache is now re-primed upon F5.
Changes since v2:
* The paths returned by git rev-parse --git-path are now cached, and the cache is primed with the most common paths.
Changes since v1:
* Rather than a fine-grained override of gitdir just for the hooks path, we now spawn git rev-parse --git-path [...] every time gitdir is called with arguments. This makes the code safer, although at the cost of potentially many spawned processes.
Johannes Schindelin (1):
Make gitdir work with worktrees, respect core.hooksPath, etc
git-gui.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-)
base-commit: 60c60b627e81bf84e1cb01729d2ae882178f079d
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-361%2Fdscho%2Fgit-gui-hooks-path-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-361/dscho/git-gui-hooks-path-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/361
Range-diff vs v3:
1: 65c2fa33e1 ! 1: 2f55d6fb2a Fix gitdir e.g. to respect core.hooksPath
@@ -1,17 +1,21 @@
Author: Johannes Schindelin <[email protected]>
- Fix gitdir e.g. to respect core.hooksPath
+ Make gitdir work with worktrees, respect core.hooksPath, etc
- Since v2.9.0, Git knows about the config variable core.hookspath
- that allows overriding the path to the directory containing the
- Git hooks.
+ Since v2.9.0, Git knows about the config variable core.hookspath that
+ allows overriding the path to the directory containing the Git hooks.
- Since v2.10.0, the --git-path option respects that config
- variable, too, so we may just as well use that command.
+ Since v2.10.0, the --git-path option respects that config variable,
+ too, so we may just as well use that command.
+
+ Other paths inside .git are equally subject to differ from
+ <gitdir>/<path>, i.e. inside worktrees, where _some_ paths live in the
+ "gitdir" and some live in the "commondir" (i.e. the "gitdir" of the main
+ worktree).
For Git versions older than v2.5.0 (which was the first version to
- support the --git-path option for the rev-parse command), we
- simply fall back to the previous code.
+ support the --git-path option for the rev-parse command), we simply
+ fall back to the previous code.
An original patch handled only the hooksPath setting, however, during the code submission it was deemed better to fix all call to the gitdir
@@ -19,7 +23,9 @@
To avoid spawning a gazillion git rev-parse --git-path instances, we cache the returned paths, priming the cache upon startup in a single
- git rev-parse invocation with the known entries.
+ git rev-parse invocation with some paths (that have been
+ determined via a typical startup and via grepping the source code for
+ calls to the gitdir function).
This fixes https://github.com/git-for-windows/git/issues/1755
@@ -48,6 +54,8 @@
+
+ # --git-path is only supported since Git v2.5.0
+ if {[package vcompare $::_git_version 2.5.0] >= 0} {
++ # This list was generated from a typical startup as well as from
++ # grepping through Git GUI's source code.
+ set gitdir_keys [list \
+ CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \
+ GITGUI_MSG HEAD hooks hooks/prepare-commit-msg \
@@ -106,3 +114,21 @@
set _prefix [git rev-parse --show-prefix]
} err]} {
load_config 1
+@@
+ global HEAD PARENT MERGE_HEAD commit_type
+ global ui_index ui_workdir ui_comm
+ global rescan_active file_states
+- global repo_config
++ global repo_config _gitdir_cache
+
+ if {$rescan_active > 0 || ![lock_index read]} return
+
++ # Only re-prime gitdir cache on a full rescan
++ if {$after ne "ui_ready"} {
++ array unset _gitdir_cache
++ prime_gitdir_cache
++ }
++
+ repository_state newType newHEAD newMERGE_HEAD
+ if {[string match amend* $commit_type]
+ && $newType eq {normal}
Signature · 1 line
gitgitgadget
PATCH v4 1/1 Make gitdir work with worktrees, respect core.hooksPath, etc
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the --git-path option respects that config variable, too, so we may just as well use that command.
Other paths inside .git are equally subject to differ from <gitdir>/<path>, i.e. inside worktrees, where _some_ paths live in the "gitdir" and some live in the "commondir" (i.e. the "gitdir" of the main worktree).
For Git versions older than v2.5.0 (which was the first version to support the --git-path option for the rev-parse command), we simply fall back to the previous code.
An original patch handled only the hooksPath setting, however, during the code submission it was deemed better to fix all call to the gitdir function.
To avoid spawning a gazillion git rev-parse --git-path instances, we cache the returned paths, priming the cache upon startup in a single git rev-parse invocation with some paths (that have been determined via a typical startup and via grepping the source code for calls to the gitdir function).
This fixes https://github.com/git-for-windows/git/issues/1755
--- git-gui.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-)
git-gui.sh +58 -4
@@ -158,6 +158,7 @@ if {[tk windowingsystem] eq "aqua"} { set _appname {Git Gui} set _gitdir {} +array set _gitdir_cache {} set _gitworktree {} set _isbare {} set _gitexec {}
@@ -197,12 +198,59 @@ proc appname {} { return $_appname } +proc prime_gitdir_cache {} { + global _gitdir _gitdir_cache + + set gitdir_cmd [list git rev-parse --git-dir] + + # `--git-path` is only supported since Git v2.5.0 + if {[package vcompare $::_git_version 2.5.0] >= 0} { + # This list was generated from a typical startup as well as from + # grepping through Git GUI's source code. + set gitdir_keys [list \ + CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \ + GITGUI_MSG HEAD hooks hooks/prepare-commit-msg \ + index.lock info info/exclude logs MERGE_HEAD MERGE_MSG \ + MERGE_RR objects "objects/4\[0-1\]/*" \ + "objects/4\[0-3\]/*" objects/info \ + objects/info/alternates objects/pack packed-refs \ + PREPARE_COMMIT_MSG rebase-merge/head-name remotes \ + rr-cache rr-cache/MERGE_RR SQUASH_MSG \ + ] + + foreach key $gitdir_keys { + lappend gitdir_cmd --git-path $key + } + } + + set i -1 + foreach path [split [eval $gitdir_cmd] "\n"] { + if {$i eq -1} { + set _gitdir $path + } else { + set _gitdir_cache([lindex $gitdir_keys $i]) $path + } + incr i + } +} + proc gitdir {args} { - global _gitdir + global _gitdir _gitdir_cache + if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + + set args [eval [list file join] $args] + if {![info exists _gitdir_cache($args)]} { + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set _gitdir_cache($args) [git rev-parse --git-path $args] + } else { + set _gitdir_cache($args) [file join $_gitdir $args] + } + } + + return $_gitdir_cache($args) } proc gitexec {args} {
@@ -1242,7 +1290,7 @@ if {[catch { && [catch { # beware that from the .git dir this sets _gitdir to . # and _prefix to the empty string - set _gitdir [git rev-parse --git-dir] + prime_gitdir_cache set _prefix [git rev-parse --show-prefix] } err]} { load_config 1
@@ -1453,10 +1501,16 @@ proc rescan {after {honor_trustmtime 1}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm global rescan_active file_states - global repo_config + global repo_config _gitdir_cache if {$rescan_active > 0 || ![lock_index read]} return + # Only re-prime gitdir cache on a full rescan + if {$after ne "ui_ready"} { + array unset _gitdir_cache + prime_gitdir_cache + } + repository_state newType newHEAD newMERGE_HEAD if {[string match amend* $commit_type] && $newType eq {normal}
Signature · 1 line
gitgitgadget
Re: [PATCH v4 1/1] Make gitdir work with worktrees, respect core.hooksPath, etc
Hi Johannes,
Thanks for the re-roll. Some comments below...
Quoted 110 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Since v2.9.0, Git knows about the config variable core.hookspath that allows overriding the path to the directory containing the Git hooks.
Since v2.10.0, the
--git-pathoption respects that config variable, too, so we may just as well use that command.Other paths inside
.gitare equally subject to differ from<gitdir>/<path>, i.e. inside worktrees, where _some_ paths live in the "gitdir" and some live in the "commondir" (i.e. the "gitdir" of the main worktree).For Git versions older than v2.5.0 (which was the first version to support the
--git-pathoption for therev-parsecommand), we simply fall back to the previous code.An original patch handled only the hooksPath setting, however, during the code submission it was deemed better to fix all call to the
gitdirfunction.To avoid spawning a gazillion
git rev-parse --git-pathinstances, we cache the returned paths, priming the cache upon startup in a singlegit rev-parse invocationwith some paths (that have been determined via a typical startup and via grepping the source code for calls to thegitdirfunction).This fixes https://github.com/git-for-windows/git/issues/1755
Initial-patch-by Philipp Gortan <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>--- git-gui.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-)git-gui.sh +50
-2@@ -158,6 +158,7 @@ if {[tk windowingsystem] eq "aqua"} { set _appname {Git Gui} set _gitdir {} +array set _gitdir_cache {} set _gitworktree {} set _isbare {} set _gitexec {}@@ -197,12 +198,59 @@ proc appname {} { return $_appname } +proc prime_gitdir_cache {} { + global _gitdir _gitdir_cache + + set gitdir_cmd [list git rev-parse --git-dir] + + # `--git-path` is only supported since Git v2.5.0 + if {[package vcompare $::_git_version 2.5.0] >= 0} { + # This list was generated from a typical startup as well as from + # grepping through Git GUI's source code. + set gitdir_keys [list \ + CHERRY_PICK_HEAD FETCH_HEAD GITGUI_BCK GITGUI_EDITMSG \ + GITGUI_MSG HEAD hooks hooks/prepare-commit-msg \ + index.lock info info/exclude logs MERGE_HEAD MERGE_MSG \ + MERGE_RR objects "objects/4\[0-1\]/*" \ + "objects/4\[0-3\]/*" objects/info \ + objects/info/alternates objects/pack packed-refs \ + PREPARE_COMMIT_MSG rebase-merge/head-name remotes \ + rr-cache rr-cache/MERGE_RR SQUASH_MSG \ + ] + + foreach key $gitdir_keys { + lappend gitdir_cmd --git-path $key + } + } + + set i -1 + foreach path [split [eval $gitdir_cmd] "\n"] { + if {$i eq -1} { + set _gitdir $path + } else { + set _gitdir_cache([lindex $gitdir_keys $i]) $path + } + incr i + } +} + proc gitdir {args} { - global _gitdir + global _gitdir _gitdir_cache + if {$args eq {}} { return $_gitdir } - return [eval [list file join $_gitdir] $args] + + set args [eval [list file join] $args] + if {![info exists _gitdir_cache($args)]} { + if {[package vcompare $::_git_version 2.5.0] >= 0} { + set _gitdir_cache($args) [git rev-parse --git-path $args] + } else { + set _gitdir_cache($args) [file join $_gitdir $args] + } + } + + return $_gitdir_cache($args) } proc gitexec {args} {
git-gui.sh if {[catch { · line 1296
Quoted 8 lines
git-gui.sh +1
-1@@ -1242,7 +1290,7 @@ if {[catch { && [catch { # beware that from the .git dir this sets _gitdir to . # and _prefix to the empty string - set _gitdir [git rev-parse --git-dir] + prime_gitdir_cache set _prefix [git rev-parse --show-prefix] } err]} { load_config 1
Looks good till here.
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1509
Quoted 11 lines
git-gui.sh +3
-1@@ -1453,10 +1501,16 @@ proc rescan {after {honor_trustmtime 1}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm global rescan_active file_states - global repo_config + global repo_config _gitdir_cache if {$rescan_active > 0 || ![lock_index read]} return + # Only re-prime gitdir cache on a full rescan + if {$after ne "ui_ready"} {
What do you mean by a "full rescan"? I assume you use it as the differentiator between ui_do_rescan (called when you hit F5 or choose rescan from the menu) and do_rescan (called when you revert a line or hunk), and a "full rescan" refers to ui_do_rescan.
Well in that case, this check is incorrect. do_rescan passes only "ui_ready" and ui_do_rescan passes "force_first_diff ui_ready".
But either way, I'm not a big fan of this. This check makes assumptions about the behaviour of its callers based on what they pass to $after. The way I see it, $after should be a black box to rescan, and it should make absolutely no assumptions about it.
Doing it this way is really brittle, and would break as soon as someone changes the behaviour of ui_do_rescan. If someone in the future passes a different value in $after, this would stop working as intended and would not refresh the cached list on a rescan.
So, I think a better place for this if statement would be in ui_do_rescan. This would mean adding a new function that does this. But if we unset _gitdir_cache in prime_gitdir_cache (I see no reason not to), we can get away with just something like:
proc ui_do_rescan {} {
rescan {prime_gitdir_cache; ui_ready}
}Though since prime_gitdir_cache does not really depend on the rescan being finished, something like this would also work fine:
proc ui_do_rescan {} {
rescan ui_ready
prime_gitdir_cache
}This would allow us to do these two things in parallel since rescan is asynchronous. But that would also mean it is possible that the status bar would show "Ready" while prime_gitdir_cache is still executing.
I can't really make up my mind on what is better. I'm inclining on using the latter way, effectively trading a bit of UI inconsistency for performance (at least in theory).
Thoughts?
Quoted 7 lines
git-gui.sh +4
-0+ array unset _gitdir_cache + prime_gitdir_cache + } + repository_state newType newHEAD newMERGE_HEAD if {[string match amend* $commit_type] && $newType eq {normal}
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH v4 1/1] Make gitdir work with worktrees, respect core.hooksPath, etc
Hi Pratyush,
Quoted 41 lines · Pratyush Yadav
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1509
Quoted 11 lines · Johannes Schindelin via GitGitGadget
git-gui.sh +3
-1@@ -1453,10 +1501,16 @@ proc rescan {after {honor_trustmtime 1}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm global rescan_active file_states - global repo_config + global repo_config _gitdir_cache if {$rescan_active > 0 || ![lock_index read]} return + # Only re-prime gitdir cache on a full rescan + if {$after ne "ui_ready"} {What do you mean by a "full rescan"? I assume you use it as the differentiator between
ui_do_rescan(called when you hit F5 or choose rescan from the menu) anddo_rescan(called when you revert a line or hunk), and a "full rescan" refers toui_do_rescan.Well in that case, this check is incorrect.
do_rescanpasses only "ui_ready" andui_do_rescanpasses "force_first_diffui_ready".But either way, I'm not a big fan of this. This check makes assumptions about the behaviour of its callers based on what they pass to $after. The way I see it, $after should be a black box to
rescan, and it should make absolutely no assumptions about it.Doing it this way is really brittle, and would break as soon as someone changes the behaviour of
ui_do_rescan. If someone in the future passes a different value in $after, this would stop working as intended and would not refresh the cached list on a rescan.So, I think a better place for this if statement would be in
ui_do_rescan. This would mean adding a new function that does this. But if we unset_gitdir_cacheinprime_gitdir_cache(I see no reason not to), we can get away with just something like:proc ui_do_rescan {} { rescan {prime_gitdir_cache; ui_ready} }
Quoted 7 lines
Though since
prime_gitdir_cachedoes not really depend on the rescan being finished, something like this would also work fine:proc ui_do_rescan {} { rescan ui_ready prime_gitdir_cache }
That was my first attempt. However, there is a very important piece of code that is even still quoted above: that if {$rescan_active > 0 || ![lock_index read]} return part.
I do _not_ want to interfere with an actively-going-on rescan. If there is an active one, I don't want to re-prime the _gitdir cache.
That was the reason why I put the additional code into rescan rather than into ui_do_rescan().
Ciao,
Johannes
Quoted 23 lines
This would allow us to do these two things in parallel since
rescanis asynchronous. But that would also mean it is possible that the status bar would show "Ready" whileprime_gitdir_cacheis still executing.I can't really make up my mind on what is better. I'm inclining on using the latter way, effectively trading a bit of UI inconsistency for performance (at least in theory).
Thoughts?
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1516
Quoted 7 lines
git-gui.sh +4
-0+ array unset _gitdir_cache + prime_gitdir_cache + } + repository_state newType newHEAD newMERGE_HEAD if {[string match amend* $commit_type] && $newType eq {normal}--
Regards,
Pratyush Yadav
Re: [PATCH v4 1/1] Make gitdir work with worktrees, respect core.hooksPath, etc
Quoted 53 lines · Johannes Schindelin
Hi Pratyush,
Quoted 41 lines · Pratyush Yadav
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1509
Quoted 11 lines · Johannes Schindelin via GitGitGadget
git-gui.sh +3
-1@@ -1453,10 +1501,16 @@ proc rescan {after {honor_trustmtime 1}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm global rescan_active file_states - global repo_config + global repo_config _gitdir_cache if {$rescan_active > 0 || ![lock_index read]} return + # Only re-prime gitdir cache on a full rescan + if {$after ne "ui_ready"} {What do you mean by a "full rescan"? I assume you use it as the differentiator between
ui_do_rescan(called when you hit F5 or choose rescan from the menu) anddo_rescan(called when you revert a line or hunk), and a "full rescan" refers toui_do_rescan.Well in that case, this check is incorrect.
do_rescanpasses only "ui_ready" andui_do_rescanpasses "force_first_diffui_ready".But either way, I'm not a big fan of this. This check makes assumptions about the behaviour of its callers based on what they pass to $after. The way I see it, $after should be a black box to
rescan, and it should make absolutely no assumptions about it.Doing it this way is really brittle, and would break as soon as someone changes the behaviour of
ui_do_rescan. If someone in the future passes a different value in $after, this would stop working as intended and would not refresh the cached list on a rescan.So, I think a better place for this if statement would be in
ui_do_rescan. This would mean adding a new function that does this. But if we unset_gitdir_cacheinprime_gitdir_cache(I see no reason not to), we can get away with just something like:proc ui_do_rescan {} { rescan {prime_gitdir_cache; ui_ready} }Quoted 7 lines
Though since
prime_gitdir_cachedoes not really depend on the rescan being finished, something like this would also work fine:proc ui_do_rescan {} { rescan ui_ready prime_gitdir_cache }
Quoted 6 lines
That was my first attempt. However, there is a very important piece of code that is even still quoted above: that
if {$rescan_active > 0 || ![lock_index read]} returnpart.I do _not_ want to interfere with an actively-going-on rescan. If there is an active one, I don't want to re-prime the
_gitdircache.
Good catch! In that case I suppose refreshing the cache in $after would be the way to go (IOW, the former of my two suggestions). Anything $after won't get executed if we return early from that check.
Quoted 24 lines
That was the reason why I put the additional code into
rescanrather than intoui_do_rescan().Ciao,
JohannesQuoted 18 lines
This would allow us to do these two things in parallel since
rescanis asynchronous. But that would also mean it is possible that the status bar would show "Ready" whileprime_gitdir_cacheis still executing.I can't really make up my mind on what is better. I'm inclining on using the latter way, effectively trading a bit of UI inconsistency for performance (at least in theory).
Thoughts?
Quoted 7 lines
git-gui.sh +4
-0+ array unset _gitdir_cache + prime_gitdir_cache + } + repository_state newType newHEAD newMERGE_HEAD if {[string match amend* $commit_type] && $newType eq {normal}
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH v4 1/1] Make gitdir work with worktrees, respect core.hooksPath, etc
Hi Pratyush,
Quoted 58 lines · Pratyush Yadav
Quoted 57 lines · Johannes Schindelin
Hi Pratyush,
Quoted 41 lines · Pratyush Yadav
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1509
Quoted 11 lines · Johannes Schindelin via GitGitGadget
git-gui.sh +3
-1@@ -1453,10 +1501,16 @@ proc rescan {after {honor_trustmtime 1}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm global rescan_active file_states - global repo_config + global repo_config _gitdir_cache if {$rescan_active > 0 || ![lock_index read]} return + # Only re-prime gitdir cache on a full rescan + if {$after ne "ui_ready"} {What do you mean by a "full rescan"? I assume you use it as the differentiator between
ui_do_rescan(called when you hit F5 or choose rescan from the menu) anddo_rescan(called when you revert a line or hunk), and a "full rescan" refers toui_do_rescan.Well in that case, this check is incorrect.
do_rescanpasses only "ui_ready" andui_do_rescanpasses "force_first_diffui_ready".But either way, I'm not a big fan of this. This check makes assumptions about the behaviour of its callers based on what they pass to $after. The way I see it, $after should be a black box to
rescan, and it should make absolutely no assumptions about it.Doing it this way is really brittle, and would break as soon as someone changes the behaviour of
ui_do_rescan. If someone in the future passes a different value in $after, this would stop working as intended and would not refresh the cached list on a rescan.So, I think a better place for this if statement would be in
ui_do_rescan. This would mean adding a new function that does this. But if we unset_gitdir_cacheinprime_gitdir_cache(I see no reason not to), we can get away with just something like:proc ui_do_rescan {} { rescan {prime_gitdir_cache; ui_ready} }Quoted 7 lines
Though since
prime_gitdir_cachedoes not really depend on the rescan being finished, something like this would also work fine:proc ui_do_rescan {} { rescan ui_ready prime_gitdir_cache }That was my first attempt. However, there is a very important piece of code that is even still quoted above: that
if {$rescan_active > 0 || ![lock_index read]} returnpart.
Quoted 6 lines
Quoted 2 lines
I do _not_ want to interfere with an actively-going-on rescan. If there is an active one, I don't want to re-prime the
_gitdircache.Good catch! In that case I suppose refreshing the cache in $after would be the way to go (IOW, the former of my two suggestions). Anything $after won't get executed if we return early from that check.
The obvious problem with that solution is that the _gitdir is reset _after_ the rescan. In my solution, it is reset _before_, as I have no idea how often the _gitdir values are used during a rescan (and if none of they were, I would like to be very cautious to prepare for a future where any of those _gitdir values _are_ used during a rescan).
So I am afraid that I find way too serious problems with both of your proposed alternatives.
Ciao,
Johannes
Quoted 31 lines
Quoted 18 lines
That was the reason why I put the additional code into
rescanrather than intoui_do_rescan().Ciao,
JohannesQuoted 11 lines
This would allow us to do these two things in parallel since
rescanis asynchronous. But that would also mean it is possible that the status bar would show "Ready" whileprime_gitdir_cacheis still executing.I can't really make up my mind on what is better. I'm inclining on using the latter way, effectively trading a bit of UI inconsistency for performance (at least in theory).
Thoughts?
Quoted 7 lines
Quoted 7 lines
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1516
Quoted 7 lines
git-gui.sh +4
-0+ array unset _gitdir_cache + prime_gitdir_cache + } + repository_state newType newHEAD newMERGE_HEAD if {[string match amend* $commit_type] && $newType eq {normal}--
Regards,
Pratyush Yadav
Re: [PATCH v4 1/1] Make gitdir work with worktrees, respect core.hooksPath, etc
In reply to Pratyush YadavHi Pratyush,
Quoted 57 lines · Pratyush Yadav
Quoted 56 lines · Johannes Schindelin
Quoted 41 lines · Pratyush Yadav
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1509
Quoted 11 lines · Johannes Schindelin via GitGitGadget
git-gui.sh +3
-1@@ -1453,10 +1501,16 @@ proc rescan {after {honor_trustmtime 1}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm global rescan_active file_states - global repo_config + global repo_config _gitdir_cache if {$rescan_active > 0 || ![lock_index read]} return + # Only re-prime gitdir cache on a full rescan + if {$after ne "ui_ready"} {What do you mean by a "full rescan"? I assume you use it as the differentiator between
ui_do_rescan(called when you hit F5 or choose rescan from the menu) anddo_rescan(called when you revert a line or hunk), and a "full rescan" refers toui_do_rescan.Well in that case, this check is incorrect.
do_rescanpasses only "ui_ready" andui_do_rescanpasses "force_first_diffui_ready".But either way, I'm not a big fan of this. This check makes assumptions about the behaviour of its callers based on what they pass to $after. The way I see it, $after should be a black box to
rescan, and it should make absolutely no assumptions about it.Doing it this way is really brittle, and would break as soon as someone changes the behaviour of
ui_do_rescan. If someone in the future passes a different value in $after, this would stop working as intended and would not refresh the cached list on a rescan.So, I think a better place for this if statement would be in
ui_do_rescan. This would mean adding a new function that does this. But if we unset_gitdir_cacheinprime_gitdir_cache(I see no reason not to), we can get away with just something like:proc ui_do_rescan {} { rescan {prime_gitdir_cache; ui_ready} }Quoted 7 lines
Though since
prime_gitdir_cachedoes not really depend on the rescan being finished, something like this would also work fine:proc ui_do_rescan {} { rescan ui_ready prime_gitdir_cache }That was my first attempt. However, there is a very important piece of code that is even still quoted above: that
if {$rescan_active > 0 || ![lock_index read]} returnpart.
Quoted 6 lines
Quoted 2 lines
I do _not_ want to interfere with an actively-going-on rescan. If there is an active one, I don't want to re-prime the
_gitdircache.Good catch! In that case I suppose refreshing the cache in $after would be the way to go (IOW, the former of my two suggestions). Anything $after won't get executed if we return early from that check.
But it also won't get executed before the actual rescan. Which is precisely what I tried to ensure.
Ciao,
Johannes
Quoted 30 lines
Quoted 18 lines
That was the reason why I put the additional code into
rescanrather than intoui_do_rescan().Ciao,
JohannesQuoted 11 lines
This would allow us to do these two things in parallel since
rescanis asynchronous. But that would also mean it is possible that the status bar would show "Ready" whileprime_gitdir_cacheis still executing.I can't really make up my mind on what is better. I'm inclining on using the latter way, effectively trading a bit of UI inconsistency for performance (at least in theory).
Thoughts?
Quoted 7 lines
Quoted 7 lines
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1516
Quoted 7 lines
git-gui.sh +4
-0+ array unset _gitdir_cache + prime_gitdir_cache + } + repository_state newType newHEAD newMERGE_HEAD if {[string match amend* $commit_type] && $newType eq {normal}--
Regards,
Pratyush Yadav
Re: [PATCH v4 1/1] Make gitdir work with worktrees, respect core.hooksPath, etc
In reply to Johannes SchindelinQuoted 69 lines · Johannes Schindelin
Hi Pratyush,
Quoted 58 lines · Pratyush Yadav
Quoted 57 lines · Johannes Schindelin
Hi Pratyush,
Quoted 41 lines · Pratyush Yadav
git-gui.sh proc rescan {after {honor_trustmtime 1}} { · line 1509
Quoted 11 lines · Johannes Schindelin via GitGitGadget
git-gui.sh +3
-1@@ -1453,10 +1501,16 @@ proc rescan {after {honor_trustmtime 1}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm global rescan_active file_states - global repo_config + global repo_config _gitdir_cache if {$rescan_active > 0 || ![lock_index read]} return + # Only re-prime gitdir cache on a full rescan + if {$after ne "ui_ready"} {What do you mean by a "full rescan"? I assume you use it as the differentiator between
ui_do_rescan(called when you hit F5 or choose rescan from the menu) anddo_rescan(called when you revert a line or hunk), and a "full rescan" refers toui_do_rescan.Well in that case, this check is incorrect.
do_rescanpasses only "ui_ready" andui_do_rescanpasses "force_first_diffui_ready".But either way, I'm not a big fan of this. This check makes assumptions about the behaviour of its callers based on what they pass to $after. The way I see it, $after should be a black box to
rescan, and it should make absolutely no assumptions about it.Doing it this way is really brittle, and would break as soon as someone changes the behaviour of
ui_do_rescan. If someone in the future passes a different value in $after, this would stop working as intended and would not refresh the cached list on a rescan.So, I think a better place for this if statement would be in
ui_do_rescan. This would mean adding a new function that does this. But if we unset_gitdir_cacheinprime_gitdir_cache(I see no reason not to), we can get away with just something like:proc ui_do_rescan {} { rescan {prime_gitdir_cache; ui_ready} }Quoted 7 lines
Though since
prime_gitdir_cachedoes not really depend on the rescan being finished, something like this would also work fine:proc ui_do_rescan {} { rescan ui_ready prime_gitdir_cache }That was my first attempt. However, there is a very important piece of code that is even still quoted above: that
if {$rescan_active > 0 || ![lock_index read]} returnpart.Quoted 6 lines
Quoted 2 lines
I do _not_ want to interfere with an actively-going-on rescan. If there is an active one, I don't want to re-prime the
_gitdircache.Good catch! In that case I suppose refreshing the cache in $after would be the way to go (IOW, the former of my two suggestions). Anything $after won't get executed if we return early from that check.
Quoted 5 lines
The obvious problem with that solution is that the
_gitdiris reset _after_ the rescan. In my solution, it is reset _before_, as I have no idea how often the_gitdirvalues are used during a rescan (and if none of they were, I would like to be very cautious to prepare for a future where any of those_gitdirvalues _are_ used during a rescan).
_gitdir values are used quite often during a rescan, so yes, this won't work.
Quoted 2 lines
So I am afraid that I find way too serious problems with both of your proposed alternatives.
One alternative I can see right now is adding another optional parameter to rescan that controls whether we refresh the gitdir cache or not. That parameter would default to 0/false. I'm not the biggest fan of something like this, but it might be the easiest way to do it given the constraints.
I also thought about trying to acquire the index lock in prime_gitdir_cache, but that could create a race on the lock between prime_gitdir_cache and rescan.
If you have any better ideas, I'm all ears, but otherwise, I maybe our best bet is to just go with adding an optional parameter to rescan.
Signature · 2 lines
Regards, Pratyush Yadav