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

[PATCH 6/6] Add check for downgrading of repo format version via init-db

From
MAMartin 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
Previous: Martin AtukundaNext: Junio C Hamano
Message 11 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.