chore: upgrade to libgit2-1.2.0

This commit is contained in:
Aleksey Kulikov 2021-09-17 18:22:01 +03:00
parent b83fea9360
commit a1e420d86c
36 changed files with 2889 additions and 1024 deletions

File diff suppressed because it is too large Load diff

View file

@ -5,15 +5,15 @@ import 'bindings/libgit2_bindings.dart';
DynamicLibrary loadLibrary() { DynamicLibrary loadLibrary() {
if (Platform.isLinux || Platform.isAndroid || Platform.isFuchsia) { if (Platform.isLinux || Platform.isAndroid || Platform.isFuchsia) {
return DynamicLibrary.open( return DynamicLibrary.open(
'${Directory.current.path}/libgit2/libgit2-1.1.1.so'); '${Directory.current.path}/libgit2/libgit2-1.2.0.so');
} }
if (Platform.isMacOS) { if (Platform.isMacOS) {
return DynamicLibrary.open( return DynamicLibrary.open(
'${Directory.current.path}/libgit2/libgit2-1.1.1.dylib'); '${Directory.current.path}/libgit2/libgit2-1.2.0.dylib');
} }
if (Platform.isWindows) { if (Platform.isWindows) {
return DynamicLibrary.open( return DynamicLibrary.open(
'${Directory.current.path}/libgit2/libgit2-1.1.1.dll'); '${Directory.current.path}/libgit2/libgit2-1.2.0.dll');
} }
throw Exception('Platform not implemented'); throw Exception('Platform not implemented');
} }

View file

@ -130,9 +130,32 @@ GIT_EXTERN(git_attr_value_t) git_attr_value(const char *attr);
* *
* Passing the `GIT_ATTR_CHECK_INCLUDE_HEAD` flag will use attributes * Passing the `GIT_ATTR_CHECK_INCLUDE_HEAD` flag will use attributes
* from a `.gitattributes` file in the repository at the HEAD revision. * from a `.gitattributes` file in the repository at the HEAD revision.
*
* Passing the `GIT_ATTR_CHECK_INCLUDE_COMMIT` flag will use attributes
* from a `.gitattributes` file in a specific commit.
*/ */
#define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2) #define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2)
#define GIT_ATTR_CHECK_INCLUDE_HEAD (1 << 3) #define GIT_ATTR_CHECK_INCLUDE_HEAD (1 << 3)
#define GIT_ATTR_CHECK_INCLUDE_COMMIT (1 << 4)
/**
* An options structure for querying attributes.
*/
typedef struct {
unsigned int version;
/** A combination of GIT_ATTR_CHECK flags */
unsigned int flags;
/**
* The commit to load attributes from, when
* `GIT_ATTR_CHECK_INCLUDE_COMMIT` is specified.
*/
git_oid *commit_id;
} git_attr_options;
#define GIT_ATTR_OPTIONS_VERSION 1
#define GIT_ATTR_OPTIONS_INIT {GIT_ATTR_OPTIONS_VERSION}
/** /**
* Look up the value of one git attribute for path. * Look up the value of one git attribute for path.
@ -156,6 +179,28 @@ GIT_EXTERN(int) git_attr_get(
const char *path, const char *path,
const char *name); const char *name);
/**
* Look up the value of one git attribute for path with extended options.
*
* @param value_out Output of the value of the attribute. Use the GIT_ATTR_...
* macros to test for TRUE, FALSE, UNSPECIFIED, etc. or just
* use the string value for attributes set to a value. You
* should NOT modify or free this value.
* @param repo The repository containing the path.
* @param opts The `git_attr_options` to use when querying these attributes.
* @param path The path to check for attributes. Relative paths are
* interpreted relative to the repo root. The file does
* not have to exist, but if it does not, then it will be
* treated as a plain file (not a directory).
* @param name The name of the attribute to look up.
*/
GIT_EXTERN(int) git_attr_get_ext(
const char **value_out,
git_repository *repo,
git_attr_options *opts,
const char *path,
const char *name);
/** /**
* Look up a list of git attributes for path. * Look up a list of git attributes for path.
* *
@ -193,6 +238,30 @@ GIT_EXTERN(int) git_attr_get_many(
size_t num_attr, size_t num_attr,
const char **names); const char **names);
/**
* Look up a list of git attributes for path with extended options.
*
* @param values_out An array of num_attr entries that will have string
* pointers written into it for the values of the attributes.
* You should not modify or free the values that are written
* into this array (although of course, you should free the
* array itself if you allocated it).
* @param repo The repository containing the path.
* @param opts The `git_attr_options` to use when querying these attributes.
* @param path The path inside the repo to check attributes. This
* does not have to exist, but if it does not, then
* it will be treated as a plain file (i.e. not a directory).
* @param num_attr The number of attributes being looked up
* @param names An array of num_attr strings containing attribute names.
*/
GIT_EXTERN(int) git_attr_get_many_ext(
const char **values_out,
git_repository *repo,
git_attr_options *opts,
const char *path,
size_t num_attr,
const char **names);
/** /**
* The callback used with git_attr_foreach. * The callback used with git_attr_foreach.
* *
@ -231,6 +300,26 @@ GIT_EXTERN(int) git_attr_foreach(
git_attr_foreach_cb callback, git_attr_foreach_cb callback,
void *payload); void *payload);
/**
* Loop over all the git attributes for a path with extended options.
*
* @param repo The repository containing the path.
* @param opts The `git_attr_options` to use when querying these attributes.
* @param path Path inside the repo to check attributes. This does not have
* to exist, but if it does not, then it will be treated as a
* plain file (i.e. not a directory).
* @param callback Function to invoke on each attribute name and value.
* See git_attr_foreach_cb.
* @param payload Passed on as extra parameter to callback function.
* @return 0 on success, non-zero callback return value, or error code
*/
GIT_EXTERN(int) git_attr_foreach_ext(
git_repository *repo,
git_attr_options *opts,
const char *path,
git_attr_foreach_cb callback,
void *payload);
/** /**
* Flush the gitattributes cache. * Flush the gitattributes cache.
* *

View file

@ -26,27 +26,52 @@ GIT_BEGIN_DECL
typedef enum { typedef enum {
/** Normal blame, the default */ /** Normal blame, the default */
GIT_BLAME_NORMAL = 0, GIT_BLAME_NORMAL = 0,
/** Track lines that have moved within a file (like `git blame -M`).
* NOT IMPLEMENTED. */ /**
* Track lines that have moved within a file (like `git blame -M`).
*
* This is not yet implemented and reserved for future use.
*/
GIT_BLAME_TRACK_COPIES_SAME_FILE = (1<<0), GIT_BLAME_TRACK_COPIES_SAME_FILE = (1<<0),
/** Track lines that have moved across files in the same commit (like `git blame -C`).
* NOT IMPLEMENTED. */ /**
* Track lines that have moved across files in the same commit
* (like `git blame -C`).
*
* This is not yet implemented and reserved for future use.
*/
GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES = (1<<1), GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES = (1<<1),
/** Track lines that have been copied from another file that exists in the
* same commit (like `git blame -CC`). Implies SAME_FILE. /**
* NOT IMPLEMENTED. */ * Track lines that have been copied from another file that exists
* in the same commit (like `git blame -CC`). Implies SAME_FILE.
*
* This is not yet implemented and reserved for future use.
*/
GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES = (1<<2), GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES = (1<<2),
/** Track lines that have been copied from another file that exists in *any*
* commit (like `git blame -CCC`). Implies SAME_COMMIT_COPIES. /**
* NOT IMPLEMENTED. */ * Track lines that have been copied from another file that exists in
* *any* commit (like `git blame -CCC`). Implies SAME_COMMIT_COPIES.
*
* This is not yet implemented and reserved for future use.
*/
GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES = (1<<3), GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES = (1<<3),
/** Restrict the search of commits to those reachable following only the
* first parents. */ /**
* Restrict the search of commits to those reachable following only
* the first parents.
*/
GIT_BLAME_FIRST_PARENT = (1<<4), GIT_BLAME_FIRST_PARENT = (1<<4),
/** Use mailmap file to map author and committer names and email addresses
* to canonical real names and email addresses. The mailmap will be read /**
* from the working directory, or HEAD in a bare repository. */ * Use mailmap file to map author and committer names and email
* addresses to canonical real names and email addresses. The
* mailmap will be read from the working directory, or HEAD in a
* bare repository.
*/
GIT_BLAME_USE_MAILMAP = (1<<5), GIT_BLAME_USE_MAILMAP = (1<<5),
/** Ignore whitespace differences */ /** Ignore whitespace differences */
GIT_BLAME_IGNORE_WHITESPACE = (1<<6), GIT_BLAME_IGNORE_WHITESPACE = (1<<6),
} git_blame_flag_t; } git_blame_flag_t;
@ -63,25 +88,33 @@ typedef struct git_blame_options {
/** A combination of `git_blame_flag_t` */ /** A combination of `git_blame_flag_t` */
uint32_t flags; uint32_t flags;
/** The lower bound on the number of alphanumeric
* characters that must be detected as moving/copying within a file for it to /**
* associate those lines with the parent commit. The default value is 20. * The lower bound on the number of alphanumeric characters that
* must be detected as moving/copying within a file for it to
* associate those lines with the parent commit. The default value
* is 20.
*
* This value only takes effect if any of the `GIT_BLAME_TRACK_COPIES_*` * This value only takes effect if any of the `GIT_BLAME_TRACK_COPIES_*`
* flags are specified. * flags are specified.
*/ */
uint16_t min_match_characters; uint16_t min_match_characters;
/** The id of the newest commit to consider. The default is HEAD. */ /** The id of the newest commit to consider. The default is HEAD. */
git_oid newest_commit; git_oid newest_commit;
/** /**
* The id of the oldest commit to consider. * The id of the oldest commit to consider.
* The default is the first commit encountered with a NULL parent. * The default is the first commit encountered with a NULL parent.
*/ */
git_oid oldest_commit; git_oid oldest_commit;
/** /**
* The first line in the file to blame. * The first line in the file to blame.
* The default is 1 (line numbers start with 1). * The default is 1 (line numbers start with 1).
*/ */
size_t min_line; size_t min_line;
/** /**
* The last line in the file to blame. * The last line in the file to blame.
* The default is the last line of the file. * The default is the last line of the file.
@ -108,41 +141,59 @@ GIT_EXTERN(int) git_blame_options_init(
/** /**
* Structure that represents a blame hunk. * Structure that represents a blame hunk.
*
* - `lines_in_hunk` is the number of lines in this hunk
* - `final_commit_id` is the OID of the commit where this line was last
* changed.
* - `final_start_line_number` is the 1-based line number where this hunk
* begins, in the final version of the file
* - `final_signature` is the author of `final_commit_id`. If
* `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical
* real name and email address.
* - `orig_commit_id` is the OID of the commit where this hunk was found. This
* will usually be the same as `final_commit_id`, except when
* `GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES` has been specified.
* - `orig_path` is the path to the file where this hunk originated, as of the
* commit specified by `orig_commit_id`.
* - `orig_start_line_number` is the 1-based line number where this hunk begins
* in the file named by `orig_path` in the commit specified by
* `orig_commit_id`.
* - `orig_signature` is the author of `orig_commit_id`. If
* `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical
* real name and email address.
* - `boundary` is 1 iff the hunk has been tracked to a boundary commit (the
* root, or the commit specified in git_blame_options.oldest_commit)
*/ */
typedef struct git_blame_hunk { typedef struct git_blame_hunk {
/**
* The number of lines in this hunk.
*/
size_t lines_in_hunk; size_t lines_in_hunk;
/**
* The OID of the commit where this line was last changed.
*/
git_oid final_commit_id; git_oid final_commit_id;
/**
* The 1-based line number where this hunk begins, in the final version
* of the file.
*/
size_t final_start_line_number; size_t final_start_line_number;
/**
* The author of `final_commit_id`. If `GIT_BLAME_USE_MAILMAP` has been
* specified, it will contain the canonical real name and email address.
*/
git_signature *final_signature; git_signature *final_signature;
/**
* The OID of the commit where this hunk was found.
* This will usually be the same as `final_commit_id`, except when
* `GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES` has been specified.
*/
git_oid orig_commit_id; git_oid orig_commit_id;
/**
* The path to the file where this hunk originated, as of the commit
* specified by `orig_commit_id`.
*/
const char *orig_path; const char *orig_path;
/**
* The 1-based line number where this hunk begins in the file named by
* `orig_path` in the commit specified by `orig_commit_id`.
*/
size_t orig_start_line_number; size_t orig_start_line_number;
/**
* The author of `orig_commit_id`. If `GIT_BLAME_USE_MAILMAP` has been
* specified, it will contain the canonical real name and email address.
*/
git_signature *orig_signature; git_signature *orig_signature;
/**
* The 1 iff the hunk has been tracked to a boundary commit (the root,
* or the commit specified in git_blame_options.oldest_commit)
*/
char boundary; char boundary;
} git_blame_hunk; } git_blame_hunk;

View file

@ -84,7 +84,7 @@ GIT_EXTERN(git_repository *) git_blob_owner(const git_blob *blob);
* time. * time.
* *
* @param blob pointer to the blob * @param blob pointer to the blob
* @return the pointer * @return the pointer, or NULL on error
*/ */
GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob); GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
@ -113,7 +113,13 @@ typedef enum {
* When set, filters will be loaded from a `.gitattributes` file * When set, filters will be loaded from a `.gitattributes` file
* in the HEAD commit. * in the HEAD commit.
*/ */
GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD = (1 << 2), GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD = (1 << 2),
/**
* When set, filters will be loaded from a `.gitattributes` file
* in the specified commit.
*/
GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3),
} git_blob_filter_flag_t; } git_blob_filter_flag_t;
/** /**
@ -128,6 +134,12 @@ typedef struct {
/** Flags to control the filtering process, see `git_blob_filter_flag_t` above */ /** Flags to control the filtering process, see `git_blob_filter_flag_t` above */
uint32_t flags; uint32_t flags;
/**
* The commit to load attributes from, when
* `GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT` is specified.
*/
git_oid *commit_id;
} git_blob_filter_options; } git_blob_filter_options;
#define GIT_BLOB_FILTER_OPTIONS_VERSION 1 #define GIT_BLOB_FILTER_OPTIONS_VERSION 1

