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

Skip to content

SHA256 improvements #6965

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 9 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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: take an options structure for repository_new
Future-proof the SHA256-ification of `git_repository_new` by taking an
options structure instead of an oid type.
  • Loading branch information
ethomson committed Dec 18, 2024
commit 622035e6ad284e2e468d1b482e3ad4c718dff96e
46 changes: 44 additions & 2 deletions include/git2/sys/repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,56 @@ GIT_BEGIN_DECL

#ifdef GIT_EXPERIMENTAL_SHA256

/**
* The options for creating an repository from scratch.
*
* Initialize with `GIT_REPOSITORY_NEW_OPTIONS_INIT`. Alternatively,
* you can use `git_repository_new_options_init`.
*
* @options[version] GIT_REPOSITORY_NEW_OPTIONS_VERSION
* @options[init_macro] GIT_REPOSITORY_NEW_OPTIONS_INIT
* @options[init_function] git_repository_new_options_init
*/
typedef struct git_repository_new_options {
unsigned int version; /**< The version */

/**
* The object ID type for the object IDs that exist in the index.
*
* If this is not specified, this defaults to `GIT_OID_SHA1`.
*/
git_oid_t oid_type;
} git_repository_new_options;

/** Current version for the `git_repository_new_options` structure */
#define GIT_REPOSITORY_NEW_OPTIONS_VERSION 1

/** Static constructor for `git_repository_new_options` */
#define GIT_REPOSITORY_NEW_OPTIONS_INIT { GIT_REPOSITORY_NEW_OPTIONS_VERSION }

/**
* Initialize git_repository_new_options structure
*
* Initializes a `git_repository_new_options` with default values.
* Equivalent to creating an instance with
* `GIT_REPOSITORY_NEW_OPTIONS_INIT`.
*
* @param opts The `git_repository_new_options` struct to initialize.
* @param version The struct version; pass `GIT_REPOSITORY_NEW_OPTIONS_VERSION`.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_repository_new_options_init(
git_repository_new_options *opts,
unsigned int version);

/**
* Create a new repository with no backends.
*
* @param[out] out The blank repository
* @param oid_type the object ID type for this repository
* @param opts the options for repository creation, or NULL for defaults
* @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_new(git_repository **out, git_oid_t oid_type);
GIT_EXTERN(int) git_repository_new(git_repository **out, git_repository_new_options *opts);
#else

/**
Expand Down
6 changes: 4 additions & 2 deletions src/libgit2/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ int git_repository__new(git_repository **out, git_oid_t oid_type)
*out = repo = repository_alloc();
GIT_ERROR_CHECK_ALLOC(repo);

GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type));

repo->is_bare = 1;
repo->is_worktree = 0;
repo->oid_type = oid_type;
Expand All @@ -343,9 +345,9 @@ int git_repository__new(git_repository **out, git_oid_t oid_type)
}

#ifdef GIT_EXPERIMENTAL_SHA256
int git_repository_new(git_repository **out, git_oid_t oid_type)
int git_repository_new(git_repository **out, git_repository_new_options *opts)
{
return git_repository__new(out, oid_type);
return git_repository__new(out, opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT);
}
#else
int git_repository_new(git_repository** out)
Expand Down
2 changes: 1 addition & 1 deletion tests/libgit2/attr/repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void test_attr_repo__inmemory_repo_without_index(void)

/* setup bare in-memory repo without index */
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_repository_new(&inmemory, GIT_OID_SHA1));
cl_git_pass(git_repository_new(&inmemory, NULL));
#else
cl_git_pass(git_repository_new(&inmemory));
#endif
Expand Down
6 changes: 5 additions & 1 deletion tests/libgit2/network/remote/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,14 @@ void test_network_remote_local__anonymous_remote_inmemory_repo(void)
git_repository *inmemory;
git_remote *remote;

#ifdef GIT_EXPERIMENTAL_SHA256
git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT;
#endif

git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git")));

#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_repository_new(&inmemory, GIT_OID_SHA1));
cl_git_pass(git_repository_new(&inmemory, &repo_opts));
#else
cl_git_pass(git_repository_new(&inmemory));
#endif
Expand Down
6 changes: 5 additions & 1 deletion tests/libgit2/odb/backend/nobackend.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ void test_odb_backend_nobackend__initialize(void)
git_refdb *refdb;

#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_repository_new(&_repo, GIT_OID_SHA1));
git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT;

repo_opts.oid_type = GIT_OID_SHA1;

cl_git_pass(git_repository_new(&_repo, &repo_opts));
#else
cl_git_pass(git_repository_new(&_repo));
#endif
Expand Down
23 changes: 19 additions & 4 deletions tests/libgit2/repo/new.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ void test_repo_new__has_nothing(void)
git_repository *repo;

#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1));
git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT;

repo_opts.oid_type = GIT_OID_SHA1;

cl_git_pass(git_repository_new(&repo, &repo_opts));
#else
cl_git_pass(git_repository_new(&repo));
#endif
Expand All @@ -21,7 +25,11 @@ void test_repo_new__is_bare_until_workdir_set(void)
git_repository *repo;

#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1));
git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT;

repo_opts.oid_type = GIT_OID_SHA1;

cl_git_pass(git_repository_new(&repo, &repo_opts));
#else
cl_git_pass(git_repository_new(&repo));
#endif
Expand All @@ -38,7 +46,11 @@ void test_repo_new__sha1(void)
git_repository *repo;

#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1));
git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT;

repo_opts.oid_type = GIT_OID_SHA1;

cl_git_pass(git_repository_new(&repo, &repo_opts));
#else
cl_git_pass(git_repository_new(&repo));
#endif
Expand All @@ -53,8 +65,11 @@ void test_repo_new__sha256(void)
cl_skip();
#else
git_repository *repo;
git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT;

repo_opts.oid_type = GIT_OID_SHA256;

cl_git_pass(git_repository_new(&repo, GIT_OID_SHA256));
cl_git_pass(git_repository_new(&repo, &repo_opts));
cl_assert_equal_i(GIT_OID_SHA256, git_repository_oid_type(repo));

git_repository_free(repo);
Expand Down
0