diff options
author | Vicent Marti <tanoku@gmail.com> | 2015-06-24 12:33:27 +0200 |
---|---|---|
committer | Carlos MartÃn Nieto <cmn@dwim.me> | 2015-10-11 17:23:09 +0200 |
commit | d59b9681737ce3f9cce16c611131b242626fc412 (patch) | |
tree | d8de65301440fb586a6021c62484c34ab90cc3c6 | |
parent | d8dc2b8f54cdf7d707c6a552175dc0d619dc230e (diff) | |
download | libgit2-d59b9681737ce3f9cce16c611131b242626fc412.tar.gz |
repo: Add support for formatversion 1
-rw-r--r-- | src/repository.c | 51 | ||||
-rw-r--r-- | src/repository.h | 3 | ||||
-rw-r--r-- | tests/repo/open.c | 24 |
3 files changed, 65 insertions, 13 deletions
diff --git a/src/repository.c b/src/repository.c index 77145cfc8..f7f79b566 100644 --- a/src/repository.c +++ b/src/repository.c @@ -32,13 +32,15 @@ # include "win32/w32_util.h" #endif -static int check_repositoryformatversion(git_config *config); +static int check_repositoryformatversion(int *version, git_config *config); +static int check_extensions(git_repository *repo, git_config *config); #define GIT_FILE_CONTENT_PREFIX "gitdir:" #define GIT_BRANCH_MASTER "master" #define GIT_REPO_VERSION 0 +#define GIT_REPO_VERSION_MAX_ALLOWED 1 git_buf git_repository__reserved_names_win32[] = { { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) }, @@ -491,6 +493,7 @@ int git_repository_open_ext( link_path = GIT_BUF_INIT; git_repository *repo; git_config *config = NULL; + int version = GIT_REPO_VERSION; if (repo_ptr) *repo_ptr = NULL; @@ -521,13 +524,18 @@ int git_repository_open_ext( if (error < 0 && error != GIT_ENOTFOUND) goto cleanup; - if (config && (error = check_repositoryformatversion(config)) < 0) + if (config && (error = check_repositoryformatversion(&version, config)) < 0) goto cleanup; + if (version >= 1) { + repo->has_extensions = 1; + if ((error = check_extensions(repo, config)) < 0) + goto cleanup; + } + if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) repo->is_bare = 1; else { - if (config && ((error = load_config_data(repo, config)) < 0 || (error = load_workdir(repo, config, &parent)) < 0)) @@ -964,28 +972,48 @@ bool git_repository__reserved_names( } #endif -static int check_repositoryformatversion(git_config *config) +static int check_repositoryformatversion(int *version, git_config *config) { - int version, error; + int error; - error = git_config_get_int32(&version, config, "core.repositoryformatversion"); + error = git_config_get_int32(version, config, "core.repositoryformatversion"); /* git ignores this if the config variable isn't there */ - if (error == GIT_ENOTFOUND) + if (error == GIT_ENOTFOUND) { + giterr_clear(); return 0; + } if (error < 0) return -1; - if (GIT_REPO_VERSION < version) { + if (*version > GIT_REPO_VERSION_MAX_ALLOWED) { giterr_set(GITERR_REPOSITORY, "Unsupported repository version %d. Only versions up to %d are supported.", - version, GIT_REPO_VERSION); + *version, GIT_REPO_VERSION_MAX_ALLOWED); return -1; } return 0; } +static int extension_each_cb(const git_config_entry *entry, void *payload) +{ + const char *name = entry->name + strlen("extensions."); + (void)payload; + + if (!strcmp(name, "noop")) + return 0; + + giterr_set(GITERR_REPOSITORY, "Unknown Git repository extension: %s", name); + return -1; +} + +static int check_extensions(git_repository *repo, git_config *config) +{ + return git_config_foreach_match( + config, "^extensions\\..*", extension_each_cb, repo); +} + static int repo_init_create_head(const char *git_dir, const char *ref_name) { git_buf ref_path = GIT_BUF_INIT; @@ -1176,11 +1204,12 @@ 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 = GIT_REPO_VERSION; if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0) goto cleanup; - if (is_reinit && (error = check_repositoryformatversion(config)) < 0) + if (is_reinit && (error = check_repositoryformatversion(&version, config)) < 0) goto cleanup; #define SET_REPO_CONFIG(TYPE, NAME, VAL) do { \ @@ -1188,7 +1217,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) diff --git a/src/repository.h b/src/repository.h index fd679b483..aec89f6fb 100644 --- a/src/repository.h +++ b/src/repository.h @@ -136,7 +136,8 @@ struct git_repository { git_array_t(git_buf) reserved_names; - unsigned is_bare:1; + unsigned is_bare:1, + has_extensions:1; unsigned int lru_counter; diff --git a/tests/repo/open.c b/tests/repo/open.c index d3d087231..de9193a78 100644 --- a/tests/repo/open.c +++ b/tests/repo/open.c @@ -26,14 +26,36 @@ void test_repo_open__format_version_1(void) git_config *config; repo = cl_git_sandbox_init("empty_bare.git"); + cl_git_pass(git_repository_open(&repo, "empty_bare.git")); + + + /* Set repo format version to 1, try to open (should pass) */ + cl_git_pass(git_repository_config(&config, repo)); + cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 1)); + + git_config_free(config); + git_repository_free(repo); cl_git_pass(git_repository_open(&repo, "empty_bare.git")); + + + /* Set noop extension, try to open (should pass) */ cl_git_pass(git_repository_config(&config, repo)); + cl_git_pass(git_config_set_bool(config, "extensions.noop", true)); - cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 1)); + git_config_free(config); + git_repository_free(repo); + + cl_git_pass(git_repository_open(&repo, "empty_bare.git")); + + + /* Set unknown extension, try to open (should fail) */ + cl_git_pass(git_repository_config(&config, repo)); + cl_git_pass(git_config_set_bool(config, "extensions.foobar", true)); git_config_free(config); git_repository_free(repo); + cl_git_fail(git_repository_open(&repo, "empty_bare.git")); } |