From: Martin Atukunda <matlads@dsmagic.com>
To: git@vger.kernel.org
Cc: Martin Atukunda <matlads@dsmagic.com>
Subject: [PATCH 6/6] Add check for downgrading of repo format version via init-db
Date: Tue, 22 Nov 2005 03:28:13 +0300 [thread overview]
Message-ID: <11326192931463-git-send-email-matlads@dsmagic.com> (raw)
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
next prev parent reply other threads:[~2005-11-22 0:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-22 0:28 Git Future Proofing Martin Atukunda
2005-11-22 0:28 ` [PATCH 1/6] Add GIT_REPO_VERSION, and repository_format_version Martin Atukunda
2005-11-22 0:28 ` [PATCH 3/6] Make get_git_dir take a flag that makes it re-read the env. variables Martin Atukunda
2005-11-22 0:28 ` [PATCH 2/6] Make init-db check repo format version if copying a config file Martin Atukunda
2005-11-22 0:28 ` [PATCH 4/6] Add check_repo_format check for all major operations Martin Atukunda
2005-11-22 8:29 ` Junio C Hamano
2005-11-22 12:55 ` Martin Atukunda
2005-11-22 17:46 ` Junio C Hamano
2005-11-23 0:57 ` Junio C Hamano
2005-11-22 0:28 ` Martin Atukunda [this message]
2005-11-22 0:28 ` [PATCH 5/6] Allow Specification of the conf file to read for git_config operations Martin Atukunda
2005-11-22 1:13 ` Git Future Proofing Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11326192931463-git-send-email-matlads@dsmagic.com \
--to=matlads@dsmagic.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).