Re: [PATCH] clone: accept DEPTH env var as fallback for --depth
- From
Matt Hunter <m@lfurio.us>
- Date
- Jun 13, 2026, 04:08 UTC
- Message-ID
- <DJ7MJMIFZR5N.2SG1RWB46WPQB@lfurio.us>
- In-Reply-To
- <pull.2333.git.git.1781314780645.gitgitgadget@gmail.com>
On Fri Jun 12, 2026 at 9:39 PM EDT, h8d13 via GitGitGadget wrote:
Show 6 quoted lines
> @@ -1022,6 +1022,12 @@ int cmd_clone(int argc,
> usage_msg_opt(_("You must specify a repository to clone."),
> builtin_clone_usage, builtin_clone_options);
>
> + if (!option_depth) {
> + const char *env_depth = getenv("DEPTH");Nearly all of the non-standard environment variables used by git start with "GIT_". "GIT_CLONE_DEPTH" may be a better choice.
> + if (env_depth && *env_depth) > + option_depth = xstrdup(env_depth);
Following normal command-line option parsing, if --depth is given, then option_depth points to the parsed string from cmd_clone's argv array directly and is not freed. Therefore, the string copy returned via xstrdup also goes unfreed before it is lost.
One might argue this isn't very impactful, since we would expect the process to exit after git-clone completes, but there are already several explicit calls to free and related functions at the end of cmd_clone.
Show 7 quoted lines
> + } > + > if (option_depth || option_since || option_not.nr) > deepen = 1; > if (option_single_branch == -1) > > base-commit: 3e65291872de10c3f0bf05ea8c24187e7a71ebf0