Re: [PATCH v3 02/11] setup: introduce startup_info->original_cwd
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Nov 27, 2021, 10:35 UTC
- Message-ID
- <211127.86zgpphohi.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <200ddece05d3d0599b16897ff9533cdfb3324b0c.1637966463.git.gitgitgadget@gmail.com>
On Fri, Nov 26 2021, Elijah Newren via GitGitGadget wrote:
Show 12 quoted lines
> 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.
Show 13 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?
> + precompose_string_if_needed(startup_info->original_cwd > + + offset); > + } > + return;