package git2_bindings
import "core:c"
foreign import git2 "system:git2"
@(default_calling_convention = "c", link_prefix = "git_")
foreign git2 {
/*
Init the global state
This function must be called before any other libgit2 function in order to set up global state and threading.
This function may be called multiple times - it will return the number of times the initialization has been called (including this one) that have not subsequently been shutdown.
*/
libgit2_init :: proc() -> c.int ---
/*
Shutdown the global state
Clean up the global state and threading context after calling it as many times as libgit2_init() was called - it will return the number of remainining initializations that have not been shutdown (after this one).
*/
libgit2_shutdown :: proc() -> c.int ---
/*
Return the last Error object that was generated for the current thread.
This function will never return nil.
Callers should not rely on this to determine whether an error has occurred. For error checking, callers should examine the return codes of libgit2 functions.
This call can only reliably report error messages when an error has occurred. (It may contain stale information if it is called after a different function that succeeds.)
The memory for this object is managed by libgit2. It should not be freed.
*/
error_last :: proc() -> ^Error ---
/*
Open a bare repository on the serverside.
This is a fast open for bare repositories that will come in handy if you're e.g. hosting git repositories and need to access them efficiently
Note that the libgit2 library must be initialized using libgit2_init before any APIs can be called, including this one.
*/
repository_open_bare :: proc(out: ^Repository, bare_path: cstring) -> Result ---
/*
Free a previously allocated repository
Note that after a repository is free'd, all the objects it has spawned will still exist until they are manually closed by the user with object_free, but accessing any of the attributes of an object without a backing repository will result in undefined behavior
*/
repository_free :: proc(repo: Repository) ---
/*
Make the repository HEAD point to the specified reference.
If the provided reference points to a Tree or a Blob, the HEAD is unaltered and -1 is returned.
If the provided reference points to a branch, the HEAD will point to that branch, staying attached, or become attached if it isn't yet. If the branch doesn't exist yet, no error will be return. The HEAD will then be attached to an unborn branch.
Otherwise, the HEAD will be detached and will directly point to the Commit.
*/
repository_head :: proc(out: ^Reference, repo: Repository) -> Result ---
// Free the given reference.
reference_free :: proc(ref: Reference) ---
/*
Recursively peel reference until object of the specified type is found.
The retrieved peeled object is owned by the repository and should be closed with the object_free method.
If you pass GIT_OBJECT_ANY as the target type, then the object will be peeled until a non-tag object is met.
*/
reference_peel :: proc(out: ^Object, ref: Reference, type: Object_Type) -> Result ---
/*
Lookup a reference by name in a repository.
The returned reference must be freed by the user.
The name will be checked for validity. See reference_symbolic_create() for rules about valid names.
*/
reference_lookup :: proc(out: ^Reference, repo: Repository, name: cstring) -> Result ---
/*
Close an open object
This method instructs the library to close an existing object; note that objects are owned and cached by the repository so the object may or may not be freed after this library call, depending on how aggressive is the caching mechanism used by the repository.
IMPORTANT: It is necessary to call this method when you stop using an object. Failure to do so will cause a memory leak.
*/
object_free :: proc(object: Object) ---
/*
Find a single object, as specified by a revision string.
See man gitrevisions, or http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for information on the syntax accepted.
The returned object should be released with object_free when no longer needed.
*/
revparse_single :: proc(object: ^Object, repo: Repository, spec: cstring) -> Result ---
/*
Close an open commit
This is a wrapper around object_free()
IMPORTANT: It is necessary to call this method when you stop using a commit. Failure to do so will cause a memory leak.
*/
commit_free :: proc(commit: Commit) ---
// Get the id of a commit.
commit_id :: proc(commit: Commit) -> ^Oid ---
/*
Get the short "summary" of the git commit message.
The returned message is the summary of the commit, comprising the first paragraph of the message with whitespace trimmed and squashed.
*/
commit_summary :: proc(commit: Commit) -> cstring ---
// Get the commit time (i.e. committer time) of a commit.
commit_time :: proc(commit: Commit) -> Time ---
// Get the commit timezone offset (i.e. committer's preferred timezone) of a commit.
commit_time_offset :: proc(commit: Commit) -> c.int ---
// Get the author of a commit.
commit_author :: proc(commit: Commit) -> ^Signature ---
// Get the tree pointed to by a commit.
commit_tree :: proc(out: ^Tree, commit: Commit) -> Result ---
/*
Close an open tree
You can no longer use the Tree pointer after this call.
IMPORTANT: You MUST call this method when you stop using a tree to release memory. Failure to do so will cause a memory leak.
*/
tree_free :: proc(tree: Tree) ---
// Lookup a tree object from the repository.
tree_lookup :: proc(out: ^Tree, repo: Repository, id: ^Oid) -> Result ---
// Get the number of entries listed in a tree
tree_entrycount :: proc(tree: Tree) -> c.size_t ---
/*
Free a user-owned tree entry
IMPORTANT: This function is only needed for tree entries owned by the user, such as the ones returned by tree_entry_dup() or tree_entry_bypath().
*/
tree_entry_free :: proc(entry: Tree_Entry) ---
/*
Lookup a tree entry by its position in the tree
This returns a Tree_Entry that is owned by the Tree. You don't have to free it, but you must not use it after the Tree is released.
*/
tree_entry_byindex :: proc(tree: Tree, idx: c.size_t) -> Tree_Entry ---
/*
Retrieve a tree entry contained in a tree or in any of its subtrees, given its relative path.
Unlike the other lookup functions, the returned tree entry is owned by the user and must be freed explicitly with tree_entry_free().
*/
tree_entry_bypath :: proc(out: ^Tree_Entry, root: Tree, path: cstring) -> Result ---
// Get the filename of a tree entry
tree_entry_name :: proc(entry: Tree_Entry) -> cstring ---
// Get the type of the object pointed by the entry
tree_entry_type :: proc(entry: Tree_Entry) -> Object_Type ---
// Get the id of the object pointed by the entry
tree_entry_id :: proc(entry: Tree_Entry) -> ^Oid ---
/*
Close an open blob
This is a wrapper around git_object_free()
IMPORTANT: It is necessary to call this method when you stop using a blob. Failure to do so will cause a memory leak.
*/
blob_free :: proc(blob: Blob) ---
// Lookup a blob object from a repository.
blob_lookup :: proc(out: ^Blob, repo: Repository, id: ^Oid) -> Result ---
/*
Get a read-only buffer with the raw content of a blob.
A pointer to the raw content of a blob is returned; this pointer is owned internally by the object and shall not be free'd. The pointer may be invalidated at a later time.
*/
blob_rawcontent :: proc(blob: Blob) -> rawptr ---
// Get the size in bytes of the contents of a blob
blob_rawsize :: proc(blob: Blob) -> c.size_t ---
}