Re: [PATCH v2 1/2] dir: consider worktree config in path recursion
From: Elijah Newren <hidden>
Date: 2022-05-24 14:29:26
On Wed, May 11, 2022 at 9:37 AM Junio C Hamano [off-list ref] wrote:
Goss Geppert [off-list ref] writes:quoted
diff --git a/dir.c b/dir.c index f2b0f24210..a1886e61a3 100644 --- a/dir.c +++ b/dir.c@@ -1893,9 +1893,31 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
[...]
quoted
+ real_gitdir = real_pathdup(the_repository->gitdir, 0);This function is repeatedly called during the traversal. How expensive is it to keep calling real_pathdup() on the constant the_repository->gitdir just in case it might be the same as our true GIT_DIR?
I agree that treat_directory is called many times, but this real_pathdup() call is inside the "if (nested_repo)" block, so this new real_pathdup() invocation should occur very seldom. Or are you worried about cases where users have *very* large numbers of bare repositories nested under the working directory? Even in that case, which seems pathological to me, I'd suspect the is_nonbare_repository_dir() -> read_gitfile_gently()/is_git_directory() codepath (used to determine the value of nested_repo) would be much more expensive than this call to real_pathdup(), so would it be worth trying to optimize this real_pathdup() call away even in that rare case?