status: carry the --no-lock-index option for backwards-compatibility

When a third-party tool periodically runs `git status` in order to keep
track of the state of the working tree, it is a bad idea to lock the
index: it might interfere with interactive commands executed by the
user, e.g. when the user wants to commit files.

Git for Windows introduced the `--no-lock-index` option a long time ago
to fix that (it made it into Git for Windows v2.9.2(3)) by simply
avoiding to write that file.

The downside is that the periodic `git status` calls will be a little
bit more wasteful because they may have to refresh the index repeatedly,
only to throw away the updates when it exits. This cannot really be
helped, though, as tools wanting to get a periodic update of the status
have no way to predict when the user may want to lock the index herself.

Sadly, a competing approach was submitted (by somebody who apparently
has less work on their plate than this maintainer) that made it into
v2.15.0 but is *different*: instead of a `git status`-only option, it is
an option that comes *before* the Git command and is called differently,
too.

Let's give previous users a chance to upgrade to newer Git for Windows
versions by handling the `--no-lock-index` option, still, though with a
big fat warning.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2016-08-12 10:54:26 +02:00
Родитель 5fe2bbe501
Коммит 68a2bcc316
3 изменённых файлов: 28 добавлений и 0 удалений

Просмотреть файл

@ -149,6 +149,13 @@ ignored, then the directory is not shown, but all contents are shown.
threshold. threshold.
See also linkgit:git-diff[1] `--find-renames`. See also linkgit:git-diff[1] `--find-renames`.
--no-lock-index::
--lock-index::
(DEPRECATED: use --no-optional-locks instead)
Specifies whether `git status` should try to lock the index and
update it afterwards if any changes were detected. Defaults to
`--lock-index`.
<pathspec>...:: <pathspec>...::
See the 'pathspec' entry in linkgit:gitglossary[7]. See the 'pathspec' entry in linkgit:gitglossary[7].

Просмотреть файл

@ -1475,6 +1475,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
{ {
static int no_renames = -1; static int no_renames = -1;
static const char *rename_score_arg = (const char *)-1; static const char *rename_score_arg = (const char *)-1;
static int no_lock_index = 0;
static struct wt_status s; static struct wt_status s;
unsigned int progress_flag = 0; unsigned int progress_flag = 0;
int fd; int fd;
@ -1513,6 +1514,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
OPT_CALLBACK_F('M', "find-renames", &rename_score_arg, OPT_CALLBACK_F('M', "find-renames", &rename_score_arg,
N_("n"), N_("detect renames, optionally set similarity index"), N_("n"), N_("detect renames, optionally set similarity index"),
PARSE_OPT_OPTARG | PARSE_OPT_NONEG, opt_parse_rename_score), PARSE_OPT_OPTARG | PARSE_OPT_NONEG, opt_parse_rename_score),
OPT_BOOL(0, "no-lock-index", &no_lock_index,
N_("(DEPRECATED: use `git --no-optional-locks status` "
"instead) Do not lock the index")),
OPT_END(), OPT_END(),
}; };
@ -1529,6 +1533,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)
finalize_colopts(&s.colopts, -1); finalize_colopts(&s.colopts, -1);
finalize_deferred_config(&s); finalize_deferred_config(&s);
if (no_lock_index) {
warning("--no-lock-index is deprecated, use --no-optional-locks"
" instead");
setenv(GIT_OPTIONAL_LOCKS_ENVIRONMENT, "false", 1);
}
handle_untracked_files_arg(&s); handle_untracked_files_arg(&s);
handle_ignored_arg(&s); handle_ignored_arg(&s);

Просмотреть файл

@ -1646,6 +1646,17 @@ test_expect_success '"Initial commit" should not be noted in commit template' '
test_i18ngrep ! "Initial commit" output test_i18ngrep ! "Initial commit" output
' '
test_expect_success '--no-lock-index prevents index update and is deprecated' '
test-tool chmtime =1234567890 .git/index &&
git status --no-lock-index 2>err &&
grep "no-lock-index is deprecated" err &&
test-tool chmtime -v +0 .git/index >out &&
grep ^1234567890 out &&
git status &&
test-tool chmtime -v +0 .git/index >out &&
! grep ^1234567890 out
'
test_expect_success '--no-optional-locks prevents index update' ' test_expect_success '--no-optional-locks prevents index update' '
test_set_magic_mtime .git/index && test_set_magic_mtime .git/index &&
git --no-optional-locks status && git --no-optional-locks status &&