Re: [PATCH v3 02/11] setup: introduce startup_info->original_cwd
- From
Elijah Newren <newren@gmail.com>
- Date
- Nov 27, 2021, 17:05 UTC
- Message-ID
- <CABPp-BFbmnvtUTW30KjWN6tQECjN=ErKC64oXrCLrb1OmXOZyQ@mail.gmail.com>
- In-Reply-To
- <211127.86zgpphohi.gmgdl@evledraar.gmail.com>
On Sat, Nov 27, 2021 at 2:39 AM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
Show 26 quoted lines
>
>
> On Fri, Nov 26 2021, Elijah Newren via GitGitGadget wrote:
>
> > From: Elijah Newren <newren@gmail.com>
> > [...]
> > + /*
> > + * Get our worktree; we only protect the current working directory
> > + * if it's in the worktree.
> > + */
> > + worktree = get_git_work_tree();
> > + if (!worktree)
> > + goto no_prevention_needed;
> > +
> > + offset = dir_inside_of(startup_info->original_cwd, worktree);
> > + if (offset >= 0) {
>
> Nit: Easier to read as:
>
> offset = [...]
> if (offset < 0)
> return;
>
> I.e. the reader can skip that whole "offset >= 0" block and anything
> after if it <0, which also reduces the indentation. We run into the
> "return' below.Whoops; the return should be inside the braces. I'll fix.
Show 16 quoted lines
> > + /* > > + * If startup_info->original_cwd == worktree, that is already > > + * protected and we don't need original_cwd as a secondary > > + * protection measure. > > + */ > > + if (!*(startup_info->original_cwd + offset)) > > + goto no_prevention_needed; > > + > > + /* > > + * original_cwd was inside worktree; precompose it just as > > + * we do prefix so that built up paths will match > > + */ > > + startup_info->original_cwd = \ > > TIL you can use backslashes like that in C outside of macros, but it's > not needed here, better without?
Line is too long without it, so better with it.
Show 5 quoted lines
> > > + precompose_string_if_needed(startup_info->original_cwd > > + + offset); > > + } > > + return;