git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/6] Make init-db check repo format version if copying a config file.

From
MAMartin 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
Previous: Martin AtukundaNext: Martin Atukunda
Message 2 of 12 in “Git Future Proofing”
  1. Martin AtukundaNov 22, 2005
  2. 2/6 Make init-db check repo format version if copying a config file.Martin Atukunda, Nov 22, 2005
  3. 3/6 Make get_git_dir take a flag that makes it re-read the env. variablesMartin Atukunda, Nov 22, 2005
  4. 1/6 Add GIT_REPO_VERSION, and repository_format_versionMartin Atukunda, Nov 22, 2005
  5. 4/6 Add check_repo_format check for all major operations.Martin Atukunda, Nov 22, 2005
  6. Junio C HamanoNov 22, 2005
  7. Martin AtukundaNov 22, 2005
  8. Junio C HamanoNov 22, 2005
  9. Junio C HamanoNov 23, 2005
  10. 5/6 Allow Specification of the conf file to read for git_config operationsMartin Atukunda, Nov 22, 2005
  11. 6/6 Add check for downgrading of repo format version via init-dbMartin Atukunda, Nov 22, 2005
  12. Junio C HamanoNov 22, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.