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.tag; 11 12 13 private static import libgit2.oid; 14 private static import libgit2.strarray; 15 private static import libgit2.types; 16 private import libgit2.common: GIT_EXTERN; 17 18 /* 19 * @file git2/tag.h 20 * @brief Git tag parsing routines 21 * @defgroup git_tag Git tag management 22 * @ingroup Git 23 * @{ 24 */ 25 extern (C): 26 nothrow @nogc: 27 public: 28 29 /** 30 * Lookup a tag object from the repository. 31 * 32 * Params: 33 * out_ = pointer to the looked up tag 34 * repo = the repo to use when locating the tag. 35 * id = identity of the tag to locate. 36 * 37 * Returns: 0 or an error code 38 */ 39 @GIT_EXTERN 40 int git_tag_lookup(libgit2.types.git_tag** out_, libgit2.types.git_repository* repo, const (libgit2.oid.git_oid)* id); 41 42 /** 43 * Lookup a tag object from the repository, 44 * given a prefix of its identifier (short id). 45 * 46 * @see git_object_lookup_prefix 47 * 48 * Params: 49 * out_ = pointer to the looked up tag 50 * repo = the repo to use when locating the tag. 51 * id = identity of the tag to locate. 52 * len = the length of the short identifier 53 * 54 * Returns: 0 or an error code 55 */ 56 @GIT_EXTERN 57 int git_tag_lookup_prefix(libgit2.types.git_tag** out_, libgit2.types.git_repository* repo, const (libgit2.oid.git_oid)* id, size_t len); 58 59 /** 60 * Close an open tag 61 * 62 * You can no longer use the git_tag pointer after this call. 63 * 64 * IMPORTANT: You MUST call this method when you are through with a tag to 65 * release memory. Failure to do so will cause a memory leak. 66 * 67 * Params: 68 * tag = the tag to close 69 */ 70 @GIT_EXTERN 71 void git_tag_free(libgit2.types.git_tag* tag); 72 73 /** 74 * Get the id of a tag. 75 * 76 * Params: 77 * tag = a previously loaded tag. 78 * 79 * Returns: object identity for the tag. 80 */ 81 @GIT_EXTERN 82 const (libgit2.oid.git_oid)* git_tag_id(const (libgit2.types.git_tag)* tag); 83 84 /** 85 * Get the repository that contains the tag. 86 * 87 * Params: 88 * tag = A previously loaded tag. 89 * 90 * Returns: Repository that contains this tag. 91 */ 92 @GIT_EXTERN 93 libgit2.types.git_repository* git_tag_owner(const (libgit2.types.git_tag)* tag); 94 95 /** 96 * Get the tagged object of a tag 97 * 98 * This method performs a repository lookup for the 99 * given object and returns it 100 * 101 * Params: 102 * target_out = pointer where to store the target 103 * tag = a previously loaded tag. 104 * 105 * Returns: 0 or an error code 106 */ 107 @GIT_EXTERN 108 int git_tag_target(libgit2.types.git_object** target_out, const (libgit2.types.git_tag)* tag); 109 110 /** 111 * Get the OID of the tagged object of a tag 112 * 113 * Params: 114 * tag = a previously loaded tag. 115 * 116 * Returns: pointer to the OID 117 */ 118 @GIT_EXTERN 119 const (libgit2.oid.git_oid)* git_tag_target_id(const (libgit2.types.git_tag)* tag); 120 121 /** 122 * Get the type of a tag's tagged object 123 * 124 * Params: 125 * tag = a previously loaded tag. 126 * 127 * Returns: type of the tagged object 128 */ 129 @GIT_EXTERN 130 libgit2.types.git_object_t git_tag_target_type(const (libgit2.types.git_tag)* tag); 131 132 /** 133 * Get the name of a tag 134 * 135 * Params: 136 * tag = a previously loaded tag. 137 * 138 * Returns: name of the tag 139 */ 140 @GIT_EXTERN 141 const (char)* git_tag_name(const (libgit2.types.git_tag)* tag); 142 143 /** 144 * Get the tagger (author) of a tag 145 * 146 * Params: 147 * tag = a previously loaded tag. 148 * 149 * Returns: reference to the tag's author or null when unspecified 150 */ 151 @GIT_EXTERN 152 const (libgit2.types.git_signature)* git_tag_tagger(const (libgit2.types.git_tag)* tag); 153 154 /** 155 * Get the message of a tag 156 * 157 * Params: 158 * tag = a previously loaded tag. 159 * 160 * Returns: message of the tag or null when unspecified 161 */ 162 @GIT_EXTERN 163 const (char)* git_tag_message(const (libgit2.types.git_tag)* tag); 164 165 /** 166 * Create a new tag in the repository from an object 167 * 168 * A new reference will also be created pointing to 169 * this tag object. If `force` is true and a reference 170 * already exists with the given name, it'll be replaced. 171 * 172 * The message will not be cleaned up. This can be achieved 173 * through `git_message_prettify()`. 174 * 175 * The tag name will be checked for validity. You must avoid 176 * the characters '~', '^', ':', '\\', '?', '[', and '*', and the 177 * sequences ".." and "@{" which have special meaning to revparse. 178 * 179 * Params: 180 * oid = Pointer where to store the OID of the newly created tag. If the tag already exists, this parameter will be the oid of the existing tag, and the function will return a git_error_code.GIT_EEXISTS error code. 181 * repo = Repository where to store the tag 182 * tag_name = Name for the tag; this name is validated for consistency. It should also not conflict with an already existing tag name 183 * target = Object to which this tag points. This object must belong to the given `repo`. 184 * tagger = Signature of the tagger for this tag, and of the tagging time 185 * message = Full message for this tag 186 * force = Overwrite existing references 187 * 188 * Returns: 0 on success, git_error_code.GIT_EINVALIDSPEC or an error code A tag object is written to the ODB, and a proper reference is written in the /refs/tags folder, pointing to it 189 */ 190 @GIT_EXTERN 191 int git_tag_create(libgit2.oid.git_oid* oid, libgit2.types.git_repository* repo, const (char)* tag_name, const (libgit2.types.git_object)* target, const (libgit2.types.git_signature)* tagger, const (char)* message, int force); 192 193 /** 194 * Create a new tag in the object database pointing to a git_object 195 * 196 * The message will not be cleaned up. This can be achieved 197 * through `git_message_prettify()`. 198 * 199 * Params: 200 * oid = Pointer where to store the OID of the newly created tag 201 * repo = Repository where to store the tag 202 * tag_name = Name for the tag 203 * target = Object to which this tag points. This object must belong to the given `repo`. 204 * tagger = Signature of the tagger for this tag, and of the tagging time 205 * message = Full message for this tag 206 * 207 * Returns: 0 on success or an error code 208 */ 209 @GIT_EXTERN 210 int git_tag_annotation_create(libgit2.oid.git_oid* oid, libgit2.types.git_repository* repo, const (char)* tag_name, const (libgit2.types.git_object)* target, const (libgit2.types.git_signature)* tagger, const (char)* message); 211 212 /** 213 * Create a new tag in the repository from a buffer 214 * 215 * Params: 216 * oid = Pointer where to store the OID of the newly created tag 217 * repo = Repository where to store the tag 218 * buffer = Raw tag data 219 * force = Overwrite existing tags 220 * 221 * Returns: 0 on success; error code otherwise 222 */ 223 @GIT_EXTERN 224 int git_tag_create_from_buffer(libgit2.oid.git_oid* oid, libgit2.types.git_repository* repo, const (char)* buffer, int force); 225 226 /** 227 * Create a new lightweight tag pointing at a target object 228 * 229 * A new direct reference will be created pointing to 230 * this target object. If `force` is true and a reference 231 * already exists with the given name, it'll be replaced. 232 * 233 * The tag name will be checked for validity. 234 * See `git_tag_create()` for rules about valid names. 235 * 236 * Params: 237 * oid = Pointer where to store the OID of the provided target object. If the tag already exists, this parameter will be filled with the oid of the existing pointed object and the function will return a git_error_code.GIT_EEXISTS error code. 238 * repo = Repository where to store the lightweight tag 239 * tag_name = Name for the tag; this name is validated for consistency. It should also not conflict with an already existing tag name 240 * target = Object to which this tag points. This object must belong to the given `repo`. 241 * force = Overwrite existing references 242 * 243 * Returns: 0 on success, git_error_code.GIT_EINVALIDSPEC or an error code A proper reference is written in the /refs/tags folder, pointing to the provided target object 244 */ 245 @GIT_EXTERN 246 int git_tag_create_lightweight(libgit2.oid.git_oid* oid, libgit2.types.git_repository* repo, const (char)* tag_name, const (libgit2.types.git_object)* target, int force); 247 248 /** 249 * Delete an existing tag reference. 250 * 251 * The tag name will be checked for validity. 252 * See `git_tag_create()` for rules about valid names. 253 * 254 * Params: 255 * repo = Repository where lives the tag 256 * tag_name = Name of the tag to be deleted; this name is validated for consistency. 257 * 258 * Returns: 0 on success, git_error_code.GIT_EINVALIDSPEC or an error code 259 */ 260 @GIT_EXTERN 261 int git_tag_delete(libgit2.types.git_repository* repo, const (char)* tag_name); 262 263 /** 264 * Fill a list with all the tags in the Repository 265 * 266 * The string array will be filled with the names of the 267 * matching tags; these values are owned by the user and 268 * should be free'd manually when no longer needed, using 269 * `git_strarray_free`. 270 * 271 * Params: 272 * tag_names = Pointer to a git_strarray structure where the tag names will be stored 273 * repo = Repository where to find the tags 274 * 275 * Returns: 0 or an error code 276 */ 277 @GIT_EXTERN 278 int git_tag_list(libgit2.strarray.git_strarray* tag_names, libgit2.types.git_repository* repo); 279 280 /** 281 * Fill a list with all the tags in the Repository 282 * which name match a defined pattern 283 * 284 * If an empty pattern is provided, all the tags 285 * will be returned. 286 * 287 * The string array will be filled with the names of the 288 * matching tags; these values are owned by the user and 289 * should be free'd manually when no longer needed, using 290 * `git_strarray_free`. 291 * 292 * Params: 293 * tag_names = Pointer to a git_strarray structure where the tag names will be stored 294 * pattern = Standard fnmatch pattern 295 * repo = Repository where to find the tags 296 * 297 * Returns: 0 or an error code 298 */ 299 @GIT_EXTERN 300 int git_tag_list_match(libgit2.strarray.git_strarray* tag_names, const (char)* pattern, libgit2.types.git_repository* repo); 301 302 /** 303 * Callback used to iterate over tag names 304 * 305 * @see git_tag_foreach 306 * 307 * Returns: non-zero to terminate the iteration 308 */ 309 /* 310 * Params: 311 * name = The tag name 312 * oid = The tag's OID 313 * payload = Payload passed to git_tag_foreach 314 */ 315 alias git_tag_foreach_cb = int function(const (char)* name, libgit2.oid.git_oid* oid, void* payload); 316 317 /** 318 * Call callback `cb' for each tag in the repository 319 * 320 * Params: 321 * repo = Repository 322 * callback = Callback function 323 * payload = Pointer to callback data (optional) 324 */ 325 @GIT_EXTERN 326 int git_tag_foreach(libgit2.types.git_repository* repo, .git_tag_foreach_cb callback, void* payload); 327 328 /** 329 * Recursively peel a tag until a non tag git_object is found 330 * 331 * The retrieved `tag_target` object is owned by the repository 332 * and should be closed with the `git_object_free` method. 333 * 334 * Params: 335 * tag_target_out = Pointer to the peeled git_object 336 * tag = The tag to be processed 337 * 338 * Returns: 0 or an error code 339 */ 340 @GIT_EXTERN 341 int git_tag_peel(libgit2.types.git_object** tag_target_out, const (libgit2.types.git_tag)* tag); 342 343 /** 344 * Create an in-memory copy of a tag. The copy must be explicitly 345 * free'd or it will leak. 346 * 347 * Params: 348 * out_ = Pointer to store the copy of the tag 349 * source = Original tag to copy 350 * 351 * Returns: 0 352 */ 353 @GIT_EXTERN 354 int git_tag_dup(libgit2.types.git_tag** out_, libgit2.types.git_tag* source); 355 356 /** 357 * Determine whether a tag name is valid, meaning that (when prefixed 358 * with `refs/tags/`) that it is a valid reference name, and that any 359 * additional tag name restrictions are imposed (eg, it cannot start 360 * with a `-`). 361 * 362 * Params: 363 * valid = output pointer to set with validity of given tag name 364 * name = a tag name to test 365 * 366 * Returns: 0 on success or an error code 367 */ 368 @GIT_EXTERN 369 int git_tag_name_is_valid(int* valid, const (char)* name); 370 371 /* @} */