From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>,
Karthik Nayak <karthik.188@gmail.com>, Jeff King <peff@peff.net>,
Elijah Newren <newren@gmail.com>,
Christian Couder <christian.couder@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>
Subject: [PATCH 2/3] promisor-remote: introduce enum allow_lazy_fetch
Date: Fri, 10 Jul 2026 10:51:36 +0200 [thread overview]
Message-ID: <20260710085137.4171240-3-christian.couder@gmail.com> (raw)
In-Reply-To: <20260710085137.4171240-1-christian.couder@gmail.com>
The `GIT_NO_LAZY_FETCH` environment variable is currently parsed as
a Boolean, using git_env_bool(), in both "setup.c" and
"promisor-remote.c".
In a following commit, we are going to allow a third value for this
variable, on top of 'true' and 'false'.
To prepare for that, let's introduce an `enum allow_lazy_fetch` with
the possible results of parsing the variable, along with a
parse_allow_lazy_fetch_env() function to parse it, and let's use them
everywhere the variable is parsed.
Note that, as before, an invalid value makes us die(), only the error
message changes from "bad boolean environment value ..." to "bad
environment value ...".
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
promisor-remote.c | 24 +++++++++++++++++++++++-
promisor-remote.h | 13 +++++++++++++
setup.c | 5 ++++-
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/promisor-remote.c b/promisor-remote.c
index 65496c69cf..56f57c5267 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -21,6 +21,26 @@ struct promisor_remote_config {
struct promisor_remote **promisors_tail;
};
+enum allow_lazy_fetch parse_allow_lazy_fetch_env(void)
+{
+ const char *v = getenv(NO_LAZY_FETCH_ENVIRONMENT);
+ int val;
+
+ if (!v)
+ return LAZY_FETCH_ALL;
+
+ val = git_parse_maybe_bool(v);
+
+ if (!val)
+ return LAZY_FETCH_ALL;
+ if (val > 0)
+ return LAZY_FETCH_NONE;
+
+ die(_("bad environment value '%s' for '%s'; "
+ "only 'false/0' and 'true/1' are valid"),
+ v, NO_LAZY_FETCH_ENVIRONMENT);
+}
+
static int fetch_objects(struct repository *repo,
const char *remote_name,
const struct object_id *oids,
@@ -299,7 +319,9 @@ static bool lazy_fetch_objects(struct repository *repo,
int *remaining_nr,
int *to_free)
{
- if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) {
+ enum allow_lazy_fetch lf = parse_allow_lazy_fetch_env();
+
+ if (lf == LAZY_FETCH_NONE) {
static int warning_shown;
if (!warning_shown) {
warning_shown = 1;
diff --git a/promisor-remote.h b/promisor-remote.h
index 301f5ac5cb..87fc24c9eb 100644
--- a/promisor-remote.h
+++ b/promisor-remote.h
@@ -25,6 +25,19 @@ void promisor_remote_clear(struct promisor_remote_config *config);
struct promisor_remote *repo_promisor_remote_find(struct repository *r, const char *remote_name);
int repo_has_promisor_remote(struct repository *r);
+/* Enum for lazy fetching parsing */
+enum allow_lazy_fetch {
+ LAZY_FETCH_NONE = 0, /* No lazy fetching */
+ LAZY_FETCH_ALL /* Lazy fetch from any promisor remotes */
+};
+
+/*
+ * Parse the NO_LAZY_FETCH_ENVIRONMENT env variable into an
+ * `enum allow_lazy_fetch`.
+ * If parsing fails, then die().
+ */
+enum allow_lazy_fetch parse_allow_lazy_fetch_env(void);
+
/*
* Fetches all requested objects from all promisor remotes, trying them one at
* a time until all objects are fetched.
diff --git a/setup.c b/setup.c
index 0de56a074f..0a81d9f045 100644
--- a/setup.c
+++ b/setup.c
@@ -24,6 +24,7 @@
#include "trace.h"
#include "trace2.h"
#include "worktree.h"
+#include "promisor-remote.h"
enum allowed_bare_repo {
ALLOWED_BARE_REPO_EXPLICIT = 0,
@@ -1051,6 +1052,7 @@ static void setup_git_env_internal(struct repository *repo,
const char *replace_ref_base;
struct set_gitdir_args args = { NULL };
struct strvec to_free = STRVEC_INIT;
+ enum allow_lazy_fetch lf;
args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT);
args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT);
@@ -1072,7 +1074,8 @@ static void setup_git_env_internal(struct repository *repo,
if (shallow_file)
set_alternate_shallow_file(repo, shallow_file, 0);
- if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0))
+ lf = parse_allow_lazy_fetch_env();
+ if (lf == LAZY_FETCH_NONE)
fetch_if_missing = 0;
}
--
2.55.0.125.g395cd2c8ec.dirty
next prev parent reply other threads:[~2026-07-10 8:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 8:51 [PATCH 0/3] Introduce a 'fromAccepted' option to GIT_NO_LAZY_FETCH Christian Couder
2026-07-10 8:51 ` [PATCH 1/3] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-07-10 8:51 ` Christian Couder [this message]
2026-07-10 8:51 ` [PATCH 3/3] promisor-remote: teach 'fromAccepted' to GIT_NO_LAZY_FETCH Christian Couder
2026-07-10 19:50 ` [PATCH 0/3] Introduce a 'fromAccepted' option " brian m. carlson
2026-07-12 9:06 ` Christian Couder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260710085137.4171240-3-christian.couder@gmail.com \
--to=christian.couder@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox