From: Junio C Hamano <gitster@pobox•com>
To: git@vger•kernel.org
Cc: Jeff King <peff@peff•net>, Christian Couder <chriscool@tuxfamily•org>
Subject: [PATCH] git: extend --no-lazy-fetch to work across subprocesses
Date: Fri, 16 Feb 2024 13:09:43 -0800 [thread overview]
Message-ID: <xmqqr0hcglpk.fsf_-_@gitster.g> (raw)
In-Reply-To: <xmqq1q9cl3xv.fsf@gitster.g> (Junio C. Hamano's message of "Fri, 16 Feb 2024 09:22:20 -0800")
Modeling after how the `--no-replace-objects` option is made usable
across subprocess spawning (e.g., cURL based remote helpers are
spawned as a separate process while running "git fetch"), allow the
`--no-lazy-fetch` option to be passed across process boundary.
Do not model how the value of GIT_NO_REPLACE_OBJECTS environment
variable is ignored, though. Just use the usual git_env_bool() to
allow "export GIT_NO_LAZY_FETCH=0" and "unset GIT_NO_LAZY_FETCH"
to be equivalents.
Signed-off-by: Junio C Hamano <gitster@pobox•com>
---
* And this comes on top of the original one plus the documentation
update for GIT_NO_REPLACE_OBJECTS.
Documentation/git.txt | 2 ++
environment.c | 4 ++++
environment.h | 1 +
git.c | 3 +++
t/t0410-partial-clone.sh | 9 +++++++++
5 files changed, 19 insertions(+)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 2f1cb3ef4e..be2829003d 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -183,6 +183,8 @@ If you just want to run git as if it was started in `<path>` then use
Do not fetch missing objects from the promisor remote on
demand. Useful together with `git cat-file -e <object>` to
see if the object is locally available.
+ This is equivalent to setting the `GIT_NO_LAZY_FETCH`
+ environment variable to `1`.
--literal-pathspecs::
Treat pathspecs literally (i.e. no globbing, no pathspec magic).
diff --git a/environment.c b/environment.c
index 9e37bf58c0..afad78a3f8 100644
--- a/environment.c
+++ b/environment.c
@@ -136,6 +136,7 @@ const char * const local_repo_env[] = {
GRAFT_ENVIRONMENT,
INDEX_ENVIRONMENT,
NO_REPLACE_OBJECTS_ENVIRONMENT,
+ NO_LAZY_FETCH_ENVIRONMENT,
GIT_REPLACE_REF_BASE_ENVIRONMENT,
GIT_PREFIX_ENVIRONMENT,
GIT_SHALLOW_FILE_ENVIRONMENT,
@@ -207,6 +208,9 @@ void setup_git_env(const char *git_dir)
shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
if (shallow_file)
set_alternate_shallow_file(the_repository, shallow_file, 0);
+
+ if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0))
+ fetch_if_missing = 0;
}
int is_bare_repository(void)
diff --git a/environment.h b/environment.h
index e5351c9dd9..74b3124f55 100644
--- a/environment.h
+++ b/environment.h
@@ -35,6 +35,7 @@ const char *getenv_safe(struct strvec *argv, const char *name);
#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
+#define NO_LAZY_FETCH_ENVIRONMENT "GIT_NO_LAZY_FETCH"
#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
#define GITATTRIBUTES_FILE ".gitattributes"
#define INFOATTRIBUTES_FILE "info/attributes"
diff --git a/git.c b/git.c
index 28e8bf7497..d11d4dc77b 100644
--- a/git.c
+++ b/git.c
@@ -189,6 +189,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--no-lazy-fetch")) {
fetch_if_missing = 0;
+ setenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 1);
+ if (envchanged)
+ *envchanged = 1;
} else if (!strcmp(cmd, "--no-replace-objects")) {
disable_replace_refs();
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh
index 5b7bee888d..59629cea1f 100755
--- a/t/t0410-partial-clone.sh
+++ b/t/t0410-partial-clone.sh
@@ -665,6 +665,15 @@ test_expect_success 'lazy-fetch when accessing object not in the_repository' '
git -C partial.git rev-list --objects --missing=print HEAD >out &&
grep "[?]$FILE_HASH" out &&
+ # The no-lazy-fetch mechanism prevents Git from fetching
+ test_must_fail env GIT_NO_LAZY_FETCH=1 \
+ git -C partial.git cat-file -e "$FILE_HASH" &&
+ test_must_fail git --no-lazy-fetch -C partial.git cat-file -e "$FILE_HASH" &&
+
+ # Sanity check that the file is still missing
+ git -C partial.git rev-list --objects --missing=print HEAD >out &&
+ grep "[?]$FILE_HASH" out &&
+
git -C full cat-file -s "$FILE_HASH" >expect &&
test-tool partial-clone object-info partial.git "$FILE_HASH" >actual &&
test_cmp expect actual &&
--
2.44.0-rc1-17-g3e0d3cd5c7
next prev parent reply other threads:[~2024-02-16 21:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-08 23:17 [PATCH] git: --no-lazy-fetch option Junio C Hamano
2024-02-13 20:23 ` Linus Arver
2024-02-13 20:37 ` Linus Arver
2024-02-13 20:49 ` Junio C Hamano
2024-02-15 5:30 ` Jeff King
2024-02-15 17:04 ` Junio C Hamano
2024-02-16 17:22 ` Junio C Hamano
2024-02-16 21:09 ` Junio C Hamano [this message]
2024-02-16 22:30 ` [PATCH] git: extend --no-lazy-fetch to work across subprocesses Linus Arver
2024-02-16 23:01 ` Junio C Hamano
2024-02-16 23:12 ` Linus Arver
2024-02-17 5:40 ` Jeff King
2024-02-27 6:04 ` Junio C Hamano
2024-02-27 7:49 ` Jeff King
2024-02-27 16:48 ` Junio C Hamano
2024-03-07 9:56 ` Jeff King
2024-03-07 20:33 ` Junio C Hamano
2024-02-17 5:29 ` [PATCH] git: --no-lazy-fetch option Jeff King
2024-03-09 1:57 ` Linus Arver
2024-02-15 20:59 ` Linus Arver
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=xmqqr0hcglpk.fsf_-_@gitster.g \
--to=gitster@pobox$(echo .)com \
--cc=chriscool@tuxfamily$(echo .)org \
--cc=git@vger$(echo .)kernel.org \
--cc=peff@peff$(echo .)net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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