Skip to content

Commit 94ce167

Browse files
peffgitster
authored andcommitted
init: use setup.c's repo version verification
We check our templates to make sure they are from a version of git we understand (otherwise we would init a repository we cannot ourselves run in!). But our simple integer check has fallen behind the times. Let's use the helpers that setup.c provides to do it right. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2cc7c2c commit 94ce167

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

builtin/init-db.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static void copy_templates(const char *template_dir)
9595
struct strbuf path = STRBUF_INIT;
9696
struct strbuf template_path = STRBUF_INIT;
9797
size_t template_len;
98+
struct repository_format template_format;
99+
struct strbuf err = STRBUF_INIT;
98100
DIR *dir;
99101
char *to_free = NULL;
100102

@@ -121,17 +123,18 @@ static void copy_templates(const char *template_dir)
121123

122124
/* Make sure that template is from the correct vintage */
123125
strbuf_addstr(&template_path, "config");
124-
repository_format_version = 0;
125-
git_config_from_file(check_repository_format_version,
126-
template_path.buf, NULL);
126+
read_repository_format(&template_format, template_path.buf);
127127
strbuf_setlen(&template_path, template_len);
128128

129-
if (repository_format_version &&
130-
repository_format_version != GIT_REPO_VERSION) {
131-
warning(_("not copying templates of "
132-
"a wrong format version %d from '%s'"),
133-
repository_format_version,
134-
template_dir);
129+
/*
130+
* No mention of version at all is OK, but anything else should be
131+
* verified.
132+
*/
133+
if (template_format.version >= 0 &&
134+
verify_repository_format(&template_format, &err) < 0) {
135+
warning(_("not copying templates from '%s': %s"),
136+
template_dir, err.buf);
137+
strbuf_release(&err);
135138
goto close_free_return;
136139
}
137140

0 commit comments

Comments
 (0)