Skip to content

Commit 5f031fe

Browse files
derrickstoleegitster
authored andcommitted
run-command: extract sanitize_repo_env helper
The current prepare_other_repo_env() does two distinct things: 1. Strip certain known environment variables that should be set by a child process based on a different repository. 2. Set the GIT_DIR variable to avoid repository discovery. The second item is valuable for child processes that operate on submodules, where the repo discovery could be mistaken for the parent repository. In the next change, we will see an important case where only the first item is required as the GIT_DIR discovery should happen naturally from the '-C' parameter in the child process. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c5e62e1 commit 5f031fe

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

run-command.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ int run_auto_maintenance(int quiet)
18471847
return run_command(&maint);
18481848
}
18491849

1850-
void prepare_other_repo_env(struct strvec *env, const char *new_git_dir)
1850+
void sanitize_repo_env(struct strvec *env)
18511851
{
18521852
const char * const *var;
18531853

@@ -1856,6 +1856,11 @@ void prepare_other_repo_env(struct strvec *env, const char *new_git_dir)
18561856
strcmp(*var, CONFIG_COUNT_ENVIRONMENT))
18571857
strvec_push(env, *var);
18581858
}
1859+
}
1860+
1861+
void prepare_other_repo_env(struct strvec *env, const char *new_git_dir)
1862+
{
1863+
sanitize_repo_env(env);
18591864
strvec_pushf(env, "%s=%s", GIT_DIR_ENVIRONMENT, new_git_dir);
18601865
}
18611866

run-command.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,18 @@ struct run_process_parallel_opts
509509
*/
510510
void run_processes_parallel(const struct run_process_parallel_opts *opts);
511511

512+
/**
513+
* Unset all local-repo GIT_* variables in env; see local_repo_env in
514+
* environment.h. GIT_CONFIG_PARAMETERS and GIT_CONFIG_COUNT are preserved
515+
* to pass -c and --config-env options from the parent process.
516+
*/
517+
void sanitize_repo_env(struct strvec *env);
518+
512519
/**
513520
* Convenience function which prepares env for a command to be run in a
514-
* new repo. This adds all GIT_* environment variables to env with the
515-
* exception of GIT_CONFIG_PARAMETERS and GIT_CONFIG_COUNT (which cause the
516-
* corresponding environment variables to be unset in the subprocess) and adds
517-
* an environment variable pointing to new_git_dir. See local_repo_env in
518-
* environment.h for more information.
521+
* new repo. This removes variables pointing to the local repository (using
522+
* sanitize_repo_env() above), and adds an environment variable pointing to
523+
* new_git_dir.
519524
*/
520525
void prepare_other_repo_env(struct strvec *env, const char *new_git_dir);
521526

0 commit comments

Comments
 (0)