git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 4/5] run-command: refactor subprocess env preparation

From
Elijah Newren <newren@gmail.com>
Date
Jun 10, 2021, 21:21 UTC
Message-ID
<CABPp-BGgdQ02-gUwK1vPSBw8Fw_OCKZskd+5P7_4Bj0sYX++Gg@mail.gmail.com>
In-Reply-To
<fd6907822cf4cb12023999a61682676de193bff9.1623345496.git.jonathantanmy@google.com>
On Thu, Jun 10, 2021 at 10:35 AM Jonathan Tan <jonathantanmy@google.com> wrote:
Show 48 quoted lines
>
> 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 <jonathantanmy@google.com>
> ---
>  run-command.c | 12 ++++++++++++
>  run-command.h | 10 ++++++++++
>  submodule.c   | 18 ++----------------
>  3 files changed, 24 insertions(+), 16 deletions(-)
>
> diff --git a/run-command.c b/run-command.c
> index be6bc128cd..549a94a6a4 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -1892,3 +1892,15 @@ int run_auto_maintenance(int quiet)
>
>         return run_command(&maint);
>  }
> +
> +void prepare_other_repo_env(struct strvec *env_array, const char *new_git_dir)
> +{
> +       const char * const *var;
> +
> +       for (var = local_repo_env; *var; var++) {
> +               if (strcmp(*var, CONFIG_DATA_ENVIRONMENT) &&
> +                   strcmp(*var, CONFIG_COUNT_ENVIRONMENT))
> +                       strvec_push(env_array, *var);
> +       }
> +       strvec_pushf(env_array, "%s=%s", GIT_DIR_ENVIRONMENT, new_git_dir);
> +}
> diff --git a/run-command.h b/run-command.h
> index d08414a92e..92f1c00b11 100644
> --- a/run-command.h
> +++ b/run-command.h
> @@ -483,4 +483,14 @@ int run_processes_parallel_tr2(int n, get_next_task_fn, start_failure_fn,
>                                task_finished_fn, void *pp_cb,
>                                const char *tr2_category, const char *tr2_label);
>
> +/**
> + * Convenience function which prepares env_array for a command to be run in a
> + * new repo. This adds all GIT_* environment variables to env_array with the
> + * exception of GIT_CONFIG_PARAMETERS (which cause the corresponding
> + * environment variables to be unset in the subprocess) and adds an environment
> + * variable pointing to new_git_dir. See local_repo_env in cache.h for more
> + * information.

This comment is out-of-date as of your previous patch. There's (at least) one more variable that is also excluded.

Show 41 quoted lines
> + */
> +void prepare_other_repo_env(struct strvec *env_array, const char *new_git_dir);
> +
>  #endif
> diff --git a/submodule.c b/submodule.c
> index f09031e397..8e611fe1db 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -484,28 +484,14 @@ static void print_submodule_diff_summary(struct repository *r, struct rev_info *
>         strbuf_release(&sb);
>  }
>
> -static void prepare_submodule_repo_env_no_git_dir(struct strvec *out)
> -{
> -       const char * const *var;
> -
> -       for (var = local_repo_env; *var; var++) {
> -               if (strcmp(*var, CONFIG_DATA_ENVIRONMENT) &&
> -                   strcmp(*var, CONFIG_COUNT_ENVIRONMENT))
> -                       strvec_push(out, *var);
> -       }
> -}
> -
>  void prepare_submodule_repo_env(struct strvec *out)
>  {
> -       prepare_submodule_repo_env_no_git_dir(out);
> -       strvec_pushf(out, "%s=%s", GIT_DIR_ENVIRONMENT,
> -                    DEFAULT_GIT_DIR_ENVIRONMENT);
> +       prepare_other_repo_env(out, DEFAULT_GIT_DIR_ENVIRONMENT);
>  }
>
>  static void prepare_submodule_repo_env_in_gitdir(struct strvec *out)
>  {
> -       prepare_submodule_repo_env_no_git_dir(out);
> -       strvec_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT);
> +       prepare_other_repo_env(out, ".");
>  }
>
>  /*
> --
> 2.32.0.rc1.229.g3e70b5a671-goog
Previous: Jonathan TanNext: Elijah Newren
Message 68 of 77 in “First steps towards partial clone submodules”
  1. 0/4 First steps towards partial clone submodulesJonathan Tan, Jun 1, 2021
  2. 1/4 promisor-remote: read partialClone config hereJonathan Tan, Jun 1, 2021
  3. Taylor BlauJun 4, 2021
  4. Jonathan TanJun 5, 2021
  5. Emily ShafferJun 7, 2021
  6. 2/4 promisor-remote: support per-repository configJonathan Tan, Jun 1, 2021
  7. Taylor BlauJun 4, 2021
  8. Jonathan TanJun 5, 2021
  9. Elijah NewrenJun 4, 2021
  10. Jonathan TanJun 5, 2021
  11. Emily ShafferJun 8, 2021
  12. 3/4 run-command: move envvar-resetting functionJonathan Tan, Jun 1, 2021
  13. Taylor BlauJun 4, 2021
  14. Jonathan TanJun 5, 2021
  15. Emily ShafferJun 8, 2021
  16. 4/4 promisor-remote: teach lazy-fetch in any repoJonathan Tan, Jun 1, 2021
  17. Taylor BlauJun 4, 2021
  18. Jonathan TanJun 5, 2021
  19. Elijah NewrenJun 4, 2021
  20. Jonathan TanJun 5, 2021
  21. Elijah NewrenJun 5, 2021
  22. Elijah NewrenJun 5, 2021
  23. Jonathan TanJun 5, 2021
  24. Emily ShafferJun 8, 2021
  25. Jonathan TanJun 9, 2021
  26. 0/4 First steps towards partial clone submodulesJonathan Tan, Jun 8, 2021
  27. 3/4 run-command: move envvar-resetting functionJonathan Tan, Jun 8, 2021
  28. Junio C HamanoJun 8, 2021
  29. Jonathan TanJun 9, 2021
  30. Junio C HamanoJun 9, 2021
  31. Jonathan TanJun 9, 2021
  32. 2/4 promisor-remote: support per-repository configJonathan Tan, Jun 8, 2021
  33. Junio C HamanoJun 8, 2021
  34. Jonathan TanJun 9, 2021
  35. 1/4 promisor-remote: read partialClone config hereJonathan Tan, Jun 8, 2021
  36. Junio C HamanoJun 8, 2021
  37. Jonathan TanJun 9, 2021
  38. Junio C HamanoJun 9, 2021
  39. Jonathan TanJun 9, 2021
  40. Elijah NewrenJun 8, 2021
  41. Jonathan TanJun 9, 2021
  42. Elijah NewrenJun 9, 2021
  43. Jonathan TanJun 10, 2021
  44. 4/4 promisor-remote: teach lazy-fetch in any repoJonathan Tan, Jun 8, 2021
  45. Junio C HamanoJun 8, 2021
  46. Jonathan TanJun 9, 2021
  47. Junio C HamanoJun 9, 2021
  48. Jonathan TanJun 9, 2021
  49. Junio C HamanoJun 10, 2021
  50. Elijah NewrenJun 8, 2021
  51. Jonathan TanJun 9, 2021
  52. Elijah NewrenJun 8, 2021
  53. Junio C HamanoJun 8, 2021
  54. Elijah NewrenJun 9, 2021
  55. Junio C HamanoJun 9, 2021
  56. Jonathan TanJun 9, 2021
  57. Emily ShafferJun 8, 2021
  58. 0/5 First steps towards partial clone submodulesJonathan Tan, Jun 10, 2021
  59. 2/5 promisor-remote: support per-repository configJonathan Tan, Jun 10, 2021
  60. 5/5 promisor-remote: teach lazy-fetch in any repoJonathan Tan, Jun 10, 2021
  61. 1/5 repository: move global r_f_p_c to repo structJonathan Tan, Jun 10, 2021
  62. Elijah NewrenJun 10, 2021
  63. 3/5 submodule: refrain from filtering GIT_CONFIG_COUNTJonathan Tan, Jun 10, 2021
  64. Elijah NewrenJun 10, 2021
  65. Jeff KingJun 10, 2021
  66. Jonathan TanJun 11, 2021
  67. 4/5 run-command: refactor subprocess env preparationJonathan Tan, Jun 10, 2021
  68. Elijah NewrenJun 10, 2021
  69. Elijah NewrenJun 10, 2021
  70. Elijah NewrenJun 15, 2021
  71. 0/5 First steps towards partial clone submodulesJonathan Tan, Jun 17, 2021
  72. 1/5 repository: move global r_f_p_c to repo structJonathan Tan, Jun 17, 2021
  73. 2/5 promisor-remote: support per-repository configJonathan Tan, Jun 17, 2021
  74. 3/5 submodule: refrain from filtering GIT_CONFIG_COUNTJonathan Tan, Jun 17, 2021
  75. 4/5 run-command: refactor subprocess env preparationJonathan Tan, Jun 17, 2021
  76. 5/5 promisor-remote: teach lazy-fetch in any repoJonathan Tan, Jun 17, 2021
  77. Elijah NewrenJun 19, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.