View file

@ -304,6 +304,31 @@ GIT_EXTERN(int) git_branch_remote_name(
*/ */
GIT_EXTERN(int) git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname); GIT_EXTERN(int) git_branch_upstream_remote(git_buf *buf, git_repository *repo, const char *refname);
/**
* Retrieve the upstream merge of a local branch
*
* This will return the currently configured "branch.*.merge" for a given
* branch. This branch must be local.
*
* @param buf the buffer into which to write the name
* @param repo the repository in which to look
* @param refname the full name of the branch
* @return 0 or an error code
*/
GIT_EXTERN(int) git_branch_upstream_merge(git_buf *buf, git_repository *repo, const char *refname);
/**
* Determine whether a branch name is valid, meaning that (when prefixed
* with `refs/heads/`) that it is a valid reference name, and that any
* additional branch name restrictions are imposed (eg, it cannot start
* with a `-`).
*
* @param valid output pointer to set with validity of given branch name
* @param name a branch name to test
* @return 0 on success or an error code
*/
GIT_EXTERN(int) git_branch_name_is_valid(int *valid, const char *name);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif

View file

@ -8,6 +8,7 @@
#define INCLUDE_git_cert_h__ #define INCLUDE_git_cert_h__
#include "common.h" #include "common.h"
#include "types.h"
/** /**
* @file git2/cert.h * @file git2/cert.h
@ -80,8 +81,27 @@ typedef enum {
GIT_CERT_SSH_SHA1 = (1 << 1), GIT_CERT_SSH_SHA1 = (1 << 1),
/** SHA-256 is available */ /** SHA-256 is available */
GIT_CERT_SSH_SHA256 = (1 << 2), GIT_CERT_SSH_SHA256 = (1 << 2),
/** Raw hostkey is available */
GIT_CERT_SSH_RAW = (1 << 3),
} git_cert_ssh_t; } git_cert_ssh_t;
typedef enum {
/** The raw key is of an unknown type. */
GIT_CERT_SSH_RAW_TYPE_UNKNOWN = 0,
/** The raw key is an RSA key. */
GIT_CERT_SSH_RAW_TYPE_RSA = 1,
/** The raw key is a DSS key. */
GIT_CERT_SSH_RAW_TYPE_DSS = 2,
/** The raw key is a ECDSA 256 key. */
GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_256 = 3,
/** The raw key is a ECDSA 384 key. */
GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_384 = 4,
/** The raw key is a ECDSA 521 key. */
GIT_CERT_SSH_RAW_TYPE_KEY_ECDSA_521 = 5,
/** The raw key is a ED25519 key. */
GIT_CERT_SSH_RAW_TYPE_KEY_ED25519 = 6
} git_cert_ssh_raw_type_t;
/** /**
* Hostkey information taken from libssh2 * Hostkey information taken from libssh2
*/ */
@ -89,28 +109,45 @@ typedef struct {
git_cert parent; /**< The parent cert */ git_cert parent; /**< The parent cert */
/** /**
* A hostkey type from libssh2, either * A bitmask containing the available fields.
* `GIT_CERT_SSH_MD5` or `GIT_CERT_SSH_SHA1`
*/ */
git_cert_ssh_t type; git_cert_ssh_t type;
/** /**
* Hostkey hash. If type has `GIT_CERT_SSH_MD5` set, this will * Hostkey hash. If `type` has `GIT_CERT_SSH_MD5` set, this will
* have the MD5 hash of the hostkey. * have the MD5 hash of the hostkey.
*/ */
unsigned char hash_md5[16]; unsigned char hash_md5[16];
/** /**
* Hostkey hash. If type has `GIT_CERT_SSH_SHA1` set, this will * Hostkey hash. If `type` has `GIT_CERT_SSH_SHA1` set, this will
* have the SHA-1 hash of the hostkey. * have the SHA-1 hash of the hostkey.
*/ */
unsigned char hash_sha1[20]; unsigned char hash_sha1[20];
/** /**
* Hostkey hash. If type has `GIT_CERT_SSH_SHA256` set, this will * Hostkey hash. If `type` has `GIT_CERT_SSH_SHA256` set, this will
* have the SHA-256 hash of the hostkey. * have the SHA-256 hash of the hostkey.
*/ */
unsigned char hash_sha256[32]; unsigned char hash_sha256[32];
/**
* Raw hostkey type. If `type` has `GIT_CERT_SSH_RAW` set, this will
* have the type of the raw hostkey.
*/
git_cert_ssh_raw_type_t raw_type;
/**
* Pointer to the raw hostkey. If `type` has `GIT_CERT_SSH_RAW` set,
* this will have the raw contents of the hostkey.
*/
const char *hostkey;
/**
* Raw hostkey length. If `type` has `GIT_CERT_SSH_RAW` set, this will
* have the length of the raw contents of the hostkey.
*/
size_t hostkey_len;
} git_cert_hostkey; } git_cert_hostkey;
/** /**

View file

@ -177,6 +177,12 @@ typedef enum {
/** Normally checkout writes the index upon completion; this prevents that. */ /** Normally checkout writes the index upon completion; this prevents that. */
GIT_CHECKOUT_DONT_WRITE_INDEX = (1u << 23), GIT_CHECKOUT_DONT_WRITE_INDEX = (1u << 23),
/**
* Show what would be done by a checkout. Stop after sending
* notifications; don't update the working directory or index.
*/
GIT_CHECKOUT_DRY_RUN = (1u << 24),
/** /**
* THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED * THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
*/ */
@ -194,18 +200,6 @@ typedef enum {
* Checkout will invoke an options notification callback (`notify_cb`) for * Checkout will invoke an options notification callback (`notify_cb`) for
* certain cases - you pick which ones via `notify_flags`: * certain cases - you pick which ones via `notify_flags`:
* *
* - GIT_CHECKOUT_NOTIFY_CONFLICT invokes checkout on conflicting paths.
*
* - GIT_CHECKOUT_NOTIFY_DIRTY notifies about "dirty" files, i.e. those that
* do not need an update but no longer match the baseline. Core git
* displays these files when checkout runs, but won't stop the checkout.
*
* - GIT_CHECKOUT_NOTIFY_UPDATED sends notification for any file changed.
*
* - GIT_CHECKOUT_NOTIFY_UNTRACKED notifies about untracked files.
*
* - GIT_CHECKOUT_NOTIFY_IGNORED notifies about ignored files.
*
* Returning a non-zero value from this callback will cancel the checkout. * Returning a non-zero value from this callback will cancel the checkout.
* The non-zero return value will be propagated back and returned by the * The non-zero return value will be propagated back and returned by the
* git_checkout_... call. * git_checkout_... call.
@ -216,10 +210,32 @@ typedef enum {
*/ */
typedef enum { typedef enum {
GIT_CHECKOUT_NOTIFY_NONE = 0, GIT_CHECKOUT_NOTIFY_NONE = 0,
/**
* Invokes checkout on conflicting paths.
*/
GIT_CHECKOUT_NOTIFY_CONFLICT = (1u << 0), GIT_CHECKOUT_NOTIFY_CONFLICT = (1u << 0),
/**
* Notifies about "dirty" files, i.e. those that do not need an update
* but no longer match the baseline. Core git displays these files when
* checkout runs, but won't stop the checkout.
*/
GIT_CHECKOUT_NOTIFY_DIRTY = (1u << 1), GIT_CHECKOUT_NOTIFY_DIRTY = (1u << 1),
/**
* Sends notification for any file changed.
*/
GIT_CHECKOUT_NOTIFY_UPDATED = (1u << 2), GIT_CHECKOUT_NOTIFY_UPDATED = (1u << 2),
/**
* Notifies about untracked files.
*/
GIT_CHECKOUT_NOTIFY_UNTRACKED = (1u << 3), GIT_CHECKOUT_NOTIFY_UNTRACKED = (1u << 3),
/**
* Notifies about ignored files.
*/
GIT_CHECKOUT_NOTIFY_IGNORED = (1u << 4), GIT_CHECKOUT_NOTIFY_IGNORED = (1u << 4),
GIT_CHECKOUT_NOTIFY_ALL = 0x0FFFFu GIT_CHECKOUT_NOTIFY_ALL = 0x0FFFFu

View file

@ -503,25 +503,41 @@ GIT_EXTERN(int) git_commit_create_with_signature(
GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source); GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source);
/** /**
* Commit signing callback. * Commit creation callback: used when a function is going to create
* commits (for example, in `git_rebase_commit`) to allow callers to
* override the commit creation behavior. For example, users may
* wish to sign commits by providing this information to
* `git_commit_create_buffer`, signing that buffer, then calling
* `git_commit_create_with_signature`. The resultant commit id
* should be set in the `out` object id parameter.
* *
* The callback will be called with the commit content, giving a user an * @param out pointer that this callback will populate with the object
* opportunity to sign the commit content. The signature_field * id of the commit that is created
* buf may be left empty to specify the default field "gpgsig". * @param author the author name and time of the commit
* * @param committer the committer name and time of the commit
* Signatures can take the form of any string, and can be created on an arbitrary * @param message_encoding the encoding of the given message, or NULL
* header field. Signatures are most commonly used for verifying authorship of a * to assume UTF8
* commit using GPG or a similar cryptographically secure signing algorithm. * @param message the commit message
* See https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work for more * @param tree the tree to be committed
* details. * @param parent_count the number of parents for this commit
* * @param parents the commit parents
* When the callback: * @param payload the payload pointer in the rebase options
* - returns GIT_PASSTHROUGH, no signature will be added to the commit. * @return 0 if this callback has created the commit and populated the out
* - returns < 0, commit creation will be aborted. * parameter, GIT_PASSTHROUGH if the callback has not created a
* - returns GIT_OK, the signature parameter is expected to be filled. * commit and wants the calling function to create the commit as
* if no callback had been specified, any other value to stop
* and return a failure
*/ */
typedef int (*git_commit_signing_cb)( typedef int (*git_commit_create_cb)(
git_buf *signature, git_buf *signature_field, const char *commit_content, void *payload); git_oid *out,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
size_t parent_count,
const git_commit *parents[],
void *payload);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL

View file

@ -91,10 +91,10 @@ GIT_BEGIN_DECL
/** /**
* The separator used in path list strings (ie like in the PATH * The separator used in path list strings (ie like in the PATH
* environment variable). A semi-colon ";" is used on Windows, and * environment variable). A semi-colon ";" is used on Windows and
* a colon ":" for all other systems. * AmigaOS, and a colon ":" for all other systems.
*/ */
#ifdef GIT_WIN32 #if defined(GIT_WIN32) || defined(AMIGA)
#define GIT_PATH_LIST_SEPARATOR ';' #define GIT_PATH_LIST_SEPARATOR ';'
#else #else
#define GIT_PATH_LIST_SEPARATOR ':' #define GIT_PATH_LIST_SEPARATOR ':'
@ -207,7 +207,9 @@ typedef enum {
GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS, GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS,
GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE,
GIT_OPT_GET_MWINDOW_FILE_LIMIT, GIT_OPT_GET_MWINDOW_FILE_LIMIT,
GIT_OPT_SET_MWINDOW_FILE_LIMIT GIT_OPT_SET_MWINDOW_FILE_LIMIT,
GIT_OPT_SET_ODB_PACKED_PRIORITY,
GIT_OPT_SET_ODB_LOOSE_PRIORITY
} git_libgit2_opt_t; } git_libgit2_opt_t;
/** /**
@ -421,6 +423,14 @@ typedef enum {
* > authentication, use expect/continue when POSTing data. * > authentication, use expect/continue when POSTing data.
* > This option is not available on Windows. * > This option is not available on Windows.
* *
* opts(GIT_OPT_SET_ODB_PACKED_PRIORITY, int priority)
* > Override the default priority of the packed ODB backend which
* > is added when default backends are assigned to a repository
*
* opts(GIT_OPT_SET_ODB_LOOSE_PRIORITY, int priority)
* > Override the default priority of the loose ODB backend which
* > is added when default backends are assigned to a repository
*
* @param option Option key * @param option Option key
* @param ... value to set the option * @param ... value to set the option
* @return 0 on success, <0 on failure * @return 0 on success, <0 on failure

View file

@ -18,6 +18,7 @@
#include "describe.h" #include "describe.h"
#include "diff.h" #include "diff.h"
#include "errors.h" #include "errors.h"
#include "filter.h"
#include "index.h" #include "index.h"
#include "indexer.h" #include "indexer.h"
#include "merge.h" #include "merge.h"
@ -29,6 +30,7 @@
#include "trace.h" #include "trace.h"
#include "repository.h" #include "repository.h"
#include "revert.h" #include "revert.h"
#include "revparse.h"
#include "stash.h" #include "stash.h"
#include "status.h" #include "status.h"
#include "submodule.h" #include "submodule.h"
@ -80,16 +82,19 @@ typedef git_attr_value_t git_attr_t;
/**@}*/ /**@}*/
/** @name Deprecated Blob Functions /** @name Deprecated Blob Functions and Constants
* *
* These functions are retained for backward compatibility. The newer * These functions and enumeration values are retained for backward
* versions of these functions should be preferred in all new code. * compatibility. The newer versions of these functions and values
* should be preferred in all new code.
* *
* There is no plan to remove these backward compatibility values at * There is no plan to remove these backward compatibility values at
* this time. * this time.
*/ */
/**@{*/ /**@{*/
#define GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD
GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path); GIT_EXTERN(int) git_blob_create_fromworkdir(git_oid *id, git_repository *repo, const char *relative_path);
GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path); GIT_EXTERN(int) git_blob_create_fromdisk(git_oid *id, git_repository *repo, const char *path);
GIT_EXTERN(int) git_blob_create_fromstream( GIT_EXTERN(int) git_blob_create_fromstream(
@ -115,6 +120,66 @@ GIT_EXTERN(int) git_blob_filtered_content(
/**@}*/ /**@}*/
/** @name Deprecated Filter Functions
*
* These functions are retained for backward compatibility. The
* newer versions of these functions should be preferred in all
* new code.
*
* There is no plan to remove these backward compatibility values at
* this time.
*/
/**@{*/
/** Deprecated in favor of `git_filter_list_stream_buffer`.
*
* @deprecated Use git_filter_list_stream_buffer
* @see Use git_filter_list_stream_buffer
*/
GIT_EXTERN(int) git_filter_list_stream_data(
git_filter_list *filters,
git_buf *data,
git_writestream *target);
/** Deprecated in favor of `git_filter_list_apply_to_buffer`.
*
* @deprecated Use git_filter_list_apply_to_buffer
* @see Use git_filter_list_apply_to_buffer
*/
GIT_EXTERN(int) git_filter_list_apply_to_data(
git_buf *out,
git_filter_list *filters,
git_buf *in);
/**@}*/
/** @name Deprecated Tree Functions
*
* These functions are retained for backward compatibility. The
* newer versions of these functions and values should be preferred
* in all new code.
*
* There is no plan to remove these backward compatibility values at
* this time.
*/
/**@{*/
/**
* Write the contents of the tree builder as a tree object.
* This is an alias of `git_treebuilder_write` and is preserved
* for backward compatibility.
*
* This function is deprecated, but there is no plan to remove this
* function at this time.
*
* @deprecated Use git_treebuilder_write
* @see git_treebuilder_write
*/
GIT_EXTERN(int) git_treebuilder_write_with_buffer(
git_oid *oid, git_treebuilder *bld, git_buf *tree);
/**@}*/
/** @name Deprecated Buffer Functions /** @name Deprecated Buffer Functions
* *
* These functions and enumeration values are retained for backward * These functions and enumeration values are retained for backward
@ -126,6 +191,61 @@ GIT_EXTERN(int) git_blob_filtered_content(
*/ */
/**@{*/ /**@{*/
/**
* Static initializer for git_buf from static buffer
*/
#define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) }
/**
* Resize the buffer allocation to make more space.
*
* This will attempt to grow the buffer to accommodate the target size.
*
* If the buffer refers to memory that was not allocated by libgit2 (i.e.
* the `asize` field is zero), then `ptr` will be replaced with a newly
* allocated block of data. Be careful so that memory allocated by the
* caller is not lost. As a special variant, if you pass `target_size` as
* 0 and the memory is not allocated by libgit2, this will allocate a new
* buffer of size `size` and copy the external data into it.
*
* Currently, this will never shrink a buffer, only expand it.
*
* If the allocation fails, this will return an error and the buffer will be
* marked as invalid for future operations, invaliding the contents.
*
* @param buffer The buffer to be resized; may or may not be allocated yet
* @param target_size The desired available size
* @return 0 on success, -1 on allocation failure
*/
GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size);
/**
* Set buffer to a copy of some raw data.
*
* @param buffer The buffer to set
* @param data The data to copy into the buffer
* @param datalen The length of the data to copy into the buffer
* @return 0 on success, -1 on allocation failure
*/
GIT_EXTERN(int) git_buf_set(
git_buf *buffer, const void *data, size_t datalen);
/**
* Check quickly if buffer looks like it contains binary data
*
* @param buf Buffer to check
* @return 1 if buffer looks like non-text data
*/
GIT_EXTERN(int) git_buf_is_binary(const git_buf *buf);
/**
* Check quickly if buffer contains a NUL byte
*
* @param buf Buffer to check
* @return 1 if buffer contains a NUL byte
*/
GIT_EXTERN(int) git_buf_contains_nul(const git_buf *buf);
/** /**
* Free the memory referred to by the git_buf. This is an alias of * Free the memory referred to by the git_buf. This is an alias of
* `git_buf_dispose` and is preserved for backward compatibility. * `git_buf_dispose` and is preserved for backward compatibility.
@ -140,6 +260,27 @@ GIT_EXTERN(void) git_buf_free(git_buf *buffer);
/**@}*/ /**@}*/
/** @name Deprecated Commit Definitions
*/
/**@{*/
/**
* Provide a commit signature during commit creation.
*
* Callers should instead define a `git_commit_create_cb` that
* generates a commit buffer using `git_commit_create_buffer`, sign
* that buffer and call `git_commit_create_with_signature`.
*
* @deprecated use a `git_commit_create_cb` instead
*/
typedef int (*git_commit_signing_cb)(
git_buf *signature,
git_buf *signature_field,
const char *commit_content,
void *payload);
/**@}*/
/** @name Deprecated Config Functions and Constants /** @name Deprecated Config Functions and Constants
*/ */
/**@{*/ /**@{*/
@ -340,10 +481,32 @@ GIT_EXTERN(size_t) git_object__size(git_object_t type);
/**@}*/ /**@}*/
/** @name Deprecated Reference Constants /** @name Deprecated Remote Functions
* *
* These enumeration values are retained for backward compatibility. The * These functions are retained for backward compatibility. The newer
* newer versions of these values should be preferred in all new code. * versions of these functions should be preferred in all new code.
*
* There is no plan to remove these backward compatibility functions at
* this time.
*/
/**@{*/
/**
* Ensure the remote name is well-formed.
*
* @deprecated Use git_remote_name_is_valid
* @param remote_name name to be checked.
* @return 1 if the reference name is acceptable; 0 if it isn't
*/
GIT_EXTERN(int) git_remote_is_valid_name(const char *remote_name);
/**@}*/
/** @name Deprecated Reference Functions and Constants
*
* These functions and enumeration values are retained for backward
* compatibility. The newer versions of these values should be
* preferred in all new code.
* *
* There is no plan to remove these backward compatibility values at * There is no plan to remove these backward compatibility values at
* this time. * this time.
@ -364,6 +527,23 @@ GIT_EXTERN(size_t) git_object__size(git_object_t type);
#define GIT_REF_FORMAT_REFSPEC_PATTERN GIT_REFERENCE_FORMAT_REFSPEC_PATTERN #define GIT_REF_FORMAT_REFSPEC_PATTERN GIT_REFERENCE_FORMAT_REFSPEC_PATTERN
#define GIT_REF_FORMAT_REFSPEC_SHORTHAND GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND #define GIT_REF_FORMAT_REFSPEC_SHORTHAND GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND
/**
* Ensure the reference name is well-formed.
*
* Valid reference names must follow one of two patterns:
*
* 1. Top-level names must contain only capital letters and underscores,
* and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
* 2. Names prefixed with "refs/" can be almost anything. You must avoid
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the
* sequences ".." and "@{" which have special meaning to revparse.
*
* @deprecated Use git_reference_name_is_valid
* @param refname name to be checked.
* @return 1 if the reference name is acceptable; 0 if it isn't
*/
GIT_EXTERN(int) git_reference_is_valid_name(const char *refname);
GIT_EXTERN(int) git_tag_create_frombuffer( GIT_EXTERN(int) git_tag_create_frombuffer(
git_oid *oid, git_oid *oid,
git_repository *repo, git_repository *repo,
@ -372,6 +552,25 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
/**@}*/ /**@}*/
/** @name Deprecated Revspec Constants
*
* These enumeration values are retained for backward compatibility.
* The newer versions of these values should be preferred in all new
* code.
*
* There is no plan to remove these backward compatibility values at
* this time.
*/
/**@{*/
typedef git_revspec_t git_revparse_mode_t;
#define GIT_REVPARSE_SINGLE GIT_REVSPEC_SINGLE
#define GIT_REVPARSE_RANGE GIT_REVSPEC_RANGE
#define GIT_REVPARSE_MERGE_BASE GIT_REVSPEC_MERGE_BASE
/**@}*/
/** @name Deprecated Credential Types /** @name Deprecated Credential Types
* *
* These types are retained for backward compatibility. The newer * These types are retained for backward compatibility. The newer
@ -380,6 +579,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
* There is no plan to remove these backward compatibility values at * There is no plan to remove these backward compatibility values at
* this time. * this time.
*/ */
/**@{*/
typedef git_credential git_cred; typedef git_credential git_cred;
typedef git_credential_userpass_plaintext git_cred_userpass_plaintext; typedef git_credential_userpass_plaintext git_cred_userpass_plaintext;

View file

@ -168,6 +168,10 @@ typedef enum {
* can apply given diff information to binary files. * can apply given diff information to binary files.
*/ */
GIT_DIFF_SHOW_BINARY = (1u << 30), GIT_DIFF_SHOW_BINARY = (1u << 30),
/** Ignore blank lines */
GIT_DIFF_IGNORE_BLANK_LINES = (1u << 31),
} git_diff_option_t; } git_diff_option_t;
/** /**
@ -237,32 +241,43 @@ typedef enum {
* Although this is called a "file", it could represent a file, a symbolic * Although this is called a "file", it could represent a file, a symbolic
* link, a submodule commit id, or even a tree (although that only if you * link, a submodule commit id, or even a tree (although that only if you
* are tracking type changes or ignored/untracked directories). * are tracking type changes or ignored/untracked directories).
* */
* The `id` is the `git_oid` of the item. If the entry represents an typedef struct {
/**
* The `git_oid` of the item. If the entry represents an
* absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta), * absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta),
* then the oid will be zeroes. * then the oid will be zeroes.
* */
* `path` is the NUL-terminated path to the entry relative to the working git_oid id;
/**
* The NUL-terminated path to the entry relative to the working
* directory of the repository. * directory of the repository.
* */
* `size` is the size of the entry in bytes. const char *path;
*
* `flags` is a combination of the `git_diff_flag_t` types /**
* * The size of the entry in bytes.
* `mode` is, roughly, the stat() `st_mode` value for the item. This will */
git_object_size_t size;
/**
* A combination of the `git_diff_flag_t` types
*/
uint32_t flags;
/**
* Roughly, the stat() `st_mode` value for the item. This will
* be restricted to one of the `git_filemode_t` values. * be restricted to one of the `git_filemode_t` values.
* */
* The `id_abbrev` represents the known length of the `id` field, when uint16_t mode;
/**
* Represents the known length of the `id` field, when
* converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this * converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this
* delta was created from reading a patch file, in which case it may be * delta was created from reading a patch file, in which case it may be
* abbreviated to something reasonable, like 7 characters. * abbreviated to something reasonable, like 7 characters.
*/ */
typedef struct {
git_oid id;
const char *path;
git_object_size_t size;
uint32_t flags;
uint16_t mode;
uint16_t id_abbrev; uint16_t id_abbrev;
} git_diff_file; } git_diff_file;

View file

@ -49,8 +49,33 @@ typedef enum {
/** Load attributes from `.gitattributes` in the root of HEAD */ /** Load attributes from `.gitattributes` in the root of HEAD */
GIT_FILTER_ATTRIBUTES_FROM_HEAD = (1u << 2), GIT_FILTER_ATTRIBUTES_FROM_HEAD = (1u << 2),
/**
* Load attributes from `.gitattributes` in a given commit.
* This can only be specified in a `git_filter_options`.
*/
GIT_FILTER_ATTRIBUTES_FROM_COMMIT = (1u << 3),
} git_filter_flag_t; } git_filter_flag_t;
/**
* Filtering options
*/
typedef struct {
unsigned int version;
/** See `git_filter_flag_t` above */
uint32_t flags;
/**
* The commit to load attributes from, when
* `GIT_FILTER_ATTRIBUTES_FROM_COMMIT` is specified.
*/
git_oid *commit_id;
} git_filter_options;
#define GIT_FILTER_OPTIONS_VERSION 1
#define GIT_FILTER_OPTIONS_INIT {GIT_FILTER_OPTIONS_VERSION}
/** /**
* A filter that can transform file data * A filter that can transform file data
* *
@ -103,6 +128,29 @@ GIT_EXTERN(int) git_filter_list_load(
git_filter_mode_t mode, git_filter_mode_t mode,
uint32_t flags); uint32_t flags);
/**
* Load the filter list for a given path.
*
* This will return 0 (success) but set the output git_filter_list to NULL
* if no filters are requested for the given file.
*
* @param filters Output newly created git_filter_list (or NULL)
* @param repo Repository object that contains `path`
* @param blob The blob to which the filter will be applied (if known)
* @param path Relative path of the file to be filtered
* @param mode Filtering direction (WT->ODB or ODB->WT)
* @param opts The `git_filter_options` to use when loading filters
* @return 0 on success (which could still return NULL if no filters are
* needed for the requested file), <0 on error
*/
GIT_EXTERN(int) git_filter_list_load_ext(
git_filter_list **filters,
git_repository *repo,
git_blob *blob,
const char *path,
git_filter_mode_t mode,
git_filter_options *opts);
/** /**
* Query the filter list to see if a given filter (by name) will run. * Query the filter list to see if a given filter (by name) will run.
* The built-in filters "crlf" and "ident" can be queried, otherwise this * The built-in filters "crlf" and "ident" can be queried, otherwise this
@ -122,27 +170,17 @@ GIT_EXTERN(int) git_filter_list_contains(
/** /**
* Apply filter list to a data buffer. * Apply filter list to a data buffer.
* *
* See `git2/buffer.h` for background on `git_buf` objects.
*
* If the `in` buffer holds data allocated by libgit2 (i.e. `in->asize` is
* not zero), then it will be overwritten when applying the filters. If
* not, then it will be left untouched.
*
* If there are no filters to apply (or `filters` is NULL), then the `out`
* buffer will reference the `in` buffer data (with `asize` set to zero)
* instead of allocating data. This keeps allocations to a minimum, but
* it means you have to be careful about freeing the `in` data since `out`
* may be pointing to it!
*
* @param out Buffer to store the result of the filtering * @param out Buffer to store the result of the filtering
* @param filters A loaded git_filter_list (or NULL) * @param filters A loaded git_filter_list (or NULL)
* @param in Buffer containing the data to filter * @param in Buffer containing the data to filter
* @param in_len The length of the input buffer
* @return 0 on success, an error code otherwise * @return 0 on success, an error code otherwise
*/ */
GIT_EXTERN(int) git_filter_list_apply_to_data( GIT_EXTERN(int) git_filter_list_apply_to_buffer(
git_buf *out, git_buf *out,
git_filter_list *filters, git_filter_list *filters,
git_buf *in); const char *in,
size_t in_len);
/** /**
* Apply a filter list to the contents of a file on disk * Apply a filter list to the contents of a file on disk
@ -175,12 +213,14 @@ GIT_EXTERN(int) git_filter_list_apply_to_blob(
* Apply a filter list to an arbitrary buffer as a stream * Apply a filter list to an arbitrary buffer as a stream
* *
* @param filters the list of filters to apply * @param filters the list of filters to apply
* @param data the buffer to filter * @param buffer the buffer to filter
* @param len the size of the buffer
* @param target the stream into which the data will be written * @param target the stream into which the data will be written
*/ */
GIT_EXTERN(int) git_filter_list_stream_data( GIT_EXTERN(int) git_filter_list_stream_buffer(
git_filter_list *filters, git_filter_list *filters,
git_buf *data, const char *buffer,
size_t len,
git_writestream *target); git_writestream *target);
/** /**

View file

@ -43,8 +43,9 @@ GIT_EXTERN(int) git_graph_ahead_behind(size_t *ahead, size_t *behind, git_reposi
* Note that a commit is not considered a descendant of itself, in contrast * Note that a commit is not considered a descendant of itself, in contrast
* to `git merge-base --is-ancestor`. * to `git merge-base --is-ancestor`.
* *
* @param commit a previously loaded commit. * @param repo the repository where the commits exist
* @param ancestor a potential ancestor commit. * @param commit a previously loaded commit
* @param ancestor a potential ancestor commit
* @return 1 if the given commit is a descendant of the potential ancestor, * @return 1 if the given commit is a descendant of the potential ancestor,
* 0 if not, error code otherwise. * 0 if not, error code otherwise.
*/ */
@ -53,6 +54,23 @@ GIT_EXTERN(int) git_graph_descendant_of(
const git_oid *commit, const git_oid *commit,
const git_oid *ancestor); const git_oid *ancestor);
/**
* Determine if a commit is reachable from any of a list of commits by
* following parent edges.
*
* @param repo the repository where the commits exist
* @param commit a previously loaded commit
* @param length the number of commits in the provided `descendant_array`
* @param descendant_array oids of the commits
* @return 1 if the given commit is an ancestor of any of the given potential
* descendants, 0 if not, error code otherwise.
*/
GIT_EXTERN(int) git_graph_reachable_from_any(
git_repository *repo,
const git_oid *commit,
const git_oid descendant_array[],
size_t length);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif

View file

@ -702,7 +702,7 @@ GIT_EXTERN(int) git_index_update_all(
* @param at_pos the address to which the position of the index entry is written (optional) * @param at_pos the address to which the position of the index entry is written (optional)
* @param index an existing index object * @param index an existing index object
* @param path path to search * @param path path to search
* @return 0 with valid value in at_pos; an error code otherwise * @return 0 or an error code
*/ */
GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *path); GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *path);
@ -713,7 +713,7 @@ GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *pat
* @param at_pos the address to which the position of the index entry is written (optional) * @param at_pos the address to which the position of the index entry is written (optional)
* @param index an existing index object * @param index an existing index object
* @param prefix the prefix to search for * @param prefix the prefix to search for
* @return 0 with valid value in at_pos; an error code otherwise * @return 0 or an error code
*/ */
GIT_EXTERN(int) git_index_find_prefix(size_t *at_pos, git_index *index, const char *prefix); GIT_EXTERN(int) git_index_find_prefix(size_t *at_pos, git_index *index, const char *prefix);

