[PATCH 6/6] Add check for downgrading of repo format version via init-db
- From
- Martin Atukunda <matlads@dsmagic.com>
- Date
- Nov 22, 2005, 00:28 UTC
- Message-ID
- <11326192931463-git-send-email-matlads@dsmagic.com>
- In-Reply-To
- <11326192921291-git-send-email-matlads@dsmagic.com>
This corrects an earlier assumption that init-db made. It assumed that the config file was specifying a correct repo format version.
This patch clarifies the assumption by checking the repo format version specified in the config to be copied, and dies if the copy will result in an upgrade.
It however, warns if the copy will result in a downgrade of the repo format version, as git tools are supposed (or will be able) to handle this case :)
Signed-Off-By: Martin Atukunda <matlads@dsmagic.com>
---
init-db.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-)
applies-to: 0095aa60b05c91308a25a00dc939bcd95e63b03f 7858de7a1a57e73d2585271b57acfcd044e27e68
diff --git a/init-db.c b/init-db.c index 90be428..d1fc142 100644 --- a/init-db.c +++ b/init-db.c @@ -110,6 +110,15 @@ static void copy_templates_1(char *path, } } +static int check_repo_config(const char *var, const char *value) +{ + if (strcmp(var, "core.repositoryformatversion") == 0) { + repository_format_version = git_config_int(var, value); + return 0; + } + return 1; +} + static int init_db_config_check(const char *template_path) { DIR *dir; @@ -117,8 +126,36 @@ static int init_db_config_check(const ch dir = opendir(template_path); while((de = readdir(dir)) != NULL) { - if ((strncmp(de->d_name, "config", 5) == 0)) - return check_repo_format(); + if ((strncmp(de->d_name, "config", 5) == 0)) { + int rfv1, rfv2; + char cpath[PATH_MAX]; + check_repo_format(); + + /* is the file we are copying friendly? */ + rfv1 = repository_format_version; + snprintf(cpath, sizeof(cpath), "%s%s", template_path, + de->d_name); + git_config_from_file(cpath, check_repo_config); + rfv2 = repository_format_version; + if (rfv1 == rfv2) { + break; + } + if (rfv2 < rfv1) { + /* the repo format specified in the conf file + * we are copying is older than the repo we + * are re-initialising! Downgrading? + */ + fprintf(stderr, "Possibly downgrading repo" + " format version from %d to %d. Check" + " config template file!\n", rfv1, rfv2); + break; + } else + /* OK we die */ + die ("Won't copy config file" + " for repo format version %d over" + " one for version %d", + rfv2, rfv1); + } } return 0; } --- 0.99.9.GIT