Re: [PATCH v2 2/9] setup: introduce startup_info->original_cwd
- From
Elijah Newren <newren@gmail.com>
- Date
- Nov 29, 2021, 17:18 UTC
- Message-ID
- <CABPp-BHStJ2x53cffJPb7miaxL2cKr0usgK13HxNDyYMQv11_g@mail.gmail.com>
- In-Reply-To
- <48fced3c-1fcb-d5cd-cec0-b9e58be40259@gmail.com>
On Mon, Nov 29, 2021 at 6:05 AM Derrick Stolee <stolee@gmail.com> wrote:
Show 12 quoted lines
> > On 11/25/2021 3:39 AM, Elijah Newren via GitGitGadget wrote: > > From: Elijah Newren <newren@gmail.com> > > > @@ -866,6 +866,8 @@ int cmd_main(int argc, const char **argv) > > > > trace_command_performance(argv); > > > > + startup_info->original_cwd = xgetcwd(); > > + > > I see this initial assignment in cmd_main()...
It looks like you accidentally responded to v2 when there's a v3 (something I occasionally do too). v3 changes this to put it in common-main instead of here, as suggested by Ævar, but to answer the question...
Show 26 quoted lines
> > +static void setup_original_cwd(void)
> > +{
> > + struct strbuf tmp = STRBUF_INIT;
> > + const char *worktree = NULL;
> > + int offset = -1;
> > +
> > + /*
> > + * startup_info->original_cwd wass set early on in cmd_main(), unless
> > + * we're an auxiliary tool like git-remote-http or test-tool.
> > + */
> > + if (!startup_info->original_cwd)
> > + return;
>
> ...which is assumed to be run before this method was called...
>
> > @@ -1330,6 +1378,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
> > setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
> > }
> >
> > + setup_original_cwd();
>
> ...here in setup_git_directory_gently().
>
> Why do we need that assignment in cmd_main()? Could we instead
> let setup_original_cwd() do the initial assignment? Or is it
> possible that a chdir has happened already before this point?In v1, I made that mistake. Then I realized that when users pass the -C option to git, there is a chdir() call immediately upon parsing of the -C option. So I had to move the strbuf_getcwd() call earlier.