1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-09 04:26:08 +02:00

Merge branch 'jc/no-lazy-fetch' into HEAD

"git --no-lazy-fetch cmd" allows to run "cmd" while disabling lazy
fetching of objects from the promisor remote, which may be handy
for debugging.

* jc/no-lazy-fetch:
  git: extend --no-lazy-fetch to work across subprocesses
  git: document GIT_NO_REPLACE_OBJECTS environment variable
  git: --no-lazy-fetch option
This commit is contained in:
Junio C Hamano 2024-03-01 17:32:11 -08:00
commit 14303cdbfe
5 changed files with 45 additions and 2 deletions

View File

@ -174,8 +174,17 @@ If you just want to run git as if it was started in `<path>` then use
directory.
--no-replace-objects::
Do not use replacement refs to replace Git objects. See
linkgit:git-replace[1] for more information.
Do not use replacement refs to replace Git objects.
This is equivalent to exporting the `GIT_NO_REPLACE_OBJECTS`
environment variable with any value.
See linkgit:git-replace[1] for more information.
--no-lazy-fetch::
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).
@ -872,6 +881,10 @@ for full details.
header and packfile URIs. Set this Boolean environment variable to false to prevent this
redaction.
`GIT_NO_REPLACE_OBJECTS`::
Setting and exporting this environment variable tells Git to
ignore replacement refs and do not replace Git objects.
`GIT_LITERAL_PATHSPECS`::
Setting this Boolean environment variable to true will cause Git to treat all
pathspecs literally, rather than as glob patterns. For example,
@ -893,6 +906,11 @@ for full details.
Setting this Boolean environment variable to true will cause Git to treat all
pathspecs as case-insensitive.
`GIT_NO_LAZY_FETCH`::
Setting this Boolean environment variable to true tells Git
not to lazily fetch missing objects from the promisor remote
on demand.
`GIT_REFLOG_ACTION`::
When a ref is updated, reflog entries are created to keep
track of the reason why the ref was updated (which is

View File

@ -207,6 +207,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)

View File

@ -36,6 +36,7 @@ const char *getenv_safe(struct strvec *argv, const char *name);
#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
#define NO_LAZY_FETCH_ENVIRONMENT "GIT_NO_LAZY_FETCH"
#define GITATTRIBUTES_FILE ".gitattributes"
#define INFOATTRIBUTES_FILE "info/attributes"
#define ATTRIBUTE_MACRO_PREFIX "[attr]"

6
git.c
View File

@ -4,6 +4,7 @@
#include "exec-cmd.h"
#include "gettext.h"
#include "help.h"
#include "object-file.h"
#include "pager.h"
#include "read-cache-ll.h"
#include "run-command.h"
@ -186,6 +187,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
use_pager = 0;
if (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);

View File

@ -665,6 +665,21 @@ 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" &&
# The same with command line option to "git"
test_must_fail git --no-lazy-fetch -C partial.git cat-file -e "$FILE_HASH" &&
# The same, forcing a subprocess via an alias
test_must_fail git --no-lazy-fetch -C partial.git \
-c alias.foo="!git cat-file" foo -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 &&