diff options
Diffstat (limited to 'include/git2')
| -rw-r--r-- | include/git2/branch.h | 59 | ||||
| -rw-r--r-- | include/git2/diff.h | 1 | ||||
| -rw-r--r-- | include/git2/object.h | 17 | ||||
| -rw-r--r-- | include/git2/odb_backend.h | 1 | ||||
| -rw-r--r-- | include/git2/oid.h | 26 | ||||
| -rw-r--r-- | include/git2/reflog.h | 44 | ||||
| -rw-r--r-- | include/git2/refs.h | 21 | ||||
| -rw-r--r-- | include/git2/remote.h | 65 | ||||
| -rw-r--r-- | include/git2/repository.h | 13 | ||||
| -rw-r--r-- | include/git2/status.h | 3 | ||||
| -rw-r--r-- | include/git2/types.h | 1 |
11 files changed, 213 insertions, 38 deletions
diff --git a/include/git2/branch.h b/include/git2/branch.h index 8884df15a..2f46720af 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -26,9 +26,9 @@ GIT_BEGIN_DECL * this target commit. If `force` is true and a reference * already exists with the given name, it'll be replaced. * - * @param oid_out Pointer where to store the OID of the target commit. + * The returned reference must be freed by the user. * - * @param repo Repository where to store the branch. + * @param branch_out Pointer where to store the underlying reference. * * @param branch_name Name for the branch; this name is * validated for consistency. It should also not conflict with @@ -46,7 +46,7 @@ GIT_BEGIN_DECL * pointing to the provided target commit. */ GIT_EXTERN(int) git_branch_create( - git_oid *oid_out, + git_reference **branch_out, git_repository *repo, const char *branch_name, const git_object *target, @@ -97,27 +97,62 @@ GIT_EXTERN(int) git_branch_foreach( ); /** - * Move/rename an existing branch reference. + * Move/rename an existing local branch reference. * - * @param repo Repository where lives the branch. - * - * @param old_branch_name Current name of the branch to be moved; - * this name is validated for consistency. + * @param branch Current underlying reference of the branch. * * @param new_branch_name Target name of the branch once the move * is performed; this name is validated for consistency. * * @param force Overwrite existing branch. * - * @return 0 on success, GIT_ENOTFOUND if the branch - * doesn't exist or an error code. + * @return 0 on success, or an error code. */ GIT_EXTERN(int) git_branch_move( - git_repository *repo, - const char *old_branch_name, + git_reference *branch, const char *new_branch_name, int force); +/** + * Lookup a branch by its name in a repository. + * + * The generated reference must be freed by the user. + * + * @param branch_out pointer to the looked-up branch reference + * + * @param repo the repository to look up the branch + * + * @param branch_name Name of the branch to be looked-up; + * this name is validated for consistency. + * + * @param branch_type Type of the considered branch. This should + * be valued with either GIT_BRANCH_LOCAL or GIT_BRANCH_REMOTE. + * + * @return 0 on success; GIT_ENOTFOUND when no matching branch + * exists, otherwise an error code. + */ +GIT_EXTERN(int) git_branch_lookup( + git_reference **branch_out, + git_repository *repo, + const char *branch_name, + git_branch_t branch_type); + +/** + * Return the reference supporting the remote tracking branch, + * given a local branch reference. + * + * @param tracking_out Pointer where to store the retrieved + * reference. + * + * @param branch Current underlying reference of the branch. + * + * @return 0 on success; GIT_ENOTFOUND when no remote tracking + * reference exists, otherwise an error code. + */ +GIT_EXTERN(int) git_branch_tracking( + git_reference **tracking_out, + git_reference *branch); + /** @} */ GIT_END_DECL #endif diff --git a/include/git2/diff.h b/include/git2/diff.h index edec9957b..85727d969 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -46,6 +46,7 @@ enum { GIT_DIFF_INCLUDE_UNTRACKED = (1 << 8), GIT_DIFF_INCLUDE_UNMODIFIED = (1 << 9), GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10), + GIT_DIFF_DISABLE_PATHSPEC_MATCH = (1 << 11), }; /** diff --git a/include/git2/object.h b/include/git2/object.h index 414325121..d9e653fd4 100644 --- a/include/git2/object.h +++ b/include/git2/object.h @@ -167,6 +167,23 @@ GIT_EXTERN(int) git_object_typeisloose(git_otype type); */ GIT_EXTERN(size_t) git_object__size(git_otype type); +/** + * Recursively peel an object until an object of the specified + * type is met + * + * The retrieved `peeled` object is owned by the repository + * and should be closed with the `git_object_free` method. + * + * @param peeled Pointer to the peeled git_object + * @param object The object to be processed + * @param target_type The type of the requested object + * @return 0 or an error code + */ +GIT_EXTERN(int) git_object_peel( + git_object **peeled, + git_object *object, + git_otype target_type); + /** @} */ GIT_END_DECL diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h index 3f67202d1..b93ef204f 100644 --- a/include/git2/odb_backend.h +++ b/include/git2/odb_backend.h @@ -100,6 +100,7 @@ struct git_odb_stream { GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir); GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir, int compression_level, int do_fsync); +GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **backend_out, const char *index_file); GIT_END_DECL diff --git a/include/git2/oid.h b/include/git2/oid.h index a05b40a37..d6b2d1e7f 100644 --- a/include/git2/oid.h +++ b/include/git2/oid.h @@ -136,7 +136,31 @@ GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src); * @param b second oid structure. * @return <0, 0, >0 if a < b, a == b, a > b. */ -GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b); +GIT_INLINE(int) git_oid_cmp(const git_oid *a, const git_oid *b) +{ + const unsigned char *sha1 = a->id; + const unsigned char *sha2 = b->id; + int i; + + for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) { + if (*sha1 != *sha2) + return *sha1 - *sha2; + } + + return 0; +} + +/** + * Compare two oid structures for equality + * + * @param a first oid structure. + * @param b second oid structure. + * @return true if equal, false otherwise + */ +GIT_INLINE(int) git_oid_equal(const git_oid *a, const git_oid *b) +{ + return !git_oid_cmp(a, b); +} /** * Compare the first 'len' hexadecimal characters (packets of 4 bits) diff --git a/include/git2/reflog.h b/include/git2/reflog.h index 8acba349b..a73d1f7fd 100644 --- a/include/git2/reflog.h +++ b/include/git2/reflog.h @@ -23,6 +23,10 @@ GIT_BEGIN_DECL /** * Read the reflog for the given reference * + * If there is no reflog file for the given + * reference yet, an empty reflog object will + * be returned. + * * The reflog must be freed manually by using * git_reflog_free(). * @@ -33,22 +37,26 @@ GIT_BEGIN_DECL GIT_EXTERN(int) git_reflog_read(git_reflog **reflog, git_reference *ref); /** - * Write a new reflog for the given reference - * - * If there is no reflog file for the given - * reference yet, it will be created. + * Write an existing in-memory reflog object back to disk + * using an atomic file lock. * - * `oid_old` may be NULL in case it's a new reference. + * @param reflog an existing reflog object + * @return 0 or an error code + */ +GIT_EXTERN(int) git_reflog_write(git_reflog *reflog); + +/** + * Add a new entry to the reflog. * * `msg` is optional and can be NULL. * - * @param ref the changed reference - * @param oid_old the OID the reference was pointing to + * @param reflog an existing reflog object + * @param new_oid the OID the reference is now pointing to * @param committer the signature of the committer * @param msg the reflog message * @return 0 or an error code */ -GIT_EXTERN(int) git_reflog_write(git_reference *ref, const git_oid *oid_old, const git_signature *committer, const char *msg); +GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_signature *committer, const char *msg); /** * Rename the reflog for the given reference @@ -87,6 +95,26 @@ GIT_EXTERN(unsigned int) git_reflog_entrycount(git_reflog *reflog); GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(git_reflog *reflog, unsigned int idx); /** + * Remove an entry from the reflog by its index + * + * To ensure there's no gap in the log history, set the `rewrite_previosu_entry` to 1. + * When deleting entry `n`, member old_oid of entry `n-1` (if any) will be updated with + * the value of memeber new_oid of entry `n+1`. + * + * @param reflog a previously loaded reflog. + * + * @param idx the position of the entry to remove. + * + * @param rewrite_previous_entry 1 to rewrite the history; 0 otherwise. + * + * @return 0 on success or an error code. + */ +GIT_EXTERN(int) git_reflog_drop( + git_reflog *reflog, + unsigned int idx, + int rewrite_previous_entry); + +/** * Get the old oid * * @param entry a reflog entry diff --git a/include/git2/refs.h b/include/git2/refs.h index b119e90b1..8dd8e3116 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -363,26 +363,15 @@ GIT_EXTERN(int) git_reference_foreach_glob( */ GIT_EXTERN(int) git_reference_has_log(git_reference *ref); - /** - * Return the reference supporting the remote tracking branch, - * given a reference branch. - * - * The input reference has to be located in the `refs/heads` - * namespace. - * - * @param tracking_ref Pointer where to store the retrieved - * reference. + * Check if a reference is a local branch. * - * @param branch_ref A git local branch reference. + * @param ref A git reference * - * @return 0 on success; GIT_ENOTFOUND when no remote tracking - * reference exists, otherwise an error code. + * @return 1 when the reference lives in the refs/heads + * namespace; 0 otherwise. */ -GIT_EXTERN(int) git_reference_remote_tracking_from_branch( - git_reference **tracking_ref, - git_reference *branch_ref -); +GIT_EXTERN(int) git_reference_is_branch(git_reference *ref); /** @} */ GIT_END_DECL diff --git a/include/git2/remote.h b/include/git2/remote.h index 5c01949d2..7e563f96f 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -80,6 +80,36 @@ GIT_EXTERN(const char *) git_remote_name(git_remote *remote); GIT_EXTERN(const char *) git_remote_url(git_remote *remote); /** + * Get the remote's url for pushing + * + * @param remote the remote + * @return a pointer to the url or NULL if no special url for pushing is set + */ +GIT_EXTERN(const char *) git_remote_pushurl(git_remote *remote); + +/** + * Set the remote's url + * + * Existing connections will not be updated. + * + * @param remote the remote + * @param url the url to set + * @return 0 or an error value + */ +GIT_EXTERN(int) git_remote_set_url(git_remote *remote, const char* url); + +/** + * Set the remote's url for pushing + * + * Existing connections will not be updated. + * + * @param remote the remote + * @param url the url to set or NULL to clear the pushurl + * @return 0 or an error value + */ +GIT_EXTERN(int) git_remote_set_pushurl(git_remote *remote, const char* url); + +/** * Set the remote's fetch refspec * * @param remote the remote @@ -190,7 +220,7 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote); * @param remote the remote to update * @param cb callback to run on each ref update. 'a' is the old value, 'b' is then new value */ -GIT_EXTERN(int) git_remote_update_tips(git_remote *remote, int (*cb)(const char *refname, const git_oid *a, const git_oid *b)); +GIT_EXTERN(int) git_remote_update_tips(git_remote *remote); /** * Return whether a string is a valid remote URL @@ -238,6 +268,39 @@ GIT_EXTERN(int) git_remote_add(git_remote **out, git_repository *repo, const cha GIT_EXTERN(void) git_remote_check_cert(git_remote *remote, int check); +/** + * Argument to the completion callback which tells it which operation + * finished. + */ +typedef enum git_remote_completion_type { + GIT_REMOTE_COMPLETION_DOWNLOAD, + GIT_REMOTE_COMPLETION_INDEXING, + GIT_REMOTE_COMPLETION_ERROR, +} git_remote_completion_type; + +/** + * The callback settings structure + * + * Set the calbacks to be called by the remote. + */ +struct git_remote_callbacks { + int (*progress)(const char *str, void *data); + int (*completion)(git_remote_completion_type type, void *data); + int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data); + void *data; +}; + +/** + * Set the callbacks for a remote + * + * Note that the remote keeps its own copy of the data and you need to + * call this function again if you want to change the callbacks. + * + * @param remote the remote to configure + * @param callbacks a pointer to the user's callback settings + */ +GIT_EXTERN(void) git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks); + /** @} */ GIT_END_DECL #endif diff --git a/include/git2/repository.h b/include/git2/repository.h index ff81b75ec..ef2f5413d 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -36,6 +36,19 @@ GIT_BEGIN_DECL GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path); /** + * Create a "fake" repository to wrap an object database + * + * Create a repository object to wrap an object database to be used + * with the API when all you have is an object database. This doesn't + * have any paths associated with it, so use with care. + * + * @param repository pointer to the repo + * @param odb the object database to wrap + * @return 0 or an error code + */ +GIT_EXTERN(int) git_repository_wrap_odb(git_repository **repository, git_odb *odb); + +/** * Look for a git repository and copy its path in the given buffer. * The lookup start from base_path and walk across parent directories * if nothing has been found. The lookup ends when the first repository diff --git a/include/git2/status.h b/include/git2/status.h index 69b6e47e0..9e7b5de4a 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -96,6 +96,8 @@ typedef enum { * the top-level directory will be included (with a trailing * slash on the entry name). Given this flag, the directory * itself will not be included, but all the files in it will. + * - GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH indicates that the given + * path will be treated as a literal path, and not as a pathspec. */ enum { @@ -104,6 +106,7 @@ enum { GIT_STATUS_OPT_INCLUDE_UNMODIFIED = (1 << 2), GIT_STATUS_OPT_EXCLUDE_SUBMODULES = (1 << 3), GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS = (1 << 4), + GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH = (1 << 5), }; /** diff --git a/include/git2/types.h b/include/git2/types.h index 691903005..acd5a73bc 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -179,6 +179,7 @@ typedef struct git_refspec git_refspec; typedef struct git_remote git_remote; typedef struct git_remote_head git_remote_head; +typedef struct git_remote_callbacks git_remote_callbacks; /** @} */ GIT_END_DECL |
