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