mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 21:08:56 +00:00
clone: add a callback for repository creation
Analogously to the remote creation callback, provide a way for the user of git_clone() to create the repository with whichever options they desire via callback.
This commit is contained in:
parent
dcdb8500e3
commit
d58a64e9a5
@ -25,3 +25,7 @@ v0.21 + 1
|
|||||||
|
|
||||||
The remote_callbacks member has been preserved for convenience, although it
|
The remote_callbacks member has been preserved for convenience, although it
|
||||||
is not used when a remote creation callback is supplied.
|
is not used when a remote creation callback is supplied.
|
||||||
|
|
||||||
|
* The git_clone_options struct now provides repository_cb and
|
||||||
|
repository_cb_payload to allow the user to create a repository with
|
||||||
|
custom options.
|
||||||
|
@ -73,6 +73,26 @@ typedef int (*git_remote_create_cb)(
|
|||||||
const char *url,
|
const char *url,
|
||||||
void *payload);
|
void *payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The signature of a function matchin git_repository_init, with an
|
||||||
|
* aditional void * as callback payload.
|
||||||
|
*
|
||||||
|
* Callers of git_clone my provide a function matching this signature
|
||||||
|
* to override the repository creation and customization process
|
||||||
|
* during a clone operation.
|
||||||
|
*
|
||||||
|
* @param out the resulting repository
|
||||||
|
* @param path path in which to create the repository
|
||||||
|
* @param bare whether the repository is bare. This is the value from the clone options
|
||||||
|
* @param payload payload specified by the options
|
||||||
|
* @return 0, or a negative value to indicate error
|
||||||
|
*/
|
||||||
|
typedef int (*git_repository_create_cb)(
|
||||||
|
git_repository **out,
|
||||||
|
const char *path,
|
||||||
|
int bare,
|
||||||
|
void *payload);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone options structure
|
* Clone options structure
|
||||||
*
|
*
|
||||||
@ -125,6 +145,19 @@ typedef struct git_clone_options {
|
|||||||
*/
|
*/
|
||||||
git_signature *signature;
|
git_signature *signature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A callback used to create the new repository into which to
|
||||||
|
* clone. If NULL, the 'bare' field will be used to determine
|
||||||
|
* whether to create a bare repository.
|
||||||
|
*/
|
||||||
|
git_repository_create_cb repository_cb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An opaque payload to pass to the git_repository creation callback.
|
||||||
|
* This parameter is ignored unless repository_cb is non-NULL.
|
||||||
|
*/
|
||||||
|
void *repository_cb_payload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A callback used to create the git_remote, prior to its being
|
* A callback used to create the git_remote, prior to its being
|
||||||
* used to perform the clone operation. See the documentation for
|
* used to perform the clone operation. See the documentation for
|
||||||
@ -158,9 +191,9 @@ GIT_EXTERN(int) git_clone_init_options(
|
|||||||
/**
|
/**
|
||||||
* Clone a remote repository.
|
* Clone a remote repository.
|
||||||
*
|
*
|
||||||
* This version handles the simple case. If you'd like to create the
|
* By default this creates its repository and initial remote to match
|
||||||
* repository or remote with non-default settings, you can create and
|
* git's defaults. You can use the options in the callback to
|
||||||
* configure them and then use `git_clone_into()`.
|
* customize how these are created.
|
||||||
*
|
*
|
||||||
* @param out pointer that will receive the resulting repository object
|
* @param out pointer that will receive the resulting repository object
|
||||||
* @param url the remote repository to clone
|
* @param url the remote repository to clone
|
||||||
|
15
src/clone.c
15
src/clone.c
@ -229,6 +229,13 @@ cleanup:
|
|||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int default_repository_create(git_repository **out, const char *path, int bare, void *payload)
|
||||||
|
{
|
||||||
|
GIT_UNUSED(payload);
|
||||||
|
|
||||||
|
return git_repository_init(out, path, bare);
|
||||||
|
}
|
||||||
|
|
||||||
static int default_remote_create(
|
static int default_remote_create(
|
||||||
git_remote **out,
|
git_remote **out,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
@ -396,6 +403,7 @@ int git_clone(
|
|||||||
git_remote *origin;
|
git_remote *origin;
|
||||||
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
|
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
|
||||||
uint32_t rmdir_flags = GIT_RMDIR_REMOVE_FILES;
|
uint32_t rmdir_flags = GIT_RMDIR_REMOVE_FILES;
|
||||||
|
git_repository_create_cb repository_cb;
|
||||||
|
|
||||||
assert(out && url && local_path);
|
assert(out && url && local_path);
|
||||||
|
|
||||||
@ -415,7 +423,12 @@ int git_clone(
|
|||||||
if (git_path_exists(local_path))
|
if (git_path_exists(local_path))
|
||||||
rmdir_flags |= GIT_RMDIR_SKIP_ROOT;
|
rmdir_flags |= GIT_RMDIR_SKIP_ROOT;
|
||||||
|
|
||||||
if ((error = git_repository_init(&repo, local_path, options.bare)) < 0)
|
if (options.repository_cb)
|
||||||
|
repository_cb = options.repository_cb;
|
||||||
|
else
|
||||||
|
repository_cb = default_repository_create;
|
||||||
|
|
||||||
|
if ((error = repository_cb(&repo, local_path, options.bare, options.repository_cb_payload)) < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (!(error = create_and_configure_origin(&origin, repo, url, &options))) {
|
if (!(error = create_and_configure_origin(&origin, repo, url, &options))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user