summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/setup.c b/setup.c
index 65fe5ecefb..dbac2eabe8 100644
--- a/setup.c
+++ b/setup.c
@@ -455,6 +455,7 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
if (strcmp(var, "core.repositoryformatversion") == 0)
data->version = git_config_int(var, value);
else if (skip_prefix(var, "extensions.", &ext)) {
+ data->has_extensions = 1;
/*
* record any known extensions here; otherwise,
* we fall through to recording it as unknown, and
@@ -506,9 +507,15 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
die("%s", err.buf);
}
- repository_format_precious_objects = candidate->precious_objects;
- set_repository_format_partial_clone(candidate->partial_clone);
- repository_format_worktree_config = candidate->worktree_config;
+ if (candidate->version >= 1) {
+ repository_format_precious_objects = candidate->precious_objects;
+ set_repository_format_partial_clone(candidate->partial_clone);
+ repository_format_worktree_config = candidate->worktree_config;
+ } else {
+ repository_format_precious_objects = 0;
+ set_repository_format_partial_clone(NULL);
+ repository_format_worktree_config = 0;
+ }
string_list_clear(&candidate->unknown_extensions, 0);
if (repository_format_worktree_config) {
@@ -538,6 +545,34 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
return 0;
}
+int upgrade_repository_format(int target_version)
+{
+ struct strbuf sb = STRBUF_INIT;
+ struct strbuf err = STRBUF_INIT;
+ struct strbuf repo_version = STRBUF_INIT;
+ struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+
+ strbuf_git_common_path(&sb, the_repository, "config");
+ read_repository_format(&repo_fmt, sb.buf);
+ strbuf_release(&sb);
+
+ if (repo_fmt.version >= target_version)
+ return 0;
+
+ if (verify_repository_format(&repo_fmt, &err) < 0 ||
+ (!repo_fmt.version && repo_fmt.has_extensions)) {
+ warning("unable to upgrade repository format from %d to %d: %s",
+ repo_fmt.version, target_version, err.buf);
+ strbuf_release(&err);
+ return -1;
+ }
+
+ strbuf_addf(&repo_version, "%d", target_version);
+ git_config_set("core.repositoryformatversion", repo_version.buf);
+ strbuf_release(&repo_version);
+ return 1;
+}
+
static void init_repository_format(struct repository_format *format)
{
const struct repository_format fresh = REPOSITORY_FORMAT_INIT;
@@ -1273,6 +1308,7 @@ void check_repository_format(struct repository_format *fmt)
fmt = &repo_fmt;
check_repository_format_gently(get_git_dir(), fmt, NULL);
startup_info->have_repository = 1;
+ repo_set_hash_algo(the_repository, fmt->hash_algo);
clear_repository_format(&repo_fmt);
}