View file

@ -390,6 +390,20 @@ GIT_EXTERN(int) git_odb_write_pack(
git_indexer_progress_cb progress_cb, git_indexer_progress_cb progress_cb,
void *progress_payload); void *progress_payload);
/**
* Write a `multi-pack-index` file from all the `.pack` files in the ODB.
*
* If the ODB layer understands pack files, then this will create a file called
* `multi-pack-index` next to the `.pack` and `.idx` files, which will contain
* an index of all objects stored in `.pack` files. This will allow for
* O(log n) lookup for n objects (regardless of how many packfiles there
* exist).
*
* @param db object database where the `multi-pack-index` file will be written.
*/
GIT_EXTERN(int) git_odb_write_multi_pack_index(
git_odb *db);
/** /**
* Determine the object-ID (sha1 hash) of a data buffer * Determine the object-ID (sha1 hash) of a data buffer
* *
@ -539,6 +553,21 @@ GIT_EXTERN(size_t) git_odb_num_backends(git_odb *odb);
*/ */
GIT_EXTERN(int) git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos); GIT_EXTERN(int) git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos);
/**
* Set the git commit-graph for the ODB.
*
* After a successfull call, the ownership of the cgraph parameter will be
* transferred to libgit2, and the caller should not free it.
*
* The commit-graph can also be unset by explicitly passing NULL as the cgraph
* parameter.
*
* @param odb object database
* @param cgraph the git commit-graph
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_odb_set_commit_graph(git_odb *odb, git_commit_graph *cgraph);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif

View file

@ -28,6 +28,14 @@ GIT_BEGIN_DECL
*/ */
typedef struct git_patch git_patch; typedef struct git_patch git_patch;
/**
* Get the repository associated with this patch. May be NULL.
*
* @param patch the patch
* @return a pointer to the repository
*/
GIT_EXTERN(git_repository *) git_patch_owner(const git_patch *patch);
/** /**
* Return a patch for an entry in the diff list. * Return a patch for an entry in the diff list.
* *

View file

@ -74,14 +74,38 @@ typedef struct {
*/ */
git_checkout_options checkout_options; git_checkout_options checkout_options;
/**
* Optional callback that allows users to override commit
* creation in `git_rebase_commit`. If specified, users can
* create their own commit and provide the commit ID, which
* may be useful for signing commits or otherwise customizing
* the commit creation.
*
* If this callback returns `GIT_PASSTHROUGH`, then
* `git_rebase_commit` will continue to create the commit.
*/
git_commit_create_cb commit_create_cb;
#ifdef GIT_DEPRECATE_HARD
void *reserved;
#else
/** /**
* If provided, this will be called with the commit content, allowing * If provided, this will be called with the commit content, allowing
* a signature to be added to the rebase commit. Can be skipped with * a signature to be added to the rebase commit. Can be skipped with
* GIT_PASSTHROUGH. If GIT_PASSTHROUGH is returned, a commit will be made * GIT_PASSTHROUGH. If GIT_PASSTHROUGH is returned, a commit will be made
* without a signature. * without a signature.
*
* This field is only used when performing git_rebase_commit. * This field is only used when performing git_rebase_commit.
*
* This callback is not invoked if a `git_commit_create_cb` is
* specified.
*
* This callback is deprecated; users should provide a
* creation callback as `commit_create_cb` that produces a
* commit buffer, signs it, and commits it.
*/ */
git_commit_signing_cb signing_cb; int (*signing_cb)(git_buf *, git_buf *, const char *, void *);
#endif
/** /**
* This will be passed to each of the callbacks in this struct * This will be passed to each of the callbacks in this struct

View file

@ -97,6 +97,9 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
* of updating does not match the one passed through `current_value` * of updating does not match the one passed through `current_value`
* (i.e. if the ref has changed since the user read it). * (i.e. if the ref has changed since the user read it).
* *
* If `current_value` is all zeros, this function will return GIT_EMODIFIED
* if the ref already exists.
*
* @param out Pointer to the newly created reference * @param out Pointer to the newly created reference
* @param repo Repository where that reference will live * @param repo Repository where that reference will live
* @param name The name of the reference * @param name The name of the reference
@ -743,10 +746,11 @@ GIT_EXTERN(int) git_reference_peel(
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the * the characters '~', '^', ':', '\\', '?', '[', and '*', and the
* sequences ".." and "@{" which have special meaning to revparse. * sequences ".." and "@{" which have special meaning to revparse.
* *
* @param valid output pointer to set with validity of given reference name
* @param refname name to be checked. * @param refname name to be checked.
* @return 1 if the reference name is acceptable; 0 if it isn't * @return 0 on success or an error code
*/ */
GIT_EXTERN(int) git_reference_is_valid_name(const char *refname); GIT_EXTERN(int) git_reference_name_is_valid(int *valid, const char *refname);
/** /**
* Get the reference's short name * Get the reference's short name

View file

@ -212,7 +212,8 @@ GIT_EXTERN(const char *) git_remote_name(const git_remote *remote);
* Get the remote's url * Get the remote's url
* *
* If url.*.insteadOf has been configured for this URL, it will * If url.*.insteadOf has been configured for this URL, it will
* return the modified URL. * return the modified URL. If `git_remote_set_instance_pushurl`
* has been called for this remote, then that URL will be returned.
* *
* @param remote the remote * @param remote the remote
* @return a pointer to the url * @return a pointer to the url
@ -220,10 +221,11 @@ GIT_EXTERN(const char *) git_remote_name(const git_remote *remote);
GIT_EXTERN(const char *) git_remote_url(const git_remote *remote); GIT_EXTERN(const char *) git_remote_url(const git_remote *remote);
/** /**
* Get the remote's url for pushing * Get the remote's url for pushing.
* *
* If url.*.pushInsteadOf has been configured for this URL, it * If url.*.pushInsteadOf has been configured for this URL, it
* will return the modified URL. * will return the modified URL. If `git_remote_set_instance_pushurl`
* has been called for this remote, then that URL will be returned.
* *
* @param remote the remote * @param remote the remote
* @return a pointer to the url or NULL if no special url for pushing is set * @return a pointer to the url or NULL if no special url for pushing is set
@ -253,9 +255,30 @@ GIT_EXTERN(int) git_remote_set_url(git_repository *repo, const char *remote, con
* @param repo the repository in which to perform the change * @param repo the repository in which to perform the change
* @param remote the remote's name * @param remote the remote's name
* @param url the url to set * @param url the url to set
* @return 0, or an error code
*/ */
GIT_EXTERN(int) git_remote_set_pushurl(git_repository *repo, const char *remote, const char* url); GIT_EXTERN(int) git_remote_set_pushurl(git_repository *repo, const char *remote, const char* url);
/**
* Set the url for this particular url instance. The URL in the
* configuration will be ignored, and will not be changed.
*
* @param remote the remote's name
* @param url the url to set
* @return 0 or an error value
*/
GIT_EXTERN(int) git_remote_set_instance_url(git_remote *remote, const char *url);
/**
* Set the push url for this particular url instance. The URL in the
* configuration will be ignored, and will not be changed.
*
* @param remote the remote's name
* @param url the url to set
* @return 0 or an error value
*/
GIT_EXTERN(int) git_remote_set_instance_pushurl(git_remote *remote, const char *url);
/** /**
* Add a fetch refspec to the remote's configuration * Add a fetch refspec to the remote's configuration
* *
@ -476,6 +499,7 @@ typedef int GIT_CALLBACK(git_push_negotiation)(const git_push_update **updates,
*/ */
typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, const char *status, void *data); typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, const char *status, void *data);
#ifndef GIT_DEPRECATE_HARD
/** /**
* Callback to resolve URLs before connecting to remote * Callback to resolve URLs before connecting to remote
* *
@ -487,8 +511,22 @@ typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, cons
* @param direction GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH * @param direction GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH
* @param payload Payload provided by the caller * @param payload Payload provided by the caller
* @return 0 on success, GIT_PASSTHROUGH or an error * @return 0 on success, GIT_PASSTHROUGH or an error
* @deprecated Use `git_remote_set_instance_url`
*/ */
typedef int GIT_CALLBACK(git_url_resolve_cb)(git_buf *url_resolved, const char *url, int direction, void *payload); typedef int GIT_CALLBACK(git_url_resolve_cb)(git_buf *url_resolved, const char *url, int direction, void *payload);
#endif
/**
* Callback invoked immediately before we attempt to connect to the
* given url. Callers may change the URL before the connection by
* calling `git_remote_set_instance_url` in the callback.
*
* @param remote The remote to be connected
* @param direction GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH
* @param payload Payload provided by the caller
* @return 0 on success, or an error
*/
typedef int GIT_CALLBACK(git_remote_ready_cb)(git_remote *remote, int direction, void *payload);
/** /**
* The callback settings structure * The callback settings structure
@ -574,17 +612,29 @@ struct git_remote_callbacks {
*/ */
git_transport_cb transport; git_transport_cb transport;
/**
* Callback when the remote is ready to connect.
*/
git_remote_ready_cb remote_ready;
/** /**
* This will be passed to each of the callbacks in this struct * This will be passed to each of the callbacks in this struct
* as the last parameter. * as the last parameter.
*/ */
void *payload; void *payload;
#ifdef GIT_DEPRECATE_HARD
void *reserved;
#else
/** /**
* Resolve URL before connecting to remote. * Resolve URL before connecting to remote.
* The returned URL will be used to connect to the remote instead. * The returned URL will be used to connect to the remote instead.
*
* This callback is deprecated; users should use
* git_remote_ready_cb and configure the instance URL instead.
*/ */
git_url_resolve_cb resolve_url; git_url_resolve_cb resolve_url;
#endif
}; };
#define GIT_REMOTE_CALLBACKS_VERSION 1 #define GIT_REMOTE_CALLBACKS_VERSION 1
@ -876,8 +926,10 @@ GIT_EXTERN(git_remote_autotag_option_t) git_remote_autotag(const git_remote *rem
* @param repo the repository in which to make the change * @param repo the repository in which to make the change
* @param remote the name of the remote * @param remote the name of the remote
* @param value the new value to take. * @param value the new value to take.
* @return 0, or an error code.
*/ */
GIT_EXTERN(int) git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_autotag_option_t value); GIT_EXTERN(int) git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_autotag_option_t value);
/** /**
* Retrieve the ref-prune setting * Retrieve the ref-prune setting
* *
@ -915,10 +967,11 @@ GIT_EXTERN(int) git_remote_rename(
/** /**
* Ensure the remote name is well-formed. * Ensure the remote name is well-formed.
* *
* @param valid output pointer to set with validity of given remote name
* @param remote_name name to be checked. * @param remote_name name to be checked.
* @return 1 if the reference name is acceptable; 0 if it isn't * @return 0 on success or an error code
*/ */
GIT_EXTERN(int) git_remote_is_valid_name(const char *remote_name); int git_remote_name_is_valid(int *valid, const char *remote_name);
/** /**
* Delete an existing persisted remote. * Delete an existing persisted remote.
@ -943,7 +996,7 @@ GIT_EXTERN(int) git_remote_delete(git_repository *repo, const char *name);
* *
* This function must only be called after connecting. * This function must only be called after connecting.
* *
* @param out the buffern in which to store the reference name * @param out the buffer in which to store the reference name
* @param remote the remote * @param remote the remote
* @return 0, GIT_ENOTFOUND if the remote does not have any references * @return 0, GIT_ENOTFOUND if the remote does not have any references
* or none of them point to HEAD's commit, or an error message. * or none of them point to HEAD's commit, or an error message.

View file

@ -70,12 +70,12 @@ GIT_EXTERN(int) git_revparse_ext(
*/ */
typedef enum { typedef enum {
/** The spec targeted a single object. */ /** The spec targeted a single object. */
GIT_REVPARSE_SINGLE = 1 << 0, GIT_REVSPEC_SINGLE = 1 << 0,
/** The spec targeted a range of commits. */ /** The spec targeted a range of commits. */
GIT_REVPARSE_RANGE = 1 << 1, GIT_REVSPEC_RANGE = 1 << 1,
/** The spec used the '...' operator, which invokes special semantics. */ /** The spec used the '...' operator, which invokes special semantics. */
GIT_REVPARSE_MERGE_BASE = 1 << 2, GIT_REVSPEC_MERGE_BASE = 1 << 2,
} git_revparse_mode_t; } git_revspec_t;
/** /**
* Git Revision Spec: output of a `git_revparse` operation * Git Revision Spec: output of a `git_revparse` operation
@ -85,7 +85,7 @@ typedef struct {
git_object *from; git_object *from;
/** The right element of the revspec; must be freed by the user */ /** The right element of the revspec; must be freed by the user */
git_object *to; git_object *to;
/** The intent of the revspec (i.e. `git_revparse_mode_t` flags) */ /** The intent of the revspec (i.e. `git_revspec_mode_t` flags) */
unsigned int flags; unsigned int flags;
} git_revspec; } git_revspec;

