Blame include/git2/tag.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_git_tag_h__
Packit ae9e2a
#define INCLUDE_git_tag_h__
Packit ae9e2a
Packit ae9e2a
#include "common.h"
Packit ae9e2a
#include "types.h"
Packit ae9e2a
#include "oid.h"
Packit ae9e2a
#include "object.h"
Packit ae9e2a
#include "strarray.h"
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * @file git2/tag.h
Packit ae9e2a
 * @brief Git tag parsing routines
Packit ae9e2a
 * @defgroup git_tag Git tag management
Packit ae9e2a
 * @ingroup Git
Packit ae9e2a
 * @{
Packit ae9e2a
 */
Packit ae9e2a
GIT_BEGIN_DECL
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Lookup a tag object from the repository.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer to the looked up tag
Packit ae9e2a
 * @param repo the repo to use when locating the tag.
Packit ae9e2a
 * @param id identity of the tag to locate.
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_lookup(
Packit ae9e2a
	git_tag **out, git_repository *repo, const git_oid *id);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Lookup a tag object from the repository,
Packit ae9e2a
 * given a prefix of its identifier (short id).
Packit ae9e2a
 *
Packit ae9e2a
 * @see git_object_lookup_prefix
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer to the looked up tag
Packit ae9e2a
 * @param repo the repo to use when locating the tag.
Packit ae9e2a
 * @param id identity of the tag to locate.
Packit ae9e2a
 * @param len the length of the short identifier
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_lookup_prefix(
Packit ae9e2a
	git_tag **out, git_repository *repo, const git_oid *id, size_t len);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Close an open tag
Packit ae9e2a
 *
Packit ae9e2a
 * You can no longer use the git_tag pointer after this call.
Packit ae9e2a
 *
Packit ae9e2a
 * IMPORTANT: You MUST call this method when you are through with a tag to
Packit ae9e2a
 * release memory. Failure to do so will cause a memory leak.
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag the tag to close
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) git_tag_free(git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the id of a tag.
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag a previously loaded tag.
Packit ae9e2a
 * @return object identity for the tag.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_oid *) git_tag_id(const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the repository that contains the tag.
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag A previously loaded tag.
Packit ae9e2a
 * @return Repository that contains this tag.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(git_repository *) git_tag_owner(const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the tagged object of a tag
Packit ae9e2a
 *
Packit ae9e2a
 * This method performs a repository lookup for the
Packit ae9e2a
 * given object and returns it
Packit ae9e2a
 *
Packit ae9e2a
 * @param target_out pointer where to store the target
Packit ae9e2a
 * @param tag a previously loaded tag.
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_target(git_object **target_out, const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the OID of the tagged object of a tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag a previously loaded tag.
Packit ae9e2a
 * @return pointer to the OID
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_oid *) git_tag_target_id(const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the type of a tag's tagged object
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag a previously loaded tag.
Packit ae9e2a
 * @return type of the tagged object
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(git_otype) git_tag_target_type(const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the name of a tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag a previously loaded tag.
Packit ae9e2a
 * @return name of the tag
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const char *) git_tag_name(const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the tagger (author) of a tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag a previously loaded tag.
Packit ae9e2a
 * @return reference to the tag's author or NULL when unspecified
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_signature *) git_tag_tagger(const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Get the message of a tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag a previously loaded tag.
Packit ae9e2a
 * @return message of the tag or NULL when unspecified
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const char *) git_tag_message(const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create a new tag in the repository from an object
Packit ae9e2a
 *
Packit ae9e2a
 * A new reference will also be created pointing to
Packit ae9e2a
 * this tag object. If `force` is true and a reference
Packit ae9e2a
 * already exists with the given name, it'll be replaced.
Packit ae9e2a
 *
Packit ae9e2a
 * The message will not be cleaned up. This can be achieved
Packit ae9e2a
 * through `git_message_prettify()`.
Packit ae9e2a
 *
Packit ae9e2a
 * The tag name will be checked for validity. You must avoid
Packit ae9e2a
 * the characters '~', '^', ':', '\\', '?', '[', and '*', and the
Packit ae9e2a
 * sequences ".." and "@{" which have special meaning to revparse.
Packit ae9e2a
 *
Packit ae9e2a
 * @param oid Pointer where to store the OID of the
Packit ae9e2a
 * newly created tag. If the tag already exists, this parameter
Packit ae9e2a
 * will be the oid of the existing tag, and the function will
Packit ae9e2a
 * return a GIT_EEXISTS error code.
Packit ae9e2a
 *
Packit ae9e2a
 * @param repo Repository where to store the tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag_name Name for the tag; this name is validated
Packit ae9e2a
 * for consistency. It should also not conflict with an
Packit ae9e2a
 * already existing tag name
Packit ae9e2a
 *
Packit ae9e2a
 * @param target Object to which this tag points. This object
Packit ae9e2a
 * must belong to the given `repo`.
Packit ae9e2a
 *
Packit ae9e2a
 * @param tagger Signature of the tagger for this tag, and
Packit ae9e2a
 * of the tagging time
Packit ae9e2a
 *
Packit ae9e2a
 * @param message Full message for this tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param force Overwrite existing references
Packit ae9e2a
 *
Packit ae9e2a
 * @return 0 on success, GIT_EINVALIDSPEC or an error code
Packit ae9e2a
 *	A tag object is written to the ODB, and a proper reference
Packit ae9e2a
 *	is written in the /refs/tags folder, pointing to it
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_create(
Packit ae9e2a
	git_oid *oid,
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	const char *tag_name,
Packit ae9e2a
	const git_object *target,
Packit ae9e2a
	const git_signature *tagger,
Packit ae9e2a
	const char *message,
Packit ae9e2a
	int force);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create a new tag in the object database pointing to a git_object
Packit ae9e2a
 *
Packit ae9e2a
 * The message will not be cleaned up. This can be achieved
Packit ae9e2a
 * through `git_message_prettify()`.
Packit ae9e2a
 *
Packit ae9e2a
 * @param oid Pointer where to store the OID of the
Packit ae9e2a
 * newly created tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param repo Repository where to store the tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag_name Name for the tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param target Object to which this tag points. This object
Packit ae9e2a
 * must belong to the given `repo`.
Packit ae9e2a
 *
Packit ae9e2a
 * @param tagger Signature of the tagger for this tag, and
Packit ae9e2a
 * of the tagging time
Packit ae9e2a
 *
Packit ae9e2a
 * @param message Full message for this tag
Packit ae9e2a
 *
Packit ae9e2a
 * @return 0 on success or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_annotation_create(
Packit ae9e2a
	git_oid *oid,
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	const char *tag_name,
Packit ae9e2a
	const git_object *target,
Packit ae9e2a
	const git_signature *tagger,
Packit ae9e2a
	const char *message);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create a new tag in the repository from a buffer
Packit ae9e2a
 *
Packit ae9e2a
 * @param oid Pointer where to store the OID of the newly created tag
Packit ae9e2a
 * @param repo Repository where to store the tag
Packit ae9e2a
 * @param buffer Raw tag data
Packit ae9e2a
 * @param force Overwrite existing tags
Packit ae9e2a
 * @return 0 on success; error code otherwise
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_create_frombuffer(
Packit ae9e2a
	git_oid *oid,
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	const char *buffer,
Packit ae9e2a
	int force);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create a new lightweight tag pointing at a target object
Packit ae9e2a
 *
Packit ae9e2a
 * A new direct reference will be created pointing to
Packit ae9e2a
 * this target object. If `force` is true and a reference
Packit ae9e2a
 * already exists with the given name, it'll be replaced.
Packit ae9e2a
 *
Packit ae9e2a
 * The tag name will be checked for validity.
Packit ae9e2a
 * See `git_tag_create()` for rules about valid names.
Packit ae9e2a
 *
Packit ae9e2a
 * @param oid Pointer where to store the OID of the provided
Packit ae9e2a
 * target object. If the tag already exists, this parameter
Packit ae9e2a
 * will be filled with the oid of the existing pointed object
Packit ae9e2a
 * and the function will return a GIT_EEXISTS error code.
Packit ae9e2a
 *
Packit ae9e2a
 * @param repo Repository where to store the lightweight tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag_name Name for the tag; this name is validated
Packit ae9e2a
 * for consistency. It should also not conflict with an
Packit ae9e2a
 * already existing tag name
Packit ae9e2a
 *
Packit ae9e2a
 * @param target Object to which this tag points. This object
Packit ae9e2a
 * must belong to the given `repo`.
Packit ae9e2a
 *
Packit ae9e2a
 * @param force Overwrite existing references
Packit ae9e2a
 *
Packit ae9e2a
 * @return 0 on success, GIT_EINVALIDSPEC or an error code
Packit ae9e2a
 *	A proper reference is written in the /refs/tags folder,
Packit ae9e2a
 * pointing to the provided target object
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_create_lightweight(
Packit ae9e2a
	git_oid *oid,
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	const char *tag_name,
Packit ae9e2a
	const git_object *target,
Packit ae9e2a
	int force);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Delete an existing tag reference.
Packit ae9e2a
 *
Packit ae9e2a
 * The tag name will be checked for validity.
Packit ae9e2a
 * See `git_tag_create()` for rules about valid names.
Packit ae9e2a
 *
Packit ae9e2a
 * @param repo Repository where lives the tag
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag_name Name of the tag to be deleted;
Packit ae9e2a
 * this name is validated for consistency.
Packit ae9e2a
 *
Packit ae9e2a
 * @return 0 on success, GIT_EINVALIDSPEC or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_delete(
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	const char *tag_name);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Fill a list with all the tags in the Repository
Packit ae9e2a
 *
Packit ae9e2a
 * The string array will be filled with the names of the
Packit ae9e2a
 * matching tags; these values are owned by the user and
Packit ae9e2a
 * should be free'd manually when no longer needed, using
Packit ae9e2a
 * `git_strarray_free`.
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag_names Pointer to a git_strarray structure where
Packit ae9e2a
 *		the tag names will be stored
Packit ae9e2a
 * @param repo Repository where to find the tags
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_list(
Packit ae9e2a
	git_strarray *tag_names,
Packit ae9e2a
	git_repository *repo);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Fill a list with all the tags in the Repository
Packit ae9e2a
 * which name match a defined pattern
Packit ae9e2a
 *
Packit ae9e2a
 * If an empty pattern is provided, all the tags
Packit ae9e2a
 * will be returned.
Packit ae9e2a
 *
Packit ae9e2a
 * The string array will be filled with the names of the
Packit ae9e2a
 * matching tags; these values are owned by the user and
Packit ae9e2a
 * should be free'd manually when no longer needed, using
Packit ae9e2a
 * `git_strarray_free`.
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag_names Pointer to a git_strarray structure where
Packit ae9e2a
 *		the tag names will be stored
Packit ae9e2a
 * @param pattern Standard fnmatch pattern
Packit ae9e2a
 * @param repo Repository where to find the tags
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_list_match(
Packit ae9e2a
	git_strarray *tag_names,
Packit ae9e2a
	const char *pattern,
Packit ae9e2a
	git_repository *repo);
Packit ae9e2a
Packit ae9e2a
Packit ae9e2a
typedef int (*git_tag_foreach_cb)(const char *name, git_oid *oid, void *payload);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Call callback `cb' for each tag in the repository
Packit ae9e2a
 *
Packit ae9e2a
 * @param repo Repository
Packit ae9e2a
 * @param callback Callback function
Packit ae9e2a
 * @param payload Pointer to callback data (optional)
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_foreach(
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	git_tag_foreach_cb callback,
Packit ae9e2a
	void *payload);
Packit ae9e2a
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Recursively peel a tag until a non tag git_object is found
Packit ae9e2a
 *
Packit ae9e2a
 * The retrieved `tag_target` object is owned by the repository
Packit ae9e2a
 * and should be closed with the `git_object_free` method.
Packit ae9e2a
 *
Packit ae9e2a
 * @param tag_target_out Pointer to the peeled git_object
Packit ae9e2a
 * @param tag The tag to be processed
Packit ae9e2a
 * @return 0 or an error code
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_peel(
Packit ae9e2a
	git_object **tag_target_out,
Packit ae9e2a
	const git_tag *tag);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Create an in-memory copy of a tag. The copy must be explicitly
Packit ae9e2a
 * free'd or it will leak.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out Pointer to store the copy of the tag
Packit ae9e2a
 * @param source Original tag to copy
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_tag_dup(git_tag **out, git_tag *source);
Packit ae9e2a
Packit ae9e2a
/** @} */
Packit ae9e2a
GIT_END_DECL
Packit ae9e2a
#endif