Blame include/git2/describe.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_describe_h__
Packit ae9e2a
#define INCLUDE_git_describe_h__
Packit ae9e2a
Packit ae9e2a
#include "common.h"
Packit ae9e2a
#include "types.h"
Packit ae9e2a
#include "buffer.h"
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * @file git2/describe.h
Packit ae9e2a
 * @brief Git describing routines
Packit ae9e2a
 * @defgroup git_describe Git describing routines
Packit ae9e2a
 * @ingroup Git
Packit ae9e2a
 * @{
Packit ae9e2a
 */
Packit ae9e2a
GIT_BEGIN_DECL
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Reference lookup strategy
Packit ae9e2a
 *
Packit ae9e2a
 * These behave like the --tags and --all optios to git-describe,
Packit ae9e2a
 * namely they say to look for any reference in either refs/tags/ or
Packit ae9e2a
 * refs/ respectively.
Packit ae9e2a
 */
Packit ae9e2a
typedef enum {
Packit ae9e2a
	GIT_DESCRIBE_DEFAULT,
Packit ae9e2a
	GIT_DESCRIBE_TAGS,
Packit ae9e2a
	GIT_DESCRIBE_ALL,
Packit ae9e2a
} git_describe_strategy_t;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Describe options structure
Packit ae9e2a
 *
Packit ae9e2a
 * Initialize with `GIT_DESCRIBE_OPTIONS_INIT` macro to correctly set
Packit ae9e2a
 * the `version` field.  E.g.
Packit ae9e2a
 *
Packit ae9e2a
 *		git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
Packit ae9e2a
 */
Packit ae9e2a
typedef struct git_describe_options {
Packit ae9e2a
	unsigned int version;
Packit ae9e2a
Packit ae9e2a
	unsigned int max_candidates_tags; /**< default: 10 */
Packit ae9e2a
	unsigned int describe_strategy; /**< default: GIT_DESCRIBE_DEFAULT */
Packit ae9e2a
	const char *pattern;
Packit ae9e2a
	/**
Packit ae9e2a
	 * When calculating the distance from the matching tag or
Packit ae9e2a
	 * reference, only walk down the first-parent ancestry.
Packit ae9e2a
	 */
Packit ae9e2a
	int only_follow_first_parent;
Packit ae9e2a
	/**
Packit ae9e2a
	 * If no matching tag or reference is found, the describe
Packit ae9e2a
	 * operation would normally fail. If this option is set, it
Packit ae9e2a
	 * will instead fall back to showing the full id of the
Packit ae9e2a
	 * commit.
Packit ae9e2a
	 */
Packit ae9e2a
	int show_commit_oid_as_fallback;
Packit ae9e2a
} git_describe_options;
Packit ae9e2a
Packit ae9e2a
#define GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS 10
Packit ae9e2a
#define GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE 7
Packit ae9e2a
Packit ae9e2a
#define GIT_DESCRIBE_OPTIONS_VERSION 1
Packit ae9e2a
#define GIT_DESCRIBE_OPTIONS_INIT { \
Packit ae9e2a
	GIT_DESCRIBE_OPTIONS_VERSION, \
Packit ae9e2a
	GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS, \
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
GIT_EXTERN(int) git_describe_init_options(git_describe_options *opts, unsigned int version);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Options for formatting the describe string
Packit ae9e2a
 */
Packit ae9e2a
typedef struct {
Packit ae9e2a
	unsigned int version;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * Size of the abbreviated commit id to use. This value is the
Packit ae9e2a
	 * lower bound for the length of the abbreviated string. The
Packit ae9e2a
	 * default is 7.
Packit ae9e2a
	 */
Packit ae9e2a
	unsigned int abbreviated_size;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * Set to use the long format even when a shorter name could be used.
Packit ae9e2a
	 */
Packit ae9e2a
	int always_use_long_format;
Packit ae9e2a
Packit ae9e2a
	/**
Packit ae9e2a
	 * If the workdir is dirty and this is set, this string will
Packit ae9e2a
	 * be appended to the description string.
Packit ae9e2a
	 */
Packit ae9e2a
	const char *dirty_suffix;
Packit ae9e2a
} git_describe_format_options;
Packit ae9e2a
Packit ae9e2a
#define GIT_DESCRIBE_FORMAT_OPTIONS_VERSION 1
Packit ae9e2a
#define GIT_DESCRIBE_FORMAT_OPTIONS_INIT { \
Packit ae9e2a
		GIT_DESCRIBE_FORMAT_OPTIONS_VERSION,   \
Packit ae9e2a
		GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE, \
Packit ae9e2a
 }
Packit ae9e2a
Packit ae9e2a
GIT_EXTERN(int) git_describe_init_format_options(git_describe_format_options *opts, unsigned int version);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * A struct that stores the result of a describe operation.
Packit ae9e2a
 */
Packit ae9e2a
typedef struct git_describe_result git_describe_result;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Describe a commit
Packit ae9e2a
 *
Packit ae9e2a
 * Perform the describe operation on the given committish object.
Packit ae9e2a
 *
Packit ae9e2a
 * @param result pointer to store the result. You must free this once
Packit ae9e2a
 * you're done with it.
Packit ae9e2a
 * @param committish a committish to describe
Packit ae9e2a
 * @param opts the lookup options
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_describe_commit(
Packit ae9e2a
	git_describe_result **result,
Packit ae9e2a
	git_object *committish,
Packit ae9e2a
	git_describe_options *opts);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Describe a commit
Packit ae9e2a
 *
Packit ae9e2a
 * Perform the describe operation on the current commit and the
Packit ae9e2a
 * worktree. After peforming describe on HEAD, a status is run and the
Packit ae9e2a
 * description is considered to be dirty if there are.
Packit ae9e2a
 *
Packit ae9e2a
 * @param out pointer to store the result. You must free this once
Packit ae9e2a
 * you're done with it.
Packit ae9e2a
 * @param repo the repository in which to perform the describe
Packit ae9e2a
 * @param opts the lookup options
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_describe_workdir(
Packit ae9e2a
	git_describe_result **out,
Packit ae9e2a
	git_repository *repo,
Packit ae9e2a
	git_describe_options *opts);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Print the describe result to a buffer
Packit ae9e2a
 *
Packit ae9e2a
 * @param out The buffer to store the result
Packit ae9e2a
 * @param result the result from `git_describe_commit()` or
Packit ae9e2a
 * `git_describe_workdir()`.
Packit ae9e2a
 * @param opts the formatting options
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(int) git_describe_format(
Packit ae9e2a
	git_buf *out,
Packit ae9e2a
	const git_describe_result *result,
Packit ae9e2a
	const git_describe_format_options *opts);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Free the describe result.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) git_describe_result_free(git_describe_result *result);
Packit ae9e2a
Packit ae9e2a
/** @} */
Packit ae9e2a
GIT_END_DECL
Packit ae9e2a
Packit ae9e2a
#endif