View file

@ -69,89 +69,141 @@ typedef int GIT_CALLBACK(git_status_cb)(
* With `git_status_foreach_ext`, this will control which changes get * With `git_status_foreach_ext`, this will control which changes get
* callbacks. With `git_status_list_new`, these will control which * callbacks. With `git_status_list_new`, these will control which
* changes are included in the list. * changes are included in the list.
*
* - GIT_STATUS_SHOW_INDEX_AND_WORKDIR is the default. This roughly
* matches `git status --porcelain` regarding which files are
* included and in what order.
* - GIT_STATUS_SHOW_INDEX_ONLY only gives status based on HEAD to index
* comparison, not looking at working directory changes.
* - GIT_STATUS_SHOW_WORKDIR_ONLY only gives status based on index to
* working directory comparison, not comparing the index to the HEAD.
*/ */
typedef enum { typedef enum {
/**
* The default. This roughly matches `git status --porcelain` regarding
* which files are included and in what order.
*/
GIT_STATUS_SHOW_INDEX_AND_WORKDIR = 0, GIT_STATUS_SHOW_INDEX_AND_WORKDIR = 0,
/**
* Only gives status based on HEAD to index comparison, not looking at
* working directory changes.
*/
GIT_STATUS_SHOW_INDEX_ONLY = 1, GIT_STATUS_SHOW_INDEX_ONLY = 1,
/**
* Only gives status based on index to working directory comparison,
* not comparing the index to the HEAD.
*/
GIT_STATUS_SHOW_WORKDIR_ONLY = 2, GIT_STATUS_SHOW_WORKDIR_ONLY = 2,
} git_status_show_t; } git_status_show_t;
/** /**
* Flags to control status callbacks * Flags to control status callbacks
* *
* - GIT_STATUS_OPT_INCLUDE_UNTRACKED says that callbacks should be made
* on untracked files. These will only be made if the workdir files are
* included in the status "show" option.
* - GIT_STATUS_OPT_INCLUDE_IGNORED says that ignored files get callbacks.
* Again, these callbacks will only be made if the workdir files are
* included in the status "show" option.
* - GIT_STATUS_OPT_INCLUDE_UNMODIFIED indicates that callback should be
* made even on unmodified files.
* - GIT_STATUS_OPT_EXCLUDE_SUBMODULES indicates that submodules should be
* skipped. This only applies if there are no pending typechanges to
* the submodule (either from or to another type).
* - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS indicates that all files in
* untracked directories should be included. Normally if an entire
* directory is new, then just the top-level directory is included (with
* a trailing slash on the entry name). This flag says to include all
* of the individual files in the directory instead.
* - GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH indicates that the given path
* should be treated as a literal path, and not as a pathspec pattern.
* - GIT_STATUS_OPT_RECURSE_IGNORED_DIRS indicates that the contents of
* ignored directories should be included in the status. This is like
* doing `git ls-files -o -i --exclude-standard` with core git.
* - GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX indicates that rename detection
* should be processed between the head and the index and enables
* the GIT_STATUS_INDEX_RENAMED as a possible status flag.
* - GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR indicates that rename
* detection should be run between the index and the working directory
* and enabled GIT_STATUS_WT_RENAMED as a possible status flag.
* - GIT_STATUS_OPT_SORT_CASE_SENSITIVELY overrides the native case
* sensitivity for the file system and forces the output to be in
* case-sensitive order
* - GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY overrides the native case
* sensitivity for the file system and forces the output to be in
* case-insensitive order
* - GIT_STATUS_OPT_RENAMES_FROM_REWRITES indicates that rename detection
* should include rewritten files
* - GIT_STATUS_OPT_NO_REFRESH bypasses the default status behavior of
* doing a "soft" index reload (i.e. reloading the index data if the
* file on disk has been modified outside libgit2).
* - GIT_STATUS_OPT_UPDATE_INDEX tells libgit2 to refresh the stat cache
* in the index for files that are unchanged but have out of date stat
* information in the index. It will result in less work being done on
* subsequent calls to get status. This is mutually exclusive with the
* NO_REFRESH option.
*
* Calling `git_status_foreach()` is like calling the extended version * Calling `git_status_foreach()` is like calling the extended version
* with: GIT_STATUS_OPT_INCLUDE_IGNORED, GIT_STATUS_OPT_INCLUDE_UNTRACKED, * with: GIT_STATUS_OPT_INCLUDE_IGNORED, GIT_STATUS_OPT_INCLUDE_UNTRACKED,
* and GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS. Those options are bundled * and GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS. Those options are bundled
* together as `GIT_STATUS_OPT_DEFAULTS` if you want them as a baseline. * together as `GIT_STATUS_OPT_DEFAULTS` if you want them as a baseline.
*/ */
typedef enum { typedef enum {
/**
* Says that callbacks should be made on untracked files.
* These will only be made if the workdir files are included in the status
* "show" option.
*/
GIT_STATUS_OPT_INCLUDE_UNTRACKED = (1u << 0), GIT_STATUS_OPT_INCLUDE_UNTRACKED = (1u << 0),
/**
* Says that ignored files get callbacks.
* Again, these callbacks will only be made if the workdir files are
* included in the status "show" option.
*/
GIT_STATUS_OPT_INCLUDE_IGNORED = (1u << 1), GIT_STATUS_OPT_INCLUDE_IGNORED = (1u << 1),
/**
* Indicates that callback should be made even on unmodified files.
*/
GIT_STATUS_OPT_INCLUDE_UNMODIFIED = (1u << 2), GIT_STATUS_OPT_INCLUDE_UNMODIFIED = (1u << 2),
/**
* Indicates that submodules should be skipped.
* This only applies if there are no pending typechanges to the submodule
* (either from or to another type).
*/
GIT_STATUS_OPT_EXCLUDE_SUBMODULES = (1u << 3), GIT_STATUS_OPT_EXCLUDE_SUBMODULES = (1u << 3),
/**
* Indicates that all files in untracked directories should be included.
* Normally if an entire directory is new, then just the top-level
* directory is included (with a trailing slash on the entry name).
* This flag says to include all of the individual files in the directory
* instead.
*/
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1u << 4), GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1u << 4),
/**
* Indicates that the given path should be treated as a literal path,
* and not as a pathspec pattern.
*/
GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH = (1u << 5), GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH = (1u << 5),
/**
* Indicates that the contents of ignored directories should be included
* in the status. This is like doing `git ls-files -o -i --exclude-standard`
* with core git.
*/
GIT_STATUS_OPT_RECURSE_IGNORED_DIRS = (1u << 6), GIT_STATUS_OPT_RECURSE_IGNORED_DIRS = (1u << 6),
/**
* Indicates that rename detection should be processed between the head and
* the index and enables the GIT_STATUS_INDEX_RENAMED as a possible status
* flag.
*/
GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX = (1u << 7), GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX = (1u << 7),
/**
* Indicates that rename detection should be run between the index and the
* working directory and enabled GIT_STATUS_WT_RENAMED as a possible status
* flag.
*/
GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR = (1u << 8), GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR = (1u << 8),
/**
* Overrides the native case sensitivity for the file system and forces
* the output to be in case-sensitive order.
*/
GIT_STATUS_OPT_SORT_CASE_SENSITIVELY = (1u << 9), GIT_STATUS_OPT_SORT_CASE_SENSITIVELY = (1u << 9),
/**
* Overrides the native case sensitivity for the file system and forces
* the output to be in case-insensitive order.
*/
GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY = (1u << 10), GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY = (1u << 10),
/**
* Iindicates that rename detection should include rewritten files.
*/
GIT_STATUS_OPT_RENAMES_FROM_REWRITES = (1u << 11), GIT_STATUS_OPT_RENAMES_FROM_REWRITES = (1u << 11),
/**
* Bypasses the default status behavior of doing a "soft" index reload
* (i.e. reloading the index data if the file on disk has been modified
* outside libgit2).
*/
GIT_STATUS_OPT_NO_REFRESH = (1u << 12), GIT_STATUS_OPT_NO_REFRESH = (1u << 12),
/**
* Tells libgit2 to refresh the stat cache in the index for files that are
* unchanged but have out of date stat einformation in the index.
* It will result in less work being done on subsequent calls to get status.
* This is mutually exclusive with the NO_REFRESH option.
*/
GIT_STATUS_OPT_UPDATE_INDEX = (1u << 13), GIT_STATUS_OPT_UPDATE_INDEX = (1u << 13),
/**
* Normally files that cannot be opened or read are ignored as
* these are often transient files; this option will return
* unreadable files as `GIT_STATUS_WT_UNREADABLE`.
*/
GIT_STATUS_OPT_INCLUDE_UNREADABLE = (1u << 14), GIT_STATUS_OPT_INCLUDE_UNREADABLE = (1u << 14),
/**
* Unreadable files will be detected and given the status
* untracked instead of unreadable.
*/
GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 15), GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 15),
} git_status_opt_t; } git_status_opt_t;
@ -168,7 +220,10 @@ typedef enum {
* *
*/ */
typedef struct { typedef struct {
unsigned int version; /**< The version */ /**
* The struct version; pass `GIT_STATUS_OPTIONS_VERSION`.
*/
unsigned int version;
/** /**
* The `show` value is one of the `git_status_show_t` constants that * The `show` value is one of the `git_status_show_t` constants that
@ -177,21 +232,22 @@ typedef struct {
git_status_show_t show; git_status_show_t show;
/** /**
* The `flags` value is an OR'ed combination of the `git_status_opt_t` * The `flags` value is an OR'ed combination of the
* values above. * `git_status_opt_t` values above.
*/ */
unsigned int flags; unsigned int flags;
/** /**
* The `pathspec` is an array of path patterns to match (using * The `pathspec` is an array of path patterns to match (using
* fnmatch-style matching), or just an array of paths to match exactly if * fnmatch-style matching), or just an array of paths to match
* `GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH` is specified in the flags. * exactly if `GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH` is specified
* in the flags.
*/ */
git_strarray pathspec; git_strarray pathspec;
/** /**
* The `baseline` is the tree to be used for comparison to the working directory * The `baseline` is the tree to be used for comparison to the
* and index; defaults to HEAD. * working directory and index; defaults to HEAD.
*/ */
git_tree *baseline; git_tree *baseline;
} git_status_options; } git_status_options;

View file

@ -223,6 +223,15 @@ GIT_EXTERN(int) git_submodule_lookup(
git_repository *repo, git_repository *repo,
const char *name); const char *name);
/**
* Create an in-memory copy of a submodule. The copy must be explicitly
* free'd or it will leak.
*
* @param out Pointer to store the copy of the submodule.
* @param source Original submodule to copy.
*/
GIT_EXTERN(int) git_submodule_dup(git_submodule **out, git_submodule *source);
/** /**
* Release a submodule * Release a submodule
* *

View file

@ -0,0 +1,174 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_commit_graph_h__
#define INCLUDE_sys_git_commit_graph_h__
#include "git2/common.h"
#include "git2/types.h"
/**
* @file git2/sys/commit_graph.h
* @brief Git commit-graph
* @defgroup git_commit_graph Git commit-graph APIs
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Opens a `git_commit_graph` from a path to an objects directory.
*
* This finds, opens, and validates the `commit-graph` file.
*
* @param cgraph_out the `git_commit_graph` struct to initialize.
* @param objects_dir the path to a git objects directory.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_commit_graph_open(git_commit_graph **cgraph_out, const char *objects_dir);
/**
* Frees commit-graph data. This should only be called when memory allocated
* using `git_commit_graph_open` is not returned to libgit2 because it was not
* associated with the ODB through a successful call to
* `git_odb_set_commit_graph`.
*
* @param cgraph the commit-graph object to free. If NULL, no action is taken.
*/
GIT_EXTERN(void) git_commit_graph_free(git_commit_graph *cgraph);
/**
* Create a new writer for `commit-graph` files.
*
* @param out Location to store the writer pointer.
* @param objects_info_dir The `objects/info` directory.
* The `commit-graph` file will be written in this directory.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_new(
git_commit_graph_writer **out,
const char *objects_info_dir);
/**
* Free the commit-graph writer and its resources.
*
* @param w The writer to free. If NULL no action is taken.
*/
GIT_EXTERN(void) git_commit_graph_writer_free(git_commit_graph_writer *w);
/**
* Add an `.idx` file (associated to a packfile) to the writer.
*
* @param w The writer.
* @param repo The repository that owns the `.idx` file.
* @param idx_path The path of an `.idx` file.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_add_index_file(
git_commit_graph_writer *w,
git_repository *repo,
const char *idx_path);
/**
* Add a revwalk to the writer. This will add all the commits from the revwalk
* to the commit-graph.
*
* @param w The writer.
* @param walk The git_revwalk.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_add_revwalk(
git_commit_graph_writer *w,
git_revwalk *walk);
/**
* The strategy to use when adding a new set of commits to a pre-existing
* commit-graph chain.
*/
typedef enum {
/**
* Do not split commit-graph files. The other split strategy-related option
* fields are ignored.
*/
GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0,
} git_commit_graph_split_strategy_t;
/**
* Options structure for
* `git_commit_graph_writer_commit`/`git_commit_graph_writer_dump`.
*
* Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively, you
* can use `git_commit_graph_writer_options_init`.
*/
typedef struct {
unsigned int version;
/**
* The strategy to use when adding new commits to a pre-existing commit-graph
* chain.
*/
git_commit_graph_split_strategy_t split_strategy;
/**
* The number of commits in level N is less than X times the number of
* commits in level N + 1. Default is 2.
*/
float size_multiple;
/**
* The number of commits in level N + 1 is more than C commits.
* Default is 64000.
*/
size_t max_commits;
} git_commit_graph_writer_options;
#define GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION 1
#define GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT { \
GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION \
}
/**
* Initialize git_commit_graph_writer_options structure
*
* Initializes a `git_commit_graph_writer_options` with default values. Equivalent to
* creating an instance with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`.
*
* @param opts The `git_commit_graph_writer_options` struct to initialize.
* @param version The struct version; pass `GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION`.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_commit_graph_writer_options_init(
git_commit_graph_writer_options *opts,
unsigned int version);
/**
* Write a `commit-graph` file to a file.
*
* @param w The writer
* @param opts Pointer to git_commit_graph_writer_options struct.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_commit(
git_commit_graph_writer *w,
git_commit_graph_writer_options *opts);
/**
* Dump the contents of the `commit-graph` to an in-memory buffer.
*
* @param buffer Buffer where to store the contents of the `commit-graph`.
* @param w The writer.
* @param opts Pointer to git_commit_graph_writer_options struct.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_dump(
git_buf *buffer,
git_commit_graph_writer *w,
git_commit_graph_writer_options *opts);
/** @} */
GIT_END_DECL
#endif

