1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
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.
6  */
7 module libgit2_d.describe;
8 
9 
10 private static import libgit2_d.buffer;
11 private static import libgit2_d.types;
12 
13 /**
14  * @file git2/describe.h
15  * @brief Git describing routines
16  * @defgroup git_describe Git describing routines
17  * @ingroup Git
18  * @{
19  */
20 extern (C):
21 nothrow @nogc:
22 public:
23 
24 /**
25  * Reference lookup strategy
26  *
27  * These behave like the --tags and --all options to git-describe,
28  * namely they say to look for any reference in either refs/tags/ or
29  * refs/ respectively.
30  */
31 enum git_describe_strategy_t
32 {
33 	GIT_DESCRIBE_DEFAULT,
34 	GIT_DESCRIBE_TAGS,
35 	GIT_DESCRIBE_ALL,
36 }
37 
38 /**
39  * Describe options structure
40  *
41  * Initialize with `GIT_DESCRIBE_OPTIONS_INIT`. Alternatively, you can
42  * use `git_describe_options_init`.
43  */
44 struct git_describe_options
45 {
46 	uint version_;
47 
48 	/**
49 	 * default: 10
50 	 */
51 	uint max_candidates_tags;
52 
53 	/**
54 	 * default: git_describe_strategy_t.GIT_DESCRIBE_DEFAULT
55 	 */
56 	uint describe_strategy;
57 
58 	const (char)* pattern;
59 
60 	/**
61 	 * When calculating the distance from the matching tag or
62 	 * reference, only walk down the first-parent ancestry.
63 	 */
64 	int only_follow_first_parent;
65 
66 	/**
67 	 * If no matching tag or reference is found, the describe
68 	 * operation would normally fail. If this option is set, it
69 	 * will instead fall back to showing the full id of the
70 	 * commit.
71 	 */
72 	int show_commit_oid_as_fallback;
73 }
74 
75 enum GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS = 10;
76 enum GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE = 7;
77 
78 enum GIT_DESCRIBE_OPTIONS_VERSION = 1;
79 
80 pragma(inline, true)
81 pure nothrow @safe @nogc
82 .git_describe_options GIT_DESCRIBE_OPTIONS_INIT()
83 
84 	do
85 	{
86 		.git_describe_options OUTPUT =
87 		{
88 			version_: .GIT_DESCRIBE_OPTIONS_VERSION,
89 			max_candidates_tags: .GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS,
90 		};
91 
92 		return OUTPUT;
93 	}
94 
95 /**
96  * Initialize git_describe_options structure
97  *
98  * Initializes a `git_describe_options` with default values. Equivalent to creating
99  * an instance with GIT_DESCRIBE_OPTIONS_INIT.
100  *
101  * @param opts The `git_describe_options` struct to initialize.
102  * @param version The struct version; pass `GIT_DESCRIBE_OPTIONS_VERSION`.
103  * @return Zero on success; -1 on failure.
104  */
105 //GIT_EXTERN
106 int git_describe_options_init(.git_describe_options* opts, uint version_);
107 
108 /**
109  * Describe format options structure
110  *
111  * Initialize with `GIT_DESCRIBE_FORMAT_OPTIONS_INIT`. Alternatively, you can
112  * use `git_describe_format_options_init`.
113  */
114 struct git_describe_format_options
115 {
116 	uint version_;
117 
118 	/**
119 	 * Size of the abbreviated commit id to use. This value is the
120 	 * lower bound for the length of the abbreviated string. The
121 	 * default is 7.
122 	 */
123 	uint abbreviated_size;
124 
125 	/**
126 	 * Set to use the long format even when a shorter name could be used.
127 	 */
128 	int always_use_long_format;
129 
130 	/**
131 	 * If the workdir is dirty and this is set, this string will
132 	 * be appended to the description string.
133 	 */
134 	const (char)* dirty_suffix;
135 }
136 
137 enum GIT_DESCRIBE_FORMAT_OPTIONS_VERSION = 1;
138 
139 pragma(inline, true)
140 pure nothrow @safe @nogc
141 .git_describe_format_options GIT_DESCRIBE_FORMAT_OPTIONS_INIT()
142 
143 	do
144 	{
145 		.git_describe_format_options OUTPUT =
146 		{
147 			version_: .GIT_DESCRIBE_FORMAT_OPTIONS_VERSION,
148 			abbreviated_size: .GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE,
149 		};
150 
151 		return OUTPUT;
152 	}
153 
154 /**
155  * Initialize git_describe_format_options structure
156  *
157  * Initializes a `git_describe_format_options` with default values. Equivalent to creating
158  * an instance with GIT_DESCRIBE_FORMAT_OPTIONS_INIT.
159  *
160  * @param opts The `git_describe_format_options` struct to initialize.
161  * @param version The struct version; pass `GIT_DESCRIBE_FORMAT_OPTIONS_VERSION`.
162  * @return Zero on success; -1 on failure.
163  */
164 //GIT_EXTERN
165 int git_describe_format_options_init(.git_describe_format_options* opts, uint version_);
166 
167 /**
168  * A struct that stores the result of a describe operation.
169  */
170 struct git_describe_result;
171 
172 /**
173  * Describe a commit
174  *
175  * Perform the describe operation on the given committish object.
176  *
177  * @param result pointer to store the result. You must free this once
178  * you're done with it.
179  * @param committish a committish to describe
180  * @param opts the lookup options (or NULL for defaults)
181  */
182 //GIT_EXTERN
183 int git_describe_commit(.git_describe_result** result, libgit2_d.types.git_object* committish, .git_describe_options* opts);
184 
185 /**
186  * Describe a commit
187  *
188  * Perform the describe operation on the current commit and the
189  * worktree. After peforming describe on HEAD, a status is run and the
190  * description is considered to be dirty if there are.
191  *
192  * @param out_ pointer to store the result. You must free this once
193  * you're done with it.
194  * @param repo the repository in which to perform the describe
195  * @param opts the lookup options (or NULL for defaults)
196  */
197 //GIT_EXTERN
198 int git_describe_workdir(.git_describe_result** out_, libgit2_d.types.git_repository* repo, .git_describe_options* opts);
199 
200 /**
201  * Print the describe result to a buffer
202  *
203  * @param out_ The buffer to store the result
204  * @param result the result from `git_describe_commit()` or
205  * `git_describe_workdir()`.
206  * @param opts the formatting options (or NULL for defaults)
207  */
208 //GIT_EXTERN
209 int git_describe_format(libgit2_d.buffer.git_buf* out_, const (.git_describe_result)* result, const (.git_describe_format_options)* opts);
210 
211 /**
212  * Free the describe result.
213  */
214 //GIT_EXTERN
215 void git_describe_result_free(.git_describe_result* result);
216 
217 /** @} */