Skip to content

Commit d1fa943

Browse files
jonathantanmygitster
authored andcommitted
run-command: refactor subprocess env preparation
submodule.c has functionality that prepares the environment for running a subprocess in a new repo. The lazy-fetching code (used in partial clones) will need this in a subsequent commit, so move it to a more central location. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 69bb2e1 commit d1fa943

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

run-command.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,3 +1892,15 @@ int run_auto_maintenance(int quiet)
18921892

18931893
return run_command(&maint);
18941894
}
1895+
1896+
void prepare_other_repo_env(struct strvec *env_array, const char *new_git_dir)
1897+
{
1898+
const char * const *var;
1899+
1900+
for (var = local_repo_env; *var; var++) {
1901+
if (strcmp(*var, CONFIG_DATA_ENVIRONMENT) &&
1902+
strcmp(*var, CONFIG_COUNT_ENVIRONMENT))
1903+
strvec_push(env_array, *var);
1904+
}
1905+
strvec_pushf(env_array, "%s=%s", GIT_DIR_ENVIRONMENT, new_git_dir);
1906+
}

run-command.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,14 @@ int run_processes_parallel_tr2(int n, get_next_task_fn, start_failure_fn,
483483
task_finished_fn, void *pp_cb,
484484
const char *tr2_category, const char *tr2_label);
485485

486+
/**
487+
* Convenience function which prepares env_array for a command to be run in a
488+
* new repo. This adds all GIT_* environment variables to env_array with the
489+
* exception of GIT_CONFIG_PARAMETERS and GIT_CONFIG_COUNT (which cause the
490+
* corresponding environment variables to be unset in the subprocess) and adds
491+
* an environment variable pointing to new_git_dir. See local_repo_env in
492+
* cache.h for more information.
493+
*/
494+
void prepare_other_repo_env(struct strvec *env_array, const char *new_git_dir);
495+
486496
#endif

submodule.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -484,28 +484,14 @@ static void print_submodule_diff_summary(struct repository *r, struct rev_info *
484484
strbuf_release(&sb);
485485
}
486486

487-
static void prepare_submodule_repo_env_no_git_dir(struct strvec *out)
488-
{
489-
const char * const *var;
490-
491-
for (var = local_repo_env; *var; var++) {
492-
if (strcmp(*var, CONFIG_DATA_ENVIRONMENT) &&
493-
strcmp(*var, CONFIG_COUNT_ENVIRONMENT))
494-
strvec_push(out, *var);
495-
}
496-
}
497-
498487
void prepare_submodule_repo_env(struct strvec *out)
499488
{
500-
prepare_submodule_repo_env_no_git_dir(out);
501-
strvec_pushf(out, "%s=%s", GIT_DIR_ENVIRONMENT,
502-
DEFAULT_GIT_DIR_ENVIRONMENT);
489+
prepare_other_repo_env(out, DEFAULT_GIT_DIR_ENVIRONMENT);
503490
}
504491

505492
static void prepare_submodule_repo_env_in_gitdir(struct strvec *out)
506493
{
507-
prepare_submodule_repo_env_no_git_dir(out);
508-
strvec_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT);
494+
prepare_other_repo_env(out, ".");
509495
}
510496

511497
/*

0 commit comments

Comments
 (0)