Skip to content

Commit 92eea3a

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 9919a60 + c8d4bdf commit 92eea3a

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
@@ -108,6 +108,11 @@ configuration variable documented in linkgit:git-config[1].
108108
without options are equivalent to 'always' and 'never'
109109
respectively.
110110

111+
--no-lock-index::
112+
--lock-index::
113+
Specifies whether `git status` should try to lock the index and
114+
update it afterwards if any changes were detected. Defaults to
115+
`--lock-index`.
111116

112117
OUTPUT
113118
------

builtin/commit.c

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

13331333
int cmd_status(int argc, const char **argv, const char *prefix)
13341334
{
1335+
static int no_lock_index = 0;
13351336
static struct wt_status s;
13361337
int fd;
13371338
unsigned char sha1[20];
@@ -1359,6 +1360,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13591360
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
13601361
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
13611362
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
1363+
OPT_BOOL(0, "no-lock-index", &no_lock_index,
1364+
N_("do not lock the index")),
13621365
OPT_END(),
13631366
};
13641367

@@ -1383,7 +1386,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13831386
read_cache_preload(&s.pathspec);
13841387
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13851388

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

13881391
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
13891392
if (!s.is_initial)

t/t7508-status.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,4 +1499,15 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' '
14991499
git config -f .gitmodules --remove-section submodule.subname
15001500
'
15011501

1502+
test_expect_success '--no-lock-index' '
1503+
test_commit some-file &&
1504+
test-chmtime =1234567890 .git/index &&
1505+
git status --no-lock-index &&
1506+
test-chmtime -v +0 .git/index >out &&
1507+
grep ^1234567890 out &&
1508+
git status &&
1509+
test-chmtime -v +0 .git/index >out &&
1510+
! grep ^1234567890 out
1511+
'
1512+
15021513
test_done

0 commit comments

Comments
 (0)