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