Skip to content

Commit 69dec66

Browse files
committed
update-index: upgrade/downgrade on-disk index version
With the "--index-version <n>" parameter, write the index out in the specified version. With this, an index file that is written in newer format (say v4) can be downgraded to be read by older versions of Git. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d22778 commit 69dec66

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Documentation/git-update-index.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ SYNOPSIS
1919
[--ignore-submodules]
2020
[--really-refresh] [--unresolve] [--again | -g]
2121
[--info-only] [--index-info]
22-
[-z] [--stdin]
22+
[-z] [--stdin] [--index-version <n>]
2323
[--verbose]
2424
[--] [<file>...]
2525

@@ -143,6 +143,10 @@ you will need to handle the situation manually.
143143
--verbose::
144144
Report what is being added and removed from index.
145145

146+
--index-version <n>::
147+
Write the resulting index out in the named on-disk format version.
148+
The current default version is 2.
149+
146150
-z::
147151
Only meaningful with `--stdin` or `--index-info`; paths are
148152
separated with NUL character instead of LF.

builtin/update-index.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
708708
int newfd, entries, has_errors = 0, line_termination = '\n';
709709
int read_from_stdin = 0;
710710
int prefix_length = prefix ? strlen(prefix) : 0;
711+
int preferred_index_format = 0;
711712
char set_executable_bit = 0;
712713
struct refresh_params refresh_args = {0, &has_errors};
713714
int lock_error = 0;
@@ -791,6 +792,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
791792
"(for porcelains) forget saved unresolved conflicts",
792793
PARSE_OPT_NOARG | PARSE_OPT_NONEG,
793794
resolve_undo_clear_callback},
795+
OPT_INTEGER(0, "index-version", &preferred_index_format,
796+
"write index in this format"),
794797
OPT_END()
795798
};
796799

@@ -851,6 +854,17 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
851854
}
852855
}
853856
argc = parse_options_end(&ctx);
857+
if (preferred_index_format) {
858+
if (preferred_index_format < INDEX_FORMAT_LB ||
859+
INDEX_FORMAT_UB < preferred_index_format)
860+
die("index-version %d not in range: %d..%d",
861+
preferred_index_format,
862+
INDEX_FORMAT_LB, INDEX_FORMAT_UB);
863+
864+
if (the_index.version != preferred_index_format)
865+
active_cache_changed = 1;
866+
the_index.version = preferred_index_format;
867+
}
854868

855869
if (read_from_stdin) {
856870
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;

0 commit comments

Comments
 (0)