View file

@ -167,17 +167,18 @@ typedef void GIT_CALLBACK(git_filter_shutdown_fn)(git_filter *self);
* *
* The `payload` will be a pointer to a reference payload for the filter. * The `payload` will be a pointer to a reference payload for the filter.
* This will start as NULL, but `check` can assign to this pointer for * This will start as NULL, but `check` can assign to this pointer for
* later use by the `apply` callback. Note that the value should be heap * later use by the `stream` callback. Note that the value should be heap
* allocated (not stack), so that it doesn't go away before the `apply` * allocated (not stack), so that it doesn't go away before the `stream`
* callback can use it. If a filter allocates and assigns a value to the * callback can use it. If a filter allocates and assigns a value to the
* `payload`, it will need a `cleanup` callback to free the payload. * `payload`, it will need a `cleanup` callback to free the payload.
*/ */
typedef int GIT_CALLBACK(git_filter_check_fn)( typedef int GIT_CALLBACK(git_filter_check_fn)(
git_filter *self, git_filter *self,
void **payload, /* points to NULL ptr on entry, may be set */ void **payload, /* NULL on entry, may be set */
const git_filter_source *src, const git_filter_source *src,
const char **attr_values); const char **attr_values);
#ifndef GIT_DEPRECATE_HARD
/** /**
* Callback to actually perform the data filtering * Callback to actually perform the data filtering
* *
@ -189,6 +190,8 @@ typedef int GIT_CALLBACK(git_filter_check_fn)(
* *
* The `payload` value will refer to any payload that was set by the * The `payload` value will refer to any payload that was set by the
* `check` callback. It may be read from or written to as needed. * `check` callback. It may be read from or written to as needed.
*
* @deprecated use git_filter_stream_fn
*/ */
typedef int GIT_CALLBACK(git_filter_apply_fn)( typedef int GIT_CALLBACK(git_filter_apply_fn)(
git_filter *self, git_filter *self,
@ -196,7 +199,17 @@ typedef int GIT_CALLBACK(git_filter_apply_fn)(
git_buf *to, git_buf *to,
const git_buf *from, const git_buf *from,
const git_filter_source *src); const git_filter_source *src);
#endif
/**
* Callback to perform the data filtering.
*
* Specified as `filter.stream`, this is a callback that filters data
* in a streaming manner. This function will provide a
* `git_writestream` that will the original data will be written to;
* with that data, the `git_writestream` will then perform the filter
* translation and stream the filtered data out to the `next` location.
*/
typedef int GIT_CALLBACK(git_filter_stream_fn)( typedef int GIT_CALLBACK(git_filter_stream_fn)(
git_writestream **out, git_writestream **out,
git_filter *self, git_filter *self,
@ -208,9 +221,10 @@ typedef int GIT_CALLBACK(git_filter_stream_fn)(
* Callback to clean up after filtering has been applied * Callback to clean up after filtering has been applied
* *
* Specified as `filter.cleanup`, this is an optional callback invoked * Specified as `filter.cleanup`, this is an optional callback invoked
* after the filter has been applied. If the `check` or `apply` callbacks * after the filter has been applied. If the `check`, `apply`, or
* allocated a `payload` to keep per-source filter state, use this * `stream` callbacks allocated a `payload` to keep per-source filter
* callback to free that payload and release resources as required. * state, use this callback to free that payload and release resources
* as required.
*/ */
typedef void GIT_CALLBACK(git_filter_cleanup_fn)( typedef void GIT_CALLBACK(git_filter_cleanup_fn)(
git_filter *self, git_filter *self,
@ -248,21 +262,28 @@ struct git_filter {
/** /**
* Called to determine whether the filter should be invoked for a * Called to determine whether the filter should be invoked for a
* given file. If this function returns `GIT_PASSTHROUGH` then the * given file. If this function returns `GIT_PASSTHROUGH` then the
* `apply` function will not be invoked and the contents will be passed * `stream` or `apply` functions will not be invoked and the
* through unmodified. * contents will be passed through unmodified.
*/ */
git_filter_check_fn check; git_filter_check_fn check;
#ifdef GIT_DEPRECATE_HARD
void *reserved;
#else
/** /**
* Called to actually apply the filter to file contents. If this * Provided for backward compatibility; this will apply the
* function returns `GIT_PASSTHROUGH` then the contents will be passed * filter to the given contents in a `git_buf`. Callers should
* through unmodified. * provide a `stream` function instead.
*/ */
git_filter_apply_fn apply; git_filter_apply_fn apply;
#endif
/** /**
* Called to apply the filter in a streaming manner. If this is not * Called to apply the filter, this function will provide a
* specified then the system will call `apply` with the whole buffer. * `git_writestream` that will the original data will be
* written to; with that data, the `git_writestream` will then
* perform the filter translation and stream the filtered data
* out to the `next` location.
*/ */
git_filter_stream_fn stream; git_filter_stream_fn stream;
@ -289,9 +310,9 @@ GIT_EXTERN(int) git_filter_init(git_filter *filter, unsigned int version);
* As mentioned elsewhere, the initialize callback will not be invoked * As mentioned elsewhere, the initialize callback will not be invoked
* immediately. It is deferred until the filter is used in some way. * immediately. It is deferred until the filter is used in some way.
* *
* A filter's attribute checks and `check` and `apply` callbacks will be * A filter's attribute checks and `check` and `stream` (or `apply`)
* issued in order of `priority` on smudge (to workdir), and in reverse * callbacks will be issued in order of `priority` on smudge (to
* order of `priority` on clean (to odb). * workdir), and in reverse order of `priority` on clean (to odb).
* *
* Two filters are preregistered with libgit2: * Two filters are preregistered with libgit2:
* - GIT_FILTER_CRLF with priority 0 * - GIT_FILTER_CRLF with priority 0

View file

@ -0,0 +1,74 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_midx_h__
#define INCLUDE_sys_git_midx_h__
#include "git2/common.h"
#include "git2/types.h"
/**
* @file git2/midx.h
* @brief Git multi-pack-index routines
* @defgroup git_midx Git multi-pack-index routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Create a new writer for `multi-pack-index` files.
*
* @param out location to store the writer pointer.
* @param pack_dir the directory where the `.pack` and `.idx` files are. The
* `multi-pack-index` file will be written in this directory, too.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_midx_writer_new(
git_midx_writer **out,
const char *pack_dir);
/**
* Free the multi-pack-index writer and its resources.
*
* @param w the writer to free. If NULL no action is taken.
*/
GIT_EXTERN(void) git_midx_writer_free(git_midx_writer *w);
/**
* Add an `.idx` file to the writer.
*
* @param w the writer
* @param idx_path the path of an `.idx` file.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_midx_writer_add(
git_midx_writer *w,
const char *idx_path);
/**
* Write a `multi-pack-index` file to a file.
*
* @param w the writer
* @return 0 or an error code
*/
GIT_EXTERN(int) git_midx_writer_commit(
git_midx_writer *w);
/**
* Dump the contents of the `multi-pack-index` to an in-memory buffer.
*
* @param midx Buffer where to store the contents of the `multi-pack-index`.
* @param w the writer
* @return 0 or an error code
*/
GIT_EXTERN(int) git_midx_writer_dump(
git_buf *midx,
git_midx_writer *w);
/** @} */
GIT_END_DECL
#endif

View file

@ -84,6 +84,13 @@ struct git_odb_backend {
git_odb_writepack **, git_odb_backend *, git_odb *odb, git_odb_writepack **, git_odb_backend *, git_odb *odb,
git_indexer_progress_cb progress_cb, void *progress_payload); git_indexer_progress_cb progress_cb, void *progress_payload);
/**
* If the backend supports pack files, this will create a
* `multi-pack-index` file which will contain an index of all objects
* across all the `.pack` files.
*/
int GIT_CALLBACK(writemidx)(git_odb_backend *);
/** /**
* "Freshens" an already existing object, updating its last-used * "Freshens" an already existing object, updating its last-used
* time. This occurs when `git_odb_write` was called, but the * time. This occurs when `git_odb_write` was called, but the

View file

@ -9,6 +9,7 @@
#define INCLUDE_sys_git_transport_h #define INCLUDE_sys_git_transport_h
#include "git2/net.h" #include "git2/net.h"
#include "git2/transport.h"
#include "git2/types.h" #include "git2/types.h"
#include "git2/strarray.h" #include "git2/strarray.h"
#include "git2/proxy.h" #include "git2/proxy.h"

View file

@ -365,6 +365,18 @@ GIT_EXTERN(int) git_tag_peel(
*/ */
GIT_EXTERN(int) git_tag_dup(git_tag **out, git_tag *source); GIT_EXTERN(int) git_tag_dup(git_tag **out, git_tag *source);
/**
* Determine whether a tag name is valid, meaning that (when prefixed
* with `refs/tags/`) that it is a valid reference name, and that any
* additional tag name restrictions are imposed (eg, it cannot start
* with a `-`).
*
* @param valid output pointer to set with validity of given tag name
* @param name a tag name to test
* @return 0 on success or an error code
*/
GIT_EXTERN(int) git_tag_name_is_valid(int *valid, const char *name);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif

View file

@ -379,20 +379,6 @@ GIT_EXTERN(int) git_treebuilder_filter(
GIT_EXTERN(int) git_treebuilder_write( GIT_EXTERN(int) git_treebuilder_write(
git_oid *id, git_treebuilder *bld); git_oid *id, git_treebuilder *bld);
/**
* Write the contents of the tree builder as a tree object
* using a shared git_buf.
*
* @see git_treebuilder_write
*
* @param oid Pointer to store the OID of the newly written tree
* @param bld Tree builder to write
* @param tree Shared buffer for writing the tree. Will be grown as necessary.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_treebuilder_write_with_buffer(
git_oid *oid, git_treebuilder *bld, git_buf *tree);
/** Callback for the tree traversal method */ /** Callback for the tree traversal method */
typedef int GIT_CALLBACK(git_treewalk_cb)( typedef int GIT_CALLBACK(git_treewalk_cb)(
const char *root, const git_tree_entry *entry, void *payload); const char *root, const git_tree_entry *entry, void *payload);

View file

@ -96,12 +96,21 @@ typedef struct git_odb_stream git_odb_stream;
/** A stream to write a packfile to the ODB */ /** A stream to write a packfile to the ODB */
typedef struct git_odb_writepack git_odb_writepack; typedef struct git_odb_writepack git_odb_writepack;
/** a writer for multi-pack-index files. */
typedef struct git_midx_writer git_midx_writer;
/** An open refs database handle. */ /** An open refs database handle. */
typedef struct git_refdb git_refdb; typedef struct git_refdb git_refdb;
/** A custom backend for refs */ /** A custom backend for refs */
typedef struct git_refdb_backend git_refdb_backend; typedef struct git_refdb_backend git_refdb_backend;
/** A git commit-graph */
typedef struct git_commit_graph git_commit_graph;
/** a writer for commit-graph files. */
typedef struct git_commit_graph_writer git_commit_graph_writer;
/** /**
* Representation of an existing git repository, * Representation of an existing git repository,
* including all its object contents * including all its object contents

View file

@ -7,12 +7,12 @@
#ifndef INCLUDE_git_version_h__ #ifndef INCLUDE_git_version_h__
#define INCLUDE_git_version_h__ #define INCLUDE_git_version_h__
#define LIBGIT2_VERSION "1.1.1" #define LIBGIT2_VERSION "1.2.0"
#define LIBGIT2_VER_MAJOR 1 #define LIBGIT2_VER_MAJOR 1
#define LIBGIT2_VER_MINOR 1 #define LIBGIT2_VER_MINOR 2
#define LIBGIT2_VER_REVISION 1 #define LIBGIT2_VER_REVISION 0
#define LIBGIT2_VER_PATCH 0 #define LIBGIT2_VER_PATCH 0
#define LIBGIT2_SOVERSION "1.1" #define LIBGIT2_SOVERSION "1.2"
#endif #endif

View file

@ -198,6 +198,7 @@ typedef enum {
typedef struct git_worktree_prune_options { typedef struct git_worktree_prune_options {
unsigned int version; unsigned int version;
/** A combination of `git_worktree_prune_t` */
uint32_t flags; uint32_t flags;
} git_worktree_prune_options; } git_worktree_prune_options;

Binary file not shown.

BIN
libgit2/libgit2-1.2.0.so Executable file

Binary file not shown.