Skip to content

Commit 9dfadf6

Browse files
author
Git for Windows Build Agent
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 fa80474 + 3723c4a commit 9dfadf6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Documentation/git-status.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ configuration variable documented in linkgit:git-config[1].
111111
without options are equivalent to 'always' and 'never'
112112
respectively.
113113

114+
--no-lock-index::
115+
--lock-index::
116+
Specifies whether `git status` should try to lock the index and
117+
update it afterwards if any changes were detected. Defaults to
118+
`--lock-index`.
114119

115120
OUTPUT
116121
------

builtin/commit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
13351335

13361336
int cmd_status(int argc, const char **argv, const char *prefix)
13371337
{
1338+
static int no_lock_index = 0;
13381339
static struct wt_status s;
13391340
int fd;
13401341
struct object_id oid;
@@ -1364,6 +1365,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13641365
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
13651366
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
13661367
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
1368+
OPT_BOOL(0, "no-lock-index", &no_lock_index,
1369+
N_("do not lock the index")),
13671370
OPT_END(),
13681371
};
13691372

@@ -1388,7 +1391,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13881391
read_cache_preload(&s.pathspec);
13891392
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13901393

1391-
fd = hold_locked_index(&index_lock, 0);
1394+
fd = no_lock_index ? -1 : hold_locked_index(&index_lock, 0);
13921395

13931396
s.is_initial = get_oid(s.reference, &oid) ? 1 : 0;
13941397
if (!s.is_initial)

t/t7508-status.sh

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

1673+
test_expect_success '--no-lock-index' '
1674+
test_commit some-file &&
1675+
test-chmtime =1234567890 .git/index &&
1676+
git status --no-lock-index &&
1677+
test-chmtime -v +0 .git/index >out &&
1678+
grep ^1234567890 out &&
1679+
git status &&
1680+
test-chmtime -v +0 .git/index >out &&
1681+
! grep ^1234567890 out
1682+
'
1683+
16731684
test_done

0 commit comments

Comments
 (0)