Skip to content

Commit 806e1ba

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 fa5ed23 + 3ec6afe commit 806e1ba

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Documentation/git-status.txt

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

114-
<pathspec>...::
115114
See the 'pathspec' entry in linkgit:gitglossary[7].
116115

117116
OUTPUT

builtin/commit.c

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

13341334
int cmd_status(int argc, const char **argv, const char *prefix)
13351335
{
1336+
static int no_lock_index = 0;
13361337
static struct wt_status s;
13371338
int fd;
13381339
struct object_id oid;
@@ -1362,6 +1363,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13621363
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
13631364
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
13641365
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
1366+
OPT_BOOL(0, "no-lock-index", &no_lock_index,
1367+
N_("do not lock the index")),
13651368
OPT_END(),
13661369
};
13671370

@@ -1386,7 +1389,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13861389
read_cache_preload(&s.pathspec);
13871390
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13881391

1389-
fd = hold_locked_index(&index_lock, 0);
1392+
fd = no_lock_index ? -1 : hold_locked_index(&index_lock, 0);
13901393

13911394
s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
13921395
if (!s.is_initial)

t/t7508-status.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,4 +1671,15 @@ 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' '
1675+
test_commit some-file &&
1676+
test-chmtime =1234567890 .git/index &&
1677+
git status --no-lock-index &&
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_done

0 commit comments

Comments
 (0)