[PATCH 2/6] Make init-db check repo format version if copying a config file.
- From
- Martin Atukunda <matlads@dsmagic.com>
- Date
- Nov 22, 2005, 00:28 UTC
- Message-ID
- <11326192922669-git-send-email-matlads@dsmagic.com>
- In-Reply-To
- <11326192921291-git-send-email-matlads@dsmagic.com>
This patch enables init-db to check the repo format version for a repository being re-initialised. If the version of the repo is larger than GIT_VERSION_REPO, it simply dies with an appropriate message.
Signed-Off-By: Martin Atukunda <matlads@dsmagic.com>
---
init-db.c | 14 ++++++++++++++ setup.c | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)
applies-to: 3e86d91031df530695933e7d9d5d8d9c2f3a683d 601dd50b595a9aa0a57972364262d98290a5d7b2
diff --git a/init-db.c b/init-db.c index bd88291..90be428 100644 --- a/init-db.c +++ b/init-db.c @@ -110,6 +110,19 @@ static void copy_templates_1(char *path, } } +static int init_db_config_check(const char *template_path) +{ + DIR *dir; + struct dirent *de; + + dir = opendir(template_path); + while((de = readdir(dir)) != NULL) { + if ((strncmp(de->d_name, "config", 5) == 0)) + return check_repo_format(); + } + return 0; +} + static void copy_templates(const char *git_dir, int len, char *template_dir) { char path[PATH_MAX]; @@ -131,6 +144,7 @@ static void copy_templates(const char *g template_dir); return; } + init_db_config_check(template_path); memcpy(path, git_dir, len); path[len] = 0; diff --git a/setup.c b/setup.c index c487d7e..8597424 100644 --- a/setup.c +++ b/setup.c @@ -127,3 +127,22 @@ const char *setup_git_directory(void) cwd[len] = 0; return cwd + offset; } + +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; +} + +int check_repo_format(void) +{ + if (git_config(check_repo_config) == -1) + return -1; + if (repository_format_version > GIT_REPO_VERSION) + die ("Expected git repo version <= %d, found %d", GIT_REPO_VERSION, + repository_format_version); + return 0; +} --- 0.99.9.GIT