8000 SHA256: more SHA256 support by ethomson · Pull Request #6456 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

SHA256: more SHA256 support #6456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repo: don't overwrite repo format version on reinit
Ensure that we maintain the `core.repositoryFormatVersion` value instead
of always overwriting it with the default.
  • Loading branch information
ethomson committed Feb 12, 2023
commit 366973f3785b7a2cf95a118fc4e13210ca277529
24 changes: 16 additions & 8 deletions src/libgit2/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ static int load_objectformat(git_repository *repo, git_config *config);

#define GIT_BRANCH_DEFAULT "master"

#define GIT_REPO_VERSION 0
#define GIT_REPO_MAX_VERSION 1
#define GIT_REPO_VERSION_DEFAULT 0
#define GIT_REPO_VERSION_MAX 1

git_str git_repository__reserved_names_win32[] = {
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
Expand Down Expand Up @@ -1016,7 +1016,8 @@ int git_repository_open_ext(
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;

if (config && (error = check_repositoryformatversion(&version, config)) < 0)
if (config &&
(error = check_repositoryformatversion(&version, config)) < 0)
goto cleanup;

if ((error = check_extensions(config, version)) < 0)
Expand Down Expand Up @@ -1539,17 +1540,23 @@ static int check_repositoryformatversion(int *version, git_config *config)
int error;

error = git_config_get_int32(version, config, "core.repositoryformatversion");

/* git ignores this if the config variable isn't there */
if (error == GIT_ENOTFOUND)
return 0;

if (error < 0)
return -1;

if (GIT_REPO_MAX_VERSION < *version) {
if (*version < 0) {
git_error_set(GIT_ERROR_REPOSITORY,
"invalid repository version %d", *version);
}

if (GIT_REPO_VERSION_MAX < *version) {
git_error_set(GIT_ERROR_REPOSITORY,
"unsupported repository version %d; only versions up to %d are supported",
*version, GIT_REPO_MAX_VERSION);
*version, GIT_REPO_VERSION_MAX);
return -1;
}

Expand Down Expand Up @@ -1963,12 +1970,13 @@ static int repo_init_config(
git_config *config = NULL;
bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
int version = 0;
int version = GIT_REPO_VERSION_DEFAULT;

if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0)
goto cleanup;

if (is_reinit && (error = check_repositoryformatversion(&version, config)) < 0)
if (is_reinit &&
(error = check_repositoryformatversion(&version, config)) < 0)
goto cleanup;

if ((error = check_extensions(config, version)) < 0)
Expand All @@ -1979,7 +1987,7 @@ static int repo_init_config(
goto cleanup; } while (0)

SET_REPO_CONFIG(bool, "core.bare", is_bare);
SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION);
SET_REPO_CONFIG(int32, "core.repositoryformatversion", version);

if ((error = repo_init_fs_configs(
config, cfg_path.ptr, repo_dir, work_dir, !is_reinit)) < 0)
Expand Down
33 changes: 26 additions & 7 deletions tests/libg E4BC it2/repo/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,46 @@ void test_repo_init__reinit_bare_repo(void)
cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
}

void test_repo_init__reinit_too_recent_bare_repo(void)
void test_repo_init__reinit_nondefault_version(void)
{
git_config *config;

cl_set_cleanup(&cleanup_repository, "reinit.git");

/* Initialize the repository */
cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
git_repository_config(&config, g_repo);

/* Set the config to a supported but not default version */
cl_repo_set_string(g_repo, "core.repositoryformatversion", "1");
git_config_free(config);
git_repository_free(g_repo);
g_repo = NULL;

/* Try to reinitialize the repository */
cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
cl_assert_equal_i(1, cl_repo_get_int(g_repo, "core.repositoryformatversion"));

cl_fixture_cleanup("reinit.git");
}

void test_repo_init__reinit_unsupported_version(void)
{
cl_set_cleanup(&cleanup_repository, "reinit.git");

/* Initialize the repository */
cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));

/*
* Hack the config of the repository to make it look like it has
* been created by a recenter version of git/libgit2
* been created by a too new and unsupported version of git/libgit2
*/
cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 42));

git_config_free(config);
cl_repo_set_string(g_repo, "core.repositoryformatversion", "42");
git_repository_free(g_repo);
g_repo = NULL;

/* Try to reinitialize the repository */
/* Try and fail to reinitialize the repository */
cl_git_fail(git_repository_init(&g_repo, "reinit.git", 1));

cl_fixture_cleanup("reinit.git");
}

Expand Down
0