Blame include/git2/clone.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_git_clone_h__
Packit Service 20376f
#define INCLUDE_git_clone_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "indexer.h"
Packit Service 20376f
#include "checkout.h"
Packit Service 20376f
#include "remote.h"
Packit Service 20376f
#include "transport.h"
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/clone.h
Packit Service 20376f
 * @brief Git cloning routines
Packit Service 20376f
 * @defgroup git_clone Git cloning routines
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Options for bypassing the git-aware transport on clone. Bypassing
Packit Service 20376f
 * it means that instead of a fetch, libgit2 will copy the object
Packit Service 20376f
 * database directory instead of figuring out what it needs, which is
Packit Service 20376f
 * faster. If possible, it will hardlink the files to save space.
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/**
Packit Service 20376f
	 * Auto-detect (default), libgit2 will bypass the git-aware
Packit Service 20376f
	 * transport for local paths, but use a normal fetch for
Packit Service 20376f
	 * `file://` urls.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CLONE_LOCAL_AUTO,
Packit Service 20376f
	/**
Packit Service 20376f
	 * Bypass the git-aware transport even for a `file://` url.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CLONE_LOCAL,
Packit Service 20376f
	/**
Packit Service 20376f
	 * Do no bypass the git-aware transport
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CLONE_NO_LOCAL,
Packit Service 20376f
	/**
Packit Service 20376f
	 * Bypass the git-aware transport, but do not try to use
Packit Service 20376f
	 * hardlinks.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_CLONE_LOCAL_NO_LINKS,
Packit Service 20376f
} git_clone_local_t;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * The signature of a function matching git_remote_create, with an additional
Packit Service 20376f
 * void* as a callback payload.
Packit Service 20376f
 *
Packit Service 20376f
 * Callers of git_clone may provide a function matching this signature to override
Packit Service 20376f
 * the remote creation and customization process during a clone operation.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out the resulting remote
Packit Service 20376f
 * @param repo the repository in which to create the remote
Packit Service 20376f
 * @param name the remote's name
Packit Service 20376f
 * @param url the remote's url
Packit Service 20376f
 * @param payload an opaque payload
Packit Service 20376f
 * @return 0, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
Packit Service 20376f
 */
