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.
This commit is contained in:
Edward Thomson
2024-12-17 10:40:29 +00:00
parent 43c31ecc42
commit 622035e6ad
6 changed files with 78 additions and 11 deletions

View File

@@ -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
/**