From: Junio C Hamano Date: Tue, 22 Nov 2005 08:29:29 GMT Subject: Re: [PATCH 4/6] Add check_repo_format check for all major operations. Message-ID: <7vlkzhf5li.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <113261929333-git-send-email-matlads@dsmagic.com> Martin Atukunda writes: > The git-* command set uses 3 entry points in order to prepare > to work with a git repo: enter_repo, get_git_dir, and obviously > setup_git_directory. Thanks, but I think this one is wrong. > diff --git a/environment.c b/environment.c > index 6a961ca..458eff8 100644 > --- a/environment.c > +++ b/environment.c > @@ -37,6 +37,9 @@ static void setup_git_env(void) > git_graft_file = getenv(GRAFT_ENVIRONMENT); > if (!git_graft_file) > git_graft_file = strdup(git_path("info/grafts")); > + > + /* check the repo */ > + check_repo_format(); > } > diff --git a/setup.c b/setup.c > index 8597424..934f9a3 100644 > --- a/setup.c > +++ b/setup.c > @@ -97,6 +97,9 @@ const char *setup_git_directory(void) > static char cwd[PATH_MAX+1]; > int len, offset; > > + get_git_dir(1); > + check_repo_format(); > + > /* > * If GIT_DIR is set explicitly, we're not going > * to do any discovery In setup_git_env() you have only read GIT_DIR environment but have not done the toplevel discovery. Especially, this is called from get_git_dir(), and you call that as the first thing as setup_git_directory(). However, that function is supposed to be callable by processes that are in a subdirectory, without GIT_DIR explicitly specified, and the place get_git_dir() is called in that function is way before the discovery of the toplevel happens. Until then, you do not know where your .git/ directory or .git/config file is. If you start in Documentation subdirectory in git project, your setup_git_directory() would first call get_git_dir(), which says "I assume the config file is at ./.git/config -- oh there is no such thing". At that point you are checking Documentation/.git/config. It would happen to work because you intend to allow version 0 repository for any future version of tool, and even if this codepath mistakenly thinks the repository is version 0, it does not hurt, as long as your setup_git_directory() calls check_repo_format again after doing the toplevel discovery and checks the true .git/config file, but I do not think you have that call in the current series yet. Even if you had, this does not feel quite right to me.