2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #ifndef INCLUDE_git_describe_h__
8 #define INCLUDE_git_describe_h__
15 * @file git2/describe.h
16 * @brief Git describing routines
17 * @defgroup git_describe Git describing routines
24 * Reference lookup strategy
26 * These behave like the --tags and --all options to git-describe,
27 * namely they say to look for any reference in either refs/tags/ or
34 } git_describe_strategy_t
;
37 * Describe options structure
39 * Initialize with `GIT_DESCRIBE_OPTIONS_INIT`. Alternatively, you can
40 * use `git_describe_options_init`.
43 typedef struct git_describe_options
{
46 unsigned int max_candidates_tags
; /**< default: 10 */
47 unsigned int describe_strategy
; /**< default: GIT_DESCRIBE_DEFAULT */
50 * When calculating the distance from the matching tag or
51 * reference, only walk down the first-parent ancestry.
53 int only_follow_first_parent
;
55 * If no matching tag or reference is found, the describe
56 * operation would normally fail. If this option is set, it
57 * will instead fall back to showing the full id of the
60 int show_commit_oid_as_fallback
;
61 } git_describe_options
;
63 #define GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS 10
64 #define GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE 7
66 #define GIT_DESCRIBE_OPTIONS_VERSION 1
67 #define GIT_DESCRIBE_OPTIONS_INIT { \
68 GIT_DESCRIBE_OPTIONS_VERSION, \
69 GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS, \
73 * Initialize git_describe_options structure
75 * Initializes a `git_describe_options` with default values. Equivalent to creating
76 * an instance with GIT_DESCRIBE_OPTIONS_INIT.
78 * @param opts The `git_describe_options` struct to initialize.
79 * @param version The struct version; pass `GIT_DESCRIBE_OPTIONS_VERSION`.
80 * @return Zero on success; -1 on failure.
82 GIT_EXTERN(int) git_describe_options_init(git_describe_options
*opts
, unsigned int version
);
85 * Describe format options structure
87 * Initialize with `GIT_DESCRIBE_FORMAT_OPTIONS_INIT`. Alternatively, you can
88 * use `git_describe_format_options_init`.
95 * Size of the abbreviated commit id to use. This value is the
96 * lower bound for the length of the abbreviated string. The
99 unsigned int abbreviated_size
;
102 * Set to use the long format even when a shorter name could be used.
104 int always_use_long_format
;
107 * If the workdir is dirty and this is set, this string will
108 * be appended to the description string.
110 const char *dirty_suffix
;
111 } git_describe_format_options
;
113 #define GIT_DESCRIBE_FORMAT_OPTIONS_VERSION 1
114 #define GIT_DESCRIBE_FORMAT_OPTIONS_INIT { \
115 GIT_DESCRIBE_FORMAT_OPTIONS_VERSION, \
116 GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE, \
120 * Initialize git_describe_format_options structure
122 * Initializes a `git_describe_format_options` with default values. Equivalent to creating
123 * an instance with GIT_DESCRIBE_FORMAT_OPTIONS_INIT.
125 * @param opts The `git_describe_format_options` struct to initialize.
126 * @param version The struct version; pass `GIT_DESCRIBE_FORMAT_OPTIONS_VERSION`.
127 * @return Zero on success; -1 on failure.
129 GIT_EXTERN(int) git_describe_format_options_init(git_describe_format_options
*opts
, unsigned int version
);
132 * A struct that stores the result of a describe operation.
134 typedef struct git_describe_result git_describe_result
;
139 * Perform the describe operation on the given committish object.
141 * @param result pointer to store the result. You must free this once
142 * you're done with it.
143 * @param committish a committish to describe
144 * @param opts the lookup options (or NULL for defaults)
146 GIT_EXTERN(int) git_describe_commit(
147 git_describe_result
**result
,
148 git_object
*committish
,
149 git_describe_options
*opts
);
154 * Perform the describe operation on the current commit and the
155 * worktree. After peforming describe on HEAD, a status is run and the
156 * description is considered to be dirty if there are.
158 * @param out pointer to store the result. You must free this once
159 * you're done with it.
160 * @param repo the repository in which to perform the describe
161 * @param opts the lookup options (or NULL for defaults)
163 GIT_EXTERN(int) git_describe_workdir(
164 git_describe_result
**out
,
165 git_repository
*repo
,
166 git_describe_options
*opts
);
169 * Print the describe result to a buffer
171 * @param out The buffer to store the result
172 * @param result the result from `git_describe_commit()` or
173 * `git_describe_workdir()`.
174 * @param opts the formatting options (or NULL for defaults)
176 GIT_EXTERN(int) git_describe_format(
178 const git_describe_result
*result
,
179 const git_describe_format_options
*opts
);
182 * Free the describe result.
184 GIT_EXTERN(void) git_describe_result_free(git_describe_result
*result
);