Merge branch 'jk/no-optional-locks'
Some commands (most notably "git status") makes an opportunistic update when performing a read-only operation to help optimize later operations in the same repository. The new "--no-optional-locks" option can be passed to Git to disable them. * jk/no-optional-locks: git: add --no-optional-locks option
This commit is contained in:
commit
d4e93836a6
@ -159,6 +159,10 @@ foo.bar= ...`) sets `foo.bar` to the empty string which ` git config
|
|||||||
Add "icase" magic to all pathspec. This is equivalent to setting
|
Add "icase" magic to all pathspec. This is equivalent to setting
|
||||||
the `GIT_ICASE_PATHSPECS` environment variable to `1`.
|
the `GIT_ICASE_PATHSPECS` environment variable to `1`.
|
||||||
|
|
||||||
|
--no-optional-locks::
|
||||||
|
Do not perform optional operations that require locks. This is
|
||||||
|
equivalent to setting the `GIT_OPTIONAL_LOCKS` to `0`.
|
||||||
|
|
||||||
GIT COMMANDS
|
GIT COMMANDS
|
||||||
------------
|
------------
|
||||||
|
|
||||||
@ -697,6 +701,14 @@ of clones and fetches.
|
|||||||
which feed potentially-untrusted URLS to git commands. See
|
which feed potentially-untrusted URLS to git commands. See
|
||||||
linkgit:git-config[1] for more details.
|
linkgit:git-config[1] for more details.
|
||||||
|
|
||||||
|
`GIT_OPTIONAL_LOCKS`::
|
||||||
|
If set to `0`, Git will complete any requested operation without
|
||||||
|
performing any optional sub-operations that require taking a lock.
|
||||||
|
For example, this will prevent `git status` from refreshing the
|
||||||
|
index as a side effect. This is useful for processes running in
|
||||||
|
the background which do not want to cause lock contention with
|
||||||
|
other operations on the repository. Defaults to `1`.
|
||||||
|
|
||||||
Discussion[[Discussion]]
|
Discussion[[Discussion]]
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
@ -1392,7 +1392,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
|
|||||||
read_cache_preload(&s.pathspec);
|
read_cache_preload(&s.pathspec);
|
||||||
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
|
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
|
||||||
|
|
||||||
fd = hold_locked_index(&index_lock, 0);
|
if (use_optional_locks())
|
||||||
|
fd = hold_locked_index(&index_lock, 0);
|
||||||
|
else
|
||||||
|
fd = -1;
|
||||||
|
|
||||||
s.is_initial = get_oid(s.reference, &oid) ? 1 : 0;
|
s.is_initial = get_oid(s.reference, &oid) ? 1 : 0;
|
||||||
if (!s.is_initial)
|
if (!s.is_initial)
|
||||||
|
6
cache.h
6
cache.h
@ -444,6 +444,7 @@ static inline enum object_type object_type(unsigned int mode)
|
|||||||
#define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS"
|
#define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS"
|
||||||
#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
|
#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS"
|
||||||
#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
|
#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH"
|
||||||
|
#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This environment variable is expected to contain a boolean indicating
|
* This environment variable is expected to contain a boolean indicating
|
||||||
@ -783,6 +784,11 @@ extern int protect_ntfs;
|
|||||||
*/
|
*/
|
||||||
extern int ref_paranoia;
|
extern int ref_paranoia;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value).
|
||||||
|
*/
|
||||||
|
int use_optional_locks(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The character that begins a commented line in user-editable file
|
* The character that begins a commented line in user-editable file
|
||||||
* that is subject to stripspace.
|
* that is subject to stripspace.
|
||||||
|
@ -338,3 +338,8 @@ void reset_shared_repository(void)
|
|||||||
{
|
{
|
||||||
need_shared_repository_from_config = 1;
|
need_shared_repository_from_config = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int use_optional_locks(void)
|
||||||
|
{
|
||||||
|
return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1);
|
||||||
|
}
|
||||||
|
4
git.c
4
git.c
@ -182,6 +182,10 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
|
|||||||
setenv(GIT_ICASE_PATHSPECS_ENVIRONMENT, "1", 1);
|
setenv(GIT_ICASE_PATHSPECS_ENVIRONMENT, "1", 1);
|
||||||
if (envchanged)
|
if (envchanged)
|
||||||
*envchanged = 1;
|
*envchanged = 1;
|
||||||
|
} else if (!strcmp(cmd, "--no-optional-locks")) {
|
||||||
|
setenv(GIT_OPTIONAL_LOCKS_ENVIRONMENT, "0", 1);
|
||||||
|
if (envchanged)
|
||||||
|
*envchanged = 1;
|
||||||
} else if (!strcmp(cmd, "--shallow-file")) {
|
} else if (!strcmp(cmd, "--shallow-file")) {
|
||||||
(*argv)++;
|
(*argv)++;
|
||||||
(*argc)--;
|
(*argc)--;
|
||||||
|
@ -1670,4 +1670,14 @@ test_expect_success '"Initial commit" should not be noted in commit template' '
|
|||||||
test_i18ngrep ! "Initial commit" output
|
test_i18ngrep ! "Initial commit" output
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success '--no-optional-locks prevents index update' '
|
||||||
|
test-chmtime =1234567890 .git/index &&
|
||||||
|
git --no-optional-locks status &&
|
||||||
|
test-chmtime -v +0 .git/index >out &&
|
||||||
|
grep ^1234567890 out &&
|
||||||
|
git status &&
|
||||||
|
test-chmtime -v +0 .git/index >out &&
|
||||||
|
! grep ^1234567890 out
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user