Skip to content

Commit

Permalink
Merge branch 'status-no-lock-index'
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho committed Aug 13, 2016
2 parents 7576a30 + fd3438f commit 01d1dd8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Documentation/git-status.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ configuration variable documented in linkgit:git-config[1].
without options are equivalent to 'always' and 'never'
respectively.

--no-lock-index::
--lock-index::
Specifies whether `git status` should try to lock the index and
update it afterwards if any changes were detected. Defaults to
`--lock-index`.

OUTPUT
------
Expand Down
5 changes: 4 additions & 1 deletion builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,7 @@ static int git_status_config(const char *k, const char *v, void *cb)

int cmd_status(int argc, const char **argv, const char *prefix)
{
static int no_lock_index = 0;
static struct wt_status s;
int fd;
unsigned char sha1[20];
Expand Down Expand Up @@ -1354,6 +1355,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
OPT_BOOL(0, "no-lock-index", &no_lock_index,
N_("do not lock the index")),
OPT_END(),
};

Expand All @@ -1378,7 +1381,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
read_cache_preload(&s.pathspec);
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);

fd = hold_locked_index(&index_lock, 0);
fd = no_lock_index ? -1 : hold_locked_index(&index_lock, 0);

s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
if (!s.is_initial)
Expand Down
11 changes: 11 additions & 0 deletions t/t7508-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1499,4 +1499,15 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' '
git config -f .gitmodules --remove-section submodule.subname
'

test_expect_success '--no-lock-index' '
test_commit some-file &&
test-chmtime =1234567890 .git/index &&
git status --no-lock-index &&
test-chmtime -v +0 .git/index >out &&
grep ^1234567890 out &&
git status &&
test-chmtime -v +0 .git/index >out &&
! grep ^1234567890 out
'

test_done

0 comments on commit 01d1dd8

Please sign in to comment.