Browse Source

repository: allow repository format upgrade with extensions

Now that we officially permit repository extensions in repository
format v0, permit upgrading a repository with extensions from v0 to v1
as well.

For example, this means a repository where the user has set
"extensions.preciousObjects" can use "git fetch --filter=blob:none
origin" to upgrade the repository to use v1 and the partial clone
extension.

To avoid mistakes, continue to forbid repository format upgrades in v0
repositories with an unrecognized extension.  This way, a v0 user
using a misspelled extension field gets a chance to correct the
mistake before updating to the less forgiving v1 format.

While we're here, make the error message for failure to upgrade the
repository format a bit shorter, and present it as an error, not a
warning.

Reported-by: Huan Huan Chen <huanhuanchen@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Jonathan Nieder 5 years ago committed by Junio C Hamano
parent
commit
62f2eca606
  1. 1
      cache.h
  2. 12
      setup.c
  3. 4
      t/t0410-partial-clone.sh

1
cache.h

@ -1042,7 +1042,6 @@ struct repository_format { @@ -1042,7 +1042,6 @@ struct repository_format {
int worktree_config;
int is_bare;
int hash_algo;
int has_extensions;
char *work_tree;
struct string_list unknown_extensions;
};

12
setup.c

@ -455,7 +455,6 @@ static int check_repo_format(const char *var, const char *value, void *vdata) @@ -455,7 +455,6 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
if (strcmp(var, "core.repositoryformatversion") == 0)
data->version = git_config_int(var, value);
else if (skip_prefix(var, "extensions.", &ext)) {
data->has_extensions = 1;
/*
* record any known extensions here; otherwise,
* we fall through to recording it as unknown, and
@ -553,13 +552,16 @@ int upgrade_repository_format(int target_version) @@ -553,13 +552,16 @@ int upgrade_repository_format(int target_version)
if (repo_fmt.version >= target_version)
return 0;

if (verify_repository_format(&repo_fmt, &err) < 0 ||
(!repo_fmt.version && repo_fmt.has_extensions)) {
warning("unable to upgrade repository format from %d to %d: %s",
repo_fmt.version, target_version, err.buf);
if (verify_repository_format(&repo_fmt, &err) < 0) {
error("cannot upgrade repository format from %d to %d: %s",
repo_fmt.version, target_version, err.buf);
strbuf_release(&err);
return -1;
}
if (!repo_fmt.version && repo_fmt.unknown_extensions.nr)
return error("cannot upgrade repository format: "
"unknown extension %s",
repo_fmt.unknown_extensions.items[0].string);

strbuf_addf(&repo_version, "%d", target_version);
git_config_set("core.repositoryformatversion", repo_version.buf);

4
t/t0410-partial-clone.sh

@ -42,7 +42,7 @@ test_expect_success 'convert shallow clone to partial clone' ' @@ -42,7 +42,7 @@ test_expect_success 'convert shallow clone to partial clone' '
test_cmp_config -C client 1 core.repositoryformatversion
'

test_expect_success 'converting to partial clone fails with noop extension' '
test_expect_success 'convert to partial clone with noop extension' '
rm -fr server client &&
test_create_repo server &&
test_commit -C server my_commit 1 &&
@ -50,7 +50,7 @@ test_expect_success 'converting to partial clone fails with noop extension' ' @@ -50,7 +50,7 @@ test_expect_success 'converting to partial clone fails with noop extension' '
git clone --depth=1 "file://$(pwd)/server" client &&
test_cmp_config -C client 0 core.repositoryformatversion &&
git -C client config extensions.noop true &&
test_must_fail git -C client fetch --unshallow --filter="blob:none"
git -C client fetch --unshallow --filter="blob:none"
'

test_expect_success 'converting to partial clone fails with unrecognized extension' '

Loading…
Cancel
Save