Skip to content

Commit 0eb26fd

Browse files
committed
Merge branch 'status-no-lock-index'
This branch allows third-party tools to call `git status --no-lock-index` to avoid lock contention with the interactive Git usage of the actual human user. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 33f0a16 + 652a474 commit 0eb26fd

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Documentation/git-status.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ ignored, then the directory is not shown, but all contents are shown.
134134
without options are equivalent to 'always' and 'never'
135135
respectively.
136136

137+
--no-lock-index::
138+
--lock-index::
139+
(DEPRECATED: use --no-optional-locks instead)
140+
Specifies whether `git status` should try to lock the index and
141+
update it afterwards if any changes were detected. Defaults to
142+
`--lock-index`.
143+
137144
<pathspec>...::
138145
See the 'pathspec' entry in linkgit:gitglossary[7].
139146

builtin/commit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
13641364

13651365
int cmd_status(int argc, const char **argv, const char *prefix)
13661366
{
1367+
static int no_lock_index = 0;
13671368
static struct wt_status s;
13681369
int fd;
13691370
struct object_id oid;
@@ -1397,6 +1398,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13971398
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
13981399
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
13991400
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
1401+
OPT_BOOL(0, "no-lock-index", &no_lock_index,
1402+
N_("do not lock the index")),
14001403
OPT_END(),
14011404
};
14021405

@@ -1410,6 +1413,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14101413
finalize_colopts(&s.colopts, -1);
14111414
finalize_deferred_config(&s);
14121415

1416+
if (no_lock_index) {
1417+
warning("--no-lock-index is deprecated, use --no-optional-locks"
1418+
" instead");
1419+
setenv(GIT_OPTIONAL_LOCKS_ENVIRONMENT, "false", 1);
1420+
}
1421+
14131422
handle_untracked_files_arg(&s);
14141423
handle_ignored_arg(&s);
14151424

t/t7508-status.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,17 @@ test_expect_success '"Initial commit" should not be noted in commit template' '
16711671
test_i18ngrep ! "Initial commit" output
16721672
'
16731673

1674+
test_expect_success '--no-lock-index prevents index update and is deprecated' '
1675+
test-chmtime =1234567890 .git/index &&
1676+
git status --no-lock-index 2>err &&
1677+
grep "no-lock-index is deprecated" err &&
1678+
test-chmtime -v +0 .git/index >out &&
1679+
grep ^1234567890 out &&
1680+
git status &&
1681+
test-chmtime -v +0 .git/index >out &&
1682+
! grep ^1234567890 out
1683+
'
1684+
16741685
test_expect_success '--no-optional-locks prevents index update' '
16751686
test-chmtime =1234567890 .git/index &&
16761687
git --no-optional-locks status &&

0 commit comments

Comments
 (0)