worktree: allow repository version 1
Git supports both repository versions 0 and 1. These formats are identical except for the presence of extensions. When using an extension, such as for a different hash algorithm, a check for only version 0 causes the check to fail. Instead, call verify_repository_format to verify that we have an appropriate version and no unknown extensions. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 22, 2020 at 20:17 UTC
e02a7141f83326f7098800fed764061ecf1f0eff
1 file changed
+4
-6
worktree.c
+4
-6
@@ -449,7 +449,7 @@ const struct worktree *find_shared_symref(const char *symref,
449
int submodule_uses_worktrees(const char *path)
450
{
451
char *submodule_gitdir;
452
- struct strbuf sb = STRBUF_INIT;
452
+ struct strbuf sb = STRBUF_INIT, err = STRBUF_INIT;
453
DIR *dir;
454
struct dirent *d;
455
int ret = 0;
@@ -463,18 +463,16 @@ int submodule_uses_worktrees(const char *path)
463
get_common_dir_noenv(&sb, submodule_gitdir);
464
free(submodule_gitdir);
465
466
- /*
467
- * The check below is only known to be good for repository format
468
- * version 0 at the time of writing this code.
469
- */
466
strbuf_addstr(&sb, "/config");
467
read_repository_format(&format, sb.buf);
472
- if (format.version != 0) {
468
+ if (verify_repository_format(&format, &err)) {
469
+ strbuf_release(&err);
470
strbuf_release(&sb);
471
clear_repository_format(&format);
472
return 1;
473
}
474
clear_repository_format(&format);
475
+ strbuf_release(&err);
476
477
/* Replace config by worktrees. */
478
strbuf_setlen(&sb, sb.len - strlen("config"));