Re: [PATCH v2 2/2] for-each-repo: work correctly in a worktree
- From
Jeff King <peff@peff.net>
- Date
- Feb 25, 2026, 13:13 UTC
- Message-ID
- <20260225131344.GA2139176@coredump.intra.peff.net>
- In-Reply-To
- <eeebc30a-40bf-40ac-a16b-ca5e128c3c01@gmail.com>
On Wed, Feb 25, 2026 at 06:44:51AM -0500, Derrick Stolee wrote:
Show 16 quoted lines
> > Looking at run-command.c:prep_childenv(), it seems that you can pass
> > "VAR=VAL" to "export VAR=VAL" in the child, and pass "VAR" to "unset
> > VAR" in the child.
>
> You're right. Here's a much simpler implementation:
>
> static int run_command_on_repo(const char *path, int argc, const char ** argv)
> {
> int i = 0;
> struct child_process child = CHILD_PROCESS_INIT;
> char *abspath = interpolate_path(path, 0);
>
> while (local_repo_env[i]) {
> strvec_push(&child.env, local_repo_env[i]);
> i++;
> }You can actually just use strvec_pushv() to do this as a one-liner (though annoyingly you need a cast because of how const works; you can easily find an example with grep).
But I really think you should consider keeping config-related variables in place, as prepare_other_repo_env() does. Otherwise something like:
git -c pack.threads=1 for-each-repo repack -ad
will ignore that config in the sub-processes (whereas it currently is respected).
And for that, you do need to loop yourself.
-Peff