diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-09-12 22:32:34 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-09-13 02:21:53 +0300 |
commit | 606e088d5d9af2393b4b05a8a180162c129cd734 (patch) | |
tree | 6684eaf70d5ce0a78944896aaae3a3e1f2c23405 /builtin/update-index.c | |
parent | 764b2330db42d07ed8c7d4f6c66a1d1203fb95de (diff) |
update-index: add --show-index-version
"git update-index --index-version N" is used to set the index format
version to a specific version, but there was no way to query the
current version used in the on-disk index file.
Teach the command a new "--show-index-version" option, and also
teach the "--index-version N" option to report what the version was
when run with the "--verbose" option.
Helped-by: Linus Arver <linusa@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/update-index.c')
-rw-r--r-- | builtin/update-index.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/builtin/update-index.c b/builtin/update-index.c index 5fab9ad2ec..8c3454c1c1 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1089,6 +1089,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) resolve_undo_clear_callback), OPT_INTEGER(0, "index-version", &preferred_index_format, N_("write index in this format")), + OPT_SET_INT(0, "show-index-version", &preferred_index_format, + N_("report on-disk index format version"), -1), OPT_BOOL(0, "split-index", &split_index, N_("enable or disable split index")), OPT_BOOL(0, "untracked-cache", &untracked_cache, @@ -1181,15 +1183,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; if (preferred_index_format) { - if (preferred_index_format < INDEX_FORMAT_LB || - INDEX_FORMAT_UB < preferred_index_format) + if (preferred_index_format < 0) { + printf(_("%d\n"), the_index.version); + } else if (preferred_index_format < INDEX_FORMAT_LB || + INDEX_FORMAT_UB < preferred_index_format) { die("index-version %d not in range: %d..%d", preferred_index_format, INDEX_FORMAT_LB, INDEX_FORMAT_UB); - - if (the_index.version != preferred_index_format) - the_index.cache_changed |= SOMETHING_CHANGED; - the_index.version = preferred_index_format; + } else { + if (the_index.version != preferred_index_format) + the_index.cache_changed |= SOMETHING_CHANGED; + report(_("index-version: was %d, set to %d"), + the_index.version, preferred_index_format); + the_index.version = preferred_index_format; + } } if (read_from_stdin) { |