Packit Service 20376f
typedef int (*git_remote_create_cb)(
Packit Service 20376f
	git_remote **out,
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *name,
Packit Service 20376f
	const char *url,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * The signature of a function matchin git_repository_init, with an
Packit Service 20376f
 * aditional void * as callback payload.
Packit Service 20376f
 *
Packit Service 20376f
 * Callers of git_clone my provide a function matching this signature
Packit Service 20376f
 * to override the repository creation and customization process
Packit Service 20376f
 * during a clone operation.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out the resulting repository
Packit Service 20376f
 * @param path path in which to create the repository
Packit Service 20376f
 * @param bare whether the repository is bare. This is the value from the clone options
Packit Service 20376f
 * @param payload payload specified by the options
Packit Service 20376f
 * @return 0, or a negative value to indicate error
Packit Service 20376f
 */
Packit Service 20376f
typedef int (*git_repository_create_cb)(
Packit Service 20376f
	git_repository **out,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	int bare,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Clone options structure
Packit Service 20376f
 *
Packit Service 20376f
 * Use the GIT_CLONE_OPTIONS_INIT to get the default settings, like this:
Packit Service 20376f
 *
Packit Service 20376f
 *		git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_clone_options {
Packit Service 20376f
	unsigned int version;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * These options are passed to the checkout step. To disable
Packit Service 20376f
	 * checkout, set the `checkout_strategy` to
Packit Service 20376f
	 * `GIT_CHECKOUT_NONE`.
Packit Service 20376f
	 */
Packit Service 20376f
	git_checkout_options checkout_opts;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Options which control the fetch, including callbacks.
Packit Service 20376f
	 *
Packit Service 20376f
	 * The callbacks are used for reporting fetch progress, and for acquiring
Packit Service 20376f
	 * credentials in the event they are needed.
Packit Service 20376f
	 */
Packit Service 20376f
	git_fetch_options fetch_opts;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Set to zero (false) to create a standard repo, or non-zero
Packit Service 20376f
	 * for a bare repo
Packit Service 20376f
	 */
Packit Service 20376f
	int bare;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Whether to use a fetch or copy the object database.
Packit Service 20376f
	 */
Packit Service 20376f
	git_clone_local_t local;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * The name of the branch to checkout. NULL means use the
Packit Service 20376f
	 * remote's default branch.
Packit Service 20376f
	 */
Packit Service 20376f
	const char* checkout_branch;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * A callback used to create the new repository into which to
Packit Service 20376f
	 * clone. If NULL, the 'bare' field will be used to determine
Packit Service 20376f
	 * whether to create a bare repository.
Packit Service 20376f
	 */
Packit Service 20376f
	git_repository_create_cb repository_cb;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * An opaque payload to pass to the git_repository creation callback.
Packit Service 20376f
	 * This parameter is ignored unless repository_cb is non-NULL.
Packit Service 20376f
	 */
Packit Service 20376f
	void *repository_cb_payload;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * A callback used to create the git_remote, prior to its being
Packit Service 20376f
	 * used to perform the clone operation. See the documentation for
Packit Service 20376f
	 * git_remote_create_cb for details. This parameter may be NULL,
Packit Service 20376f
	 * indicating that git_clone should provide default behavior.
Packit Service 20376f
	 */
Packit Service 20376f
	git_remote_create_cb remote_cb;
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * An opaque payload to pass to the git_remote creation callback.
Packit Service 20376f
	 * This parameter is ignored unless remote_cb is non-NULL.
Packit Service 20376f
	 */
Packit Service 20376f
	void *remote_cb_payload;
Packit Service 20376f
} git_clone_options;
Packit Service 20376f
Packit Service 20376f
#define GIT_CLONE_OPTIONS_VERSION 1
Packit Service 20376f
#define GIT_CLONE_OPTIONS_INIT { GIT_CLONE_OPTIONS_VERSION, \
Packit Service 20376f
	{ GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE }, \
Packit Service 20376f
	GIT_FETCH_OPTIONS_INIT }
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initializes a `git_clone_options` with default values. Equivalent to
Packit Service 20376f
 * creating an instance with GIT_CLONE_OPTIONS_INIT.
Packit Service 20376f
 *
Packit Service 20376f
 * @param opts The `git_clone_options` struct to initialize
Packit Service 20376f
 * @param version Version of struct; pass `GIT_CLONE_OPTIONS_VERSION`
Packit Service 20376f
 * @return Zero on success; -1 on failure.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_clone_init_options(
Packit Service 20376f
	git_clone_options *opts,
Packit Service 20376f
	unsigned int version);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Clone a remote repository.
Packit Service 20376f
 *
Packit Service 20376f
 * By default this creates its repository and initial remote to match
Packit Service 20376f
 * git's defaults. You can use the options in the callback to
Packit Service 20376f
 * customize how these are created.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer that will receive the resulting repository object
Packit Service 20376f
 * @param url the remote repository to clone
Packit Service 20376f
 * @param local_path local directory to clone to
Packit Service 20376f
 * @param options configuration options for the clone.  If NULL, the
Packit Service 20376f
 *        function works as though GIT_OPTIONS_INIT were passed.
Packit Service 20376f
 * @return 0 on success, any non-zero return value from a callback
Packit Service 20376f
 *         function, or a negative value to indicate an error (use
Packit Service 20376f
 *         `giterr_last` for a detailed error message)
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_clone(
Packit Service 20376f
	git_repository **out,
Packit Service 20376f
	const char *url,
Packit Service 20376f
	const char *local_path,
Packit Service 20376f
	const git_clone_options *options);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif