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.refs; 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/refs.h 20 * @brief Git reference management routines 21 * @defgroup git_reference Git reference management routines 22 * @ingroup Git 23 * @{ 24 */ 25 extern (C): 26 nothrow @nogc: 27 public: 28 29 /** 30 * Lookup a reference by name in a repository. 31 * 32 * The returned reference must be freed by the user. 33 * 34 * The name will be checked for validity. 35 * See `git_reference_symbolic_create()` for rules about valid names. 36 * 37 * Params: 38 * out_ = pointer to the looked-up reference 39 * repo = the repository to look up the reference 40 * name = the long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...) 41 * 42 * Returns: 0 on success, git_error_code.GIT_ENOTFOUND, git_error_code.GIT_EINVALIDSPEC or an error code. 43 */ 44 @GIT_EXTERN 45 int git_reference_lookup(libgit2.types.git_reference** out_, libgit2.types.git_repository* repo, const (char)* name); 46 47 /** 48 * Lookup a reference by name and resolve immediately to OID. 49 * 50 * This function provides a quick way to resolve a reference name straight 51 * through to the object id that it refers to. This avoids having to 52 * allocate or free any `git_reference` objects for simple situations. 53 * 54 * The name will be checked for validity. 55 * See `git_reference_symbolic_create()` for rules about valid names. 56 * 57 * Params: 58 * out_ = Pointer to oid to be filled in 59 * repo = The repository in which to look up the reference 60 * name = The long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...) 61 * 62 * Returns: 0 on success, git_error_code.GIT_ENOTFOUND, git_error_code.GIT_EINVALIDSPEC or an error code. 63 */ 64 @GIT_EXTERN 65 int git_reference_name_to_id(libgit2.oid.git_oid* out_, libgit2.types.git_repository* repo, const (char)* name); 66 67 /** 68 * Lookup a reference by DWIMing its short name 69 * 70 * Apply the git precedence rules to the given shorthand to determine 71 * which reference the user is referring to. 72 * 73 * Params: 74 * out_ = pointer in which to store the reference 75 * repo = the repository in which to look 76 * shorthand = the short name for the reference 77 * 78 * Returns: 0 or an error code 79 */ 80 @GIT_EXTERN 81 int git_reference_dwim(libgit2.types.git_reference** out_, libgit2.types.git_repository* repo, const (char)* shorthand); 82 83 /** 84 * Conditionally create a new symbolic reference. 85 * 86 * A symbolic reference is a reference name that refers to another 87 * reference name. If the other name moves, the symbolic name will move, 88 * too. As a simple example, the "HEAD" reference might refer to 89 * "refs/heads/master" while on the "master" branch of a repository. 90 * 91 * The symbolic reference will be created in the repository and written to 92 * the disk. The generated reference object must be freed by the user. 93 * 94 * Valid reference names must follow one of two patterns: 95 * 96 * 1. Top-level names must contain only capital letters and underscores, 97 * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). 98 * 2. Names prefixed with "refs/" can be almost anything. You must avoid 99 * the characters '~', '^', ':', '\\', '?', '[', and '*', and the 100 * sequences ".." and "@{" which have special meaning to revparse. 101 * 102 * This function will return an error if a reference already exists with the 103 * given name unless `force` is true, in which case it will be overwritten. 104 * 105 * The message for the reflog will be ignored if the reference does 106 * not belong in the standard set (HEAD, branches and remote-tracking 107 * branches) and it does not have a reflog. 108 * 109 * It will return git_error_code.GIT_EMODIFIED if the reference's value at the time 110 * of updating does not match the one passed through `current_value` 111 * (i.e. if the ref has changed since the user read it). 112 * 113 * If `current_value` is all zeros, this function will return GIT_EMODIFIED 114 * if the ref already exists. 115 * 116 * Params: 117 * out_ = Pointer to the newly created reference 118 * repo = Repository where that reference will live 119 * name = The name of the reference 120 * target = The target of the reference 121 * force = Overwrite existing references 122 * current_value = The expected value of the reference when updating 123 * log_message = The one line long message to be appended to the reflog 124 * 125 * Returns: 0 on success, git_error_code.GIT_EEXISTS, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EMODIFIED or an error code 126 */ 127 @GIT_EXTERN 128 int git_reference_symbolic_create_matching(libgit2.types.git_reference** out_, libgit2.types.git_repository* repo, const (char)* name, const (char)* target, int force, const (char)* current_value, const (char)* log_message); 129 130 /** 131 * Create a new symbolic reference. 132 * 133 * A symbolic reference is a reference name that refers to another 134 * reference name. If the other name moves, the symbolic name will move, 135 * too. As a simple example, the "HEAD" reference might refer to 136 * "refs/heads/master" while on the "master" branch of a repository. 137 * 138 * The symbolic reference will be created in the repository and written to 139 * the disk. The generated reference object must be freed by the user. 140 * 141 * Valid reference names must follow one of two patterns: 142 * 143 * 1. Top-level names must contain only capital letters and underscores, 144 * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). 145 * 2. Names prefixed with "refs/" can be almost anything. You must avoid 146 * the characters '~', '^', ':', '\\', '?', '[', and '*', and the 147 * sequences ".." and "@{" which have special meaning to revparse. 148 * 149 * This function will return an error if a reference already exists with the 150 * given name unless `force` is true, in which case it will be overwritten. 151 * 152 * The message for the reflog will be ignored if the reference does 153 * not belong in the standard set (HEAD, branches and remote-tracking 154 * branches) and it does not have a reflog. 155 * 156 * Params: 157 * out_ = Pointer to the newly created reference 158 * repo = Repository where that reference will live 159 * name = The name of the reference 160 * target = The target of the reference 161 * force = Overwrite existing references 162 * log_message = The one line long message to be appended to the reflog 163 * 164 * Returns: 0 on success, git_error_code.GIT_EEXISTS, git_error_code.GIT_EINVALIDSPEC or an error code 165 */ 166 @GIT_EXTERN 167 int git_reference_symbolic_create(libgit2.types.git_reference** out_, libgit2.types.git_repository* repo, const (char)* name, const (char)* target, int force, const (char)* log_message); 168 169 /** 170 * Create a new direct reference. 171 * 172 * A direct reference (also called an object id reference) refers directly 173 * to a specific object id (a.k.a. OID or SHA) in the repository. The id 174 * permanently refers to the object (although the reference itself can be 175 * moved). For example, in libgit2 the direct ref "refs/tags/v0.17.0" 176 * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977. 177 * 178 * The direct reference will be created in the repository and written to 179 * the disk. The generated reference object must be freed by the user. 180 * 181 * Valid reference names must follow one of two patterns: 182 * 183 * 1. Top-level names must contain only capital letters and underscores, 184 * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). 185 * 2. Names prefixed with "refs/" can be almost anything. You must avoid 186 * the characters '~', '^', ':', '\\', '?', '[', and '*', and the 187 * sequences ".." and "@{" which have special meaning to revparse. 188 * 189 * This function will return an error if a reference already exists with the 190 * given name unless `force` is true, in which case it will be overwritten. 191 * 192 * The message for the reflog will be ignored if the reference does 193 * not belong in the standard set (HEAD, branches and remote-tracking 194 * branches) and it does not have a reflog. 195 * 196 * Params: 197 * out_ = Pointer to the newly created reference 198 * repo = Repository where that reference will live 199 * name = The name of the reference 200 * id = The object id pointed to by the reference. 201 * force = Overwrite existing references 202 * log_message = The one line long message to be appended to the reflog 203 * 204 * Returns: 0 on success, git_error_code.GIT_EEXISTS, git_error_code.GIT_EINVALIDSPEC or an error code 205 */ 206 @GIT_EXTERN 207 int git_reference_create(libgit2.types.git_reference** out_, libgit2.types.git_repository* repo, const (char)* name, const (libgit2.oid.git_oid)* id, int force, const (char)* log_message); 208 209 /** 210 * Conditionally create new direct reference 211 * 212 * A direct reference (also called an object id reference) refers directly 213 * to a specific object id (a.k.a. OID or SHA) in the repository. The id 214 * permanently refers to the object (although the reference itself can be 215 * moved). For example, in libgit2 the direct ref "refs/tags/v0.17.0" 216 * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977. 217 * 218 * The direct reference will be created in the repository and written to 219 * the disk. The generated reference object must be freed by the user. 220 * 221 * Valid reference names must follow one of two patterns: 222 * 223 * 1. Top-level names must contain only capital letters and underscores, 224 * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). 225 * 2. Names prefixed with "refs/" can be almost anything. You must avoid 226 * the characters '~', '^', ':', '\\', '?', '[', and '*', and the 227 * sequences ".." and "@{" which have special meaning to revparse. 228 * 229 * This function will return an error if a reference already exists with the 230 * given name unless `force` is true, in which case it will be overwritten. 231 * 232 * The message for the reflog will be ignored if the reference does 233 * not belong in the standard set (HEAD, branches and remote-tracking 234 * branches) and it does not have a reflog. 235 * 236 * It will return git_error_code.GIT_EMODIFIED if the reference's value at the time 237 * of updating does not match the one passed through `current_id` 238 * (i.e. if the ref has changed since the user read it). 239 * 240 * Params: 241 * out_ = Pointer to the newly created reference 242 * repo = Repository where that reference will live 243 * name = The name of the reference 244 * id = The object id pointed to by the reference. 245 * force = Overwrite existing references 246 * current_id = The expected value of the reference at the time of update 247 * log_message = The one line long message to be appended to the reflog 248 * 249 * Returns: 0 on success, git_error_code.GIT_EMODIFIED if the value of the reference has changed, git_error_code.GIT_EEXISTS, git_error_code.GIT_EINVALIDSPEC or an error code 250 */ 251 @GIT_EXTERN 252 int git_reference_create_matching(libgit2.types.git_reference** out_, libgit2.types.git_repository* repo, const (char)* name, const (libgit2.oid.git_oid)* id, int force, const (libgit2.oid.git_oid)* current_id, const (char)* log_message); 253 254 /** 255 * Get the OID pointed to by a direct reference. 256 * 257 * Only available if the reference is direct (i.e. an object id reference, 258 * not a symbolic one). 259 * 260 * To find the OID of a symbolic ref, call `git_reference_resolve()` and 261 * then this function (or maybe use `git_reference_name_to_id()` to 262 * directly resolve a reference name all the way through to an OID). 263 * 264 * Params: 265 * ref_ = The reference 266 * 267 * Returns: a pointer to the oid if available, null otherwise 268 */ 269 @GIT_EXTERN 270 const (libgit2.oid.git_oid)* git_reference_target(const (libgit2.types.git_reference)* ref_); 271 272 /** 273 * Return the peeled OID target of this reference. 274 * 275 * This peeled OID only applies to direct references that point to 276 * a hard Tag object: it is the result of peeling such Tag. 277 * 278 * Params: 279 * ref_ = The reference 280 * 281 * Returns: a pointer to the oid if available, null otherwise 282 */ 283 @GIT_EXTERN 284 const (libgit2.oid.git_oid)* git_reference_target_peel(const (libgit2.types.git_reference)* ref_); 285 286 /** 287 * Get full name to the reference pointed to by a symbolic reference. 288 * 289 * Only available if the reference is symbolic. 290 * 291 * Params: 292 * ref_ = The reference 293 * 294 * Returns: a pointer to the name if available, null otherwise 295 */ 296 @GIT_EXTERN 297 const (char)* git_reference_symbolic_target(const (libgit2.types.git_reference)* ref_); 298 299 /** 300 * Get the type of a reference. 301 * 302 * Either direct (git_reference_t.GIT_REFERENCE_DIRECT) or symbolic (git_reference_t.GIT_REFERENCE_SYMBOLIC) 303 * 304 * Params: 305 * ref_ = The reference 306 * 307 * Returns: the type 308 */ 309 @GIT_EXTERN 310 libgit2.types.git_reference_t git_reference_type(const (libgit2.types.git_reference)* ref_); 311 312 /** 313 * Get the full name of a reference. 314 * 315 * See `git_reference_symbolic_create()` for rules about valid names. 316 * 317 * Params: 318 * ref_ = The reference 319 * 320 * Returns: the full name for the ref_ 321 */ 322 @GIT_EXTERN 323 const (char)* git_reference_name(const (libgit2.types.git_reference)* ref_); 324 325 /** 326 * Resolve a symbolic reference to a direct reference. 327 * 328 * This method iteratively peels a symbolic reference until it resolves to 329 * a direct reference to an OID. 330 * 331 * The peeled reference is returned in the `resolved_ref` argument, and 332 * must be freed manually once it's no longer needed. 333 * 334 * If a direct reference is passed as an argument, a copy of that 335 * reference is returned. This copy must be manually freed too. 336 * 337 * Params: 338 * out_ = Pointer to the peeled reference 339 * ref_ = The reference 340 * 341 * Returns: 0 or an error code 342 */ 343 @GIT_EXTERN 344 int git_reference_resolve(libgit2.types.git_reference** out_, const (libgit2.types.git_reference)* ref_); 345 346 /** 347 * Get the repository where a reference resides. 348 * 349 * Params: 350 * ref_ = The reference 351 * 352 * Returns: a pointer to the repo 353 */ 354 @GIT_EXTERN 355 libgit2.types.git_repository* git_reference_owner(const (libgit2.types.git_reference)* ref_); 356 357 /** 358 * Create a new reference with the same name as the given reference but a 359 * different symbolic target. The reference must be a symbolic reference, 360 * otherwise this will fail. 361 * 362 * The new reference will be written to disk, overwriting the given reference. 363 * 364 * The target name will be checked for validity. 365 * See `git_reference_symbolic_create()` for rules about valid names. 366 * 367 * The message for the reflog will be ignored if the reference does 368 * not belong in the standard set (HEAD, branches and remote-tracking 369 * branches) and it does not have a reflog. 370 * 371 * Params: 372 * out_ = Pointer to the newly created reference 373 * ref_ = The reference 374 * target = The new target for the reference 375 * log_message = The one line long message to be appended to the reflog 376 * 377 * Returns: 0 on success, git_error_code.GIT_EINVALIDSPEC or an error code 378 */ 379 @GIT_EXTERN 380 int git_reference_symbolic_set_target(libgit2.types.git_reference** out_, libgit2.types.git_reference* ref_, const (char)* target, const (char)* log_message); 381 382 /** 383 * Conditionally create a new reference with the same name as the given 384 * reference but a different OID target. The reference must be a direct 385 * reference, otherwise this will fail. 386 * 387 * The new reference will be written to disk, overwriting the given reference. 388 * 389 * Params: 390 * out_ = Pointer to the newly created reference 391 * ref_ = The reference 392 * id = The new target OID for the reference 393 * log_message = The one line long message to be appended to the reflog 394 * 395 * Returns: 0 on success, git_error_code.GIT_EMODIFIED if the value of the reference has changed since it was read, or an error code 396 */ 397 @GIT_EXTERN 398 int git_reference_set_target(libgit2.types.git_reference** out_, libgit2.types.git_reference* ref_, const (libgit2.oid.git_oid)* id, const (char)* log_message); 399 400 /** 401 * Rename an existing reference. 402 * 403 * This method works for both direct and symbolic references. 404 * 405 * The new name will be checked for validity. 406 * See `git_reference_symbolic_create()` for rules about valid names. 407 * 408 * If the `force` flag is not enabled, and there's already 409 * a reference with the given name, the renaming will fail. 410 * 411 * IMPORTANT: 412 * The user needs to write a proper reflog entry if the 413 * reflog is enabled for the repository. We only rename 414 * the reflog if it exists. 415 * 416 * Params: 417 * new_ref = ? 418 * ref_ = The reference to rename 419 * new_name = The new name for the reference 420 * force = Overwrite an existing reference 421 * log_message = The one line long message to be appended to the reflog 422 * 423 * Returns: 0 on success, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EEXISTS or an error code 424 * 425 */ 426 @GIT_EXTERN 427 int git_reference_rename(libgit2.types.git_reference** new_ref, libgit2.types.git_reference* ref_, const (char)* new_name, int force, const (char)* log_message); 428 429 /** 430 * Delete an existing reference. 431 * 432 * This method works for both direct and symbolic references. The reference 433 * will be immediately removed on disk but the memory will not be freed. 434 * Callers must call `git_reference_free`. 435 * 436 * This function will return an error if the reference has changed 437 * from the time it was looked up. 438 * 439 * Params: 440 * ref_ = The reference to remove 441 * 442 * Returns: 0, git_error_code.GIT_EMODIFIED or an error code 443 */ 444 @GIT_EXTERN 445 int git_reference_delete(libgit2.types.git_reference* ref_); 446 447 /** 448 * Delete an existing reference by name 449 * 450 * This method removes the named reference from the repository without 451 * looking at its old value. 452 * 453 * Params: 454 * repo = ? 455 * name = The reference to remove 456 * 457 * Returns: 0 or an error code 458 */ 459 @GIT_EXTERN 460 int git_reference_remove(libgit2.types.git_repository* repo, const (char)* name); 461 462 /** 463 * Fill a list with all the references that can be found in a repository. 464 * 465 * The string array will be filled with the names of all references; these 466 * values are owned by the user and should be free'd manually when no 467 * longer needed, using `git_strarray_free()`. 468 * 469 * Params: 470 * array = Pointer to a git_strarray structure where the reference names will be stored 471 * repo = Repository where to find the refs 472 * 473 * Returns: 0 or an error code 474 */ 475 @GIT_EXTERN 476 int git_reference_list(libgit2.strarray.git_strarray* array, libgit2.types.git_repository* repo); 477 478 /** 479 * Callback used to iterate over references 480 * 481 * @see git_reference_foreach 482 * 483 * Returns: non-zero to terminate the iteration 484 */ 485 /* 486 * Params: 487 * reference = The reference object 488 * payload = Payload passed to git_reference_foreach 489 */ 490 alias git_reference_foreach_cb = int function(libgit2.types.git_reference* reference, void* payload); 491 492 /** 493 * Callback used to iterate over reference names 494 * 495 * @see git_reference_foreach_name 496 * 497 * Returns: non-zero to terminate the iteration 498 */ 499 /* 500 * Params: 501 * name = The reference name 502 * payload = Payload passed to git_reference_foreach_name 503 */ 504 alias git_reference_foreach_name_cb = int function(const (char)* name, void* payload); 505 506 /** 507 * Perform a callback on each reference in the repository. 508 * 509 * The `callback` function will be called for each reference in the 510 * repository, receiving the reference object and the `payload` value 511 * passed to this method. Returning a non-zero value from the callback 512 * will terminate the iteration. 513 * 514 * Note that the callback function is responsible to call `git_reference_free` 515 * on each reference passed to it. 516 * 517 * Params: 518 * repo = Repository where to find the refs 519 * callback = Function which will be called for every listed ref 520 * payload = Additional data to pass to the callback 521 * 522 * Returns: 0 on success, non-zero callback return value, or error code 523 */ 524 @GIT_EXTERN 525 int git_reference_foreach(libgit2.types.git_repository* repo, .git_reference_foreach_cb callback, void* payload); 526 527 /** 528 * Perform a callback on the fully-qualified name of each reference. 529 * 530 * The `callback` function will be called for each reference in the 531 * repository, receiving the name of the reference and the `payload` value 532 * passed to this method. Returning a non-zero value from the callback 533 * will terminate the iteration. 534 * 535 * Params: 536 * repo = Repository where to find the refs 537 * callback = Function which will be called for every listed ref name 538 * payload = Additional data to pass to the callback 539 * 540 * Returns: 0 on success, non-zero callback return value, or error code 541 */ 542 @GIT_EXTERN 543 int git_reference_foreach_name(libgit2.types.git_repository* repo, git_reference_foreach_name_cb callback, void* payload); 544 545 /** 546 * Create a copy of an existing reference. 547 * 548 * Call `git_reference_free` to free the data. 549 * 550 * Params: 551 * dest = pointer where to store the copy 552 * source = object to copy 553 * 554 * Returns: 0 or an error code 555 */ 556 @GIT_EXTERN 557 int git_reference_dup(libgit2.types.git_reference** dest, libgit2.types.git_reference* source); 558 559 /** 560 * Free the given reference. 561 * 562 * Params: 563 * ref_ = git_reference 564 */ 565 @GIT_EXTERN 566 void git_reference_free(libgit2.types.git_reference* ref_); 567 568 /** 569 * Compare two references. 570 * 571 * Params: 572 * ref1 = The first git_reference 573 * ref2 = The second git_reference 574 * 575 * Returns: 0 if the same, else a stable but meaningless ordering. 576 */ 577 @GIT_EXTERN 578 int git_reference_cmp(const (libgit2.types.git_reference)* ref1, const (libgit2.types.git_reference)* ref2); 579 580 /** 581 * Create an iterator for the repo's references 582 * 583 * Params: 584 * out_ = pointer in which to store the iterator 585 * repo = the repository 586 * 587 * Returns: 0 or an error code 588 */ 589 @GIT_EXTERN 590 int git_reference_iterator_new(libgit2.types.git_reference_iterator** out_, libgit2.types.git_repository* repo); 591 592 /** 593 * Create an iterator for the repo's references that match the 594 * specified glob 595 * 596 * Params: 597 * out_ = pointer in which to store the iterator 598 * repo = the repository 599 * glob = the glob to match against the reference names 600 * 601 * Returns: 0 or an error code 602 */ 603 @GIT_EXTERN 604 int git_reference_iterator_glob_new(libgit2.types.git_reference_iterator** out_, libgit2.types.git_repository* repo, const (char)* glob); 605 606 /** 607 * Get the next reference 608 * 609 * Params: 610 * out_ = pointer in which to store the reference 611 * iter = the iterator 612 * 613 * Returns: 0, git_error_code.GIT_ITEROVER if there are no more; or an error code 614 */ 615 @GIT_EXTERN 616 int git_reference_next(libgit2.types.git_reference** out_, libgit2.types.git_reference_iterator* iter); 617 618 /** 619 * Get the next reference's name 620 * 621 * This function is provided for convenience in case only the names 622 * are interesting as it avoids the allocation of the `git_reference` 623 * object which `git_reference_next()` needs. 624 * 625 * Params: 626 * out_ = pointer in which to store the string 627 * iter = the iterator 628 * 629 * Returns: 0, git_error_code.GIT_ITEROVER if there are no more; or an error code 630 */ 631 @GIT_EXTERN 632 int git_reference_next_name(const (char)** out_, libgit2.types.git_reference_iterator* iter); 633 634 /** 635 * Free the iterator and its associated resources 636 * 637 * Params: 638 * iter = the iterator to free 639 */ 640 @GIT_EXTERN 641 void git_reference_iterator_free(libgit2.types.git_reference_iterator* iter); 642 643 /** 644 * Perform a callback on each reference in the repository whose name 645 * matches the given pattern. 646 * 647 * This function acts like `git_reference_foreach()` with an additional 648 * pattern match being applied to the reference name before issuing the 649 * callback function. See that function for more information. 650 * 651 * The pattern is matched using fnmatch or "glob" style where a '*' matches 652 * any sequence of letters, a '?' matches any letter, and square brackets 653 * can be used to define character ranges (such as "[0-9]" for digits). 654 * 655 * Params: 656 * repo = Repository where to find the refs 657 * glob = Pattern to match (fnmatch-style) against reference name. 658 * callback = Function which will be called for every listed ref 659 * payload = Additional data to pass to the callback 660 * 661 * Returns: 0 on success, git_error_code.GIT_EUSER on non-zero callback, or error code 662 */ 663 @GIT_EXTERN 664 int git_reference_foreach_glob(libgit2.types.git_repository* repo, const (char)* glob, git_reference_foreach_name_cb callback, void* payload); 665 666 /** 667 * Check if a reflog exists for the specified reference. 668 * 669 * Params: 670 * repo = the repository 671 * refname = the reference's name 672 * 673 * Returns: 0 when no reflog can be found, 1 when it exists; otherwise an error code. 674 */ 675 @GIT_EXTERN 676 int git_reference_has_log(libgit2.types.git_repository* repo, const (char)* refname); 677 678 /** 679 * Ensure there is a reflog for a particular reference. 680 * 681 * Make sure that successive updates to the reference will append to 682 * its log. 683 * 684 * Params: 685 * repo = the repository 686 * refname = the reference's name 687 * 688 * Returns: 0 or an error code. 689 */ 690 @GIT_EXTERN 691 int git_reference_ensure_log(libgit2.types.git_repository* repo, const (char)* refname); 692 693 /** 694 * Check if a reference is a local branch. 695 * 696 * Params: 697 * ref_ = A git reference 698 * 699 * Returns: 1 when the reference lives in the refs/heads namespace; 0 otherwise. 700 */ 701 @GIT_EXTERN 702 int git_reference_is_branch(const (libgit2.types.git_reference)* ref_); 703 704 /** 705 * Check if a reference is a remote tracking branch 706 * 707 * Params: 708 * ref_ = A git reference 709 * 710 * Returns: 1 when the reference lives in the refs/remotes namespace; 0 otherwise. 711 */ 712 @GIT_EXTERN 713 int git_reference_is_remote(const (libgit2.types.git_reference)* ref_); 714 715 /** 716 * Check if a reference is a tag 717 * 718 * Params: 719 * ref_ = A git reference 720 * 721 * Returns: 1 when the reference lives in the refs/tags namespace; 0 otherwise. 722 */ 723 @GIT_EXTERN 724 int git_reference_is_tag(const (libgit2.types.git_reference)* ref_); 725 726 /** 727 * Check if a reference is a note 728 * 729 * Params: 730 * ref_ = A git reference 731 * 732 * Returns: 1 when the reference lives in the refs/notes namespace; 0 otherwise. 733 */ 734 @GIT_EXTERN 735 int git_reference_is_note(const (libgit2.types.git_reference)* ref_); 736 737 /** 738 * Normalization options for reference lookup 739 */ 740 enum git_reference_format_t 741 { 742 /** 743 * No particular normalization. 744 */ 745 GIT_REFERENCE_FORMAT_NORMAL = 0u, 746 747 /** 748 * Control whether one-level refnames are accepted 749 * (i.e., refnames that do not contain multiple /-separated 750 * components). Those are expected to be written only using 751 * uppercase letters and underscore (FETCH_HEAD, ...) 752 */ 753 GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL = 1u << 0, 754 755 /** 756 * Interpret the provided name as a reference pattern for a 757 * refspec (as used with remote repositories). If this option 758 * is enabled, the name is allowed to contain a single * (<star>) 759 * in place of a one full pathname component 760 * (e.g., foo/<star>/bar but not foo/bar<star>). 761 */ 762 GIT_REFERENCE_FORMAT_REFSPEC_PATTERN = 1u << 1, 763 764 /** 765 * Interpret the name as part of a refspec in shorthand form 766 * so the `ONELEVEL` naming rules aren't enforced and 'master' 767 * becomes a valid name. 768 */ 769 GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = 1u << 2, 770 } 771 772 //Declaration name in C language 773 enum 774 { 775 GIT_REFERENCE_FORMAT_NORMAL = .git_reference_format_t.GIT_REFERENCE_FORMAT_NORMAL, 776 GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL = .git_reference_format_t.GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL, 777 GIT_REFERENCE_FORMAT_REFSPEC_PATTERN = .git_reference_format_t.GIT_REFERENCE_FORMAT_REFSPEC_PATTERN, 778 GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = .git_reference_format_t.GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND, 779 } 780 781 /** 782 * Normalize reference name and check validity. 783 * 784 * This will normalize the reference name by removing any leading slash 785 * '/' characters and collapsing runs of adjacent slashes between name 786 * components into a single slash. 787 * 788 * Once normalized, if the reference name is valid, it will be returned in 789 * the user allocated buffer. 790 * 791 * See `git_reference_symbolic_create()` for rules about valid names. 792 * 793 * Params: 794 * buffer_out = User allocated buffer to store normalized name 795 * buffer_size = Size of buffer_out 796 * name = Reference name to be checked. 797 * flags = Flags to constrain name validation rules - see the GIT_REFERENCE_FORMAT constants above. 798 * 799 * Returns: 0 on success, git_error_code.GIT_EBUFS if buffer is too small, git_error_code.GIT_EINVALIDSPEC or an error code. 800 */ 801 @GIT_EXTERN 802 int git_reference_normalize_name(char* buffer_out, size_t buffer_size, const (char)* name, uint flags); 803 804 /** 805 * Recursively peel reference until object of the specified type is found. 806 * 807 * The retrieved `peeled` object is owned by the repository 808 * and should be closed with the `git_object_free` method. 809 * 810 * If you pass `git_object_t.GIT_OBJECT_ANY` as the target type, then the object 811 * will be peeled until a non-tag object is met. 812 * 813 * Params: 814 * out_ = Pointer to the peeled git_object 815 * ref_ = The reference to be processed 816 * type = The type of the requested object (git_object_t.GIT_OBJECT_COMMIT, git_object_t.GIT_OBJECT_TAG, git_object_t.GIT_OBJECT_TREE, git_object_t.GIT_OBJECT_BLOB or git_object_t.GIT_OBJECT_ANY). 817 * 818 * Returns: 0 on success, git_error_code.GIT_EAMBIGUOUS, git_error_code.GIT_ENOTFOUND or an error code 819 */ 820 @GIT_EXTERN 821 int git_reference_peel(libgit2.types.git_object** out_, const (libgit2.types.git_reference)* ref_, libgit2.types.git_object_t type); 822 823 /** 824 * Ensure the reference name is well-formed. 825 * 826 * Valid reference names must follow one of two patterns: 827 * 828 * 1. Top-level names must contain only capital letters and underscores, 829 * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). 830 * 2. Names prefixed with "refs/" can be almost anything. You must avoid 831 * the characters '~', '^', ':', '\\', '?', '[', and '*', and the 832 * sequences ".." and "@{" which have special meaning to revparse. 833 * 834 * Params: 835 * valid = output pointer to set with validity of given reference name 836 * refname = name to be checked. 837 * 838 * Returns: 0 on success or an error code 839 */ 840 @GIT_EXTERN 841 int git_reference_name_is_valid(int* valid, const (char)* refname); 842 843 /** 844 * Get the reference's short name 845 * 846 * This will transform the reference name into a name "human-readable" 847 * version. If no shortname is appropriate, it will return the full 848 * name. 849 * 850 * The memory is owned by the reference and must not be freed. 851 * 852 * Params: 853 * ref_ = a reference 854 * 855 * Returns: the human-readable version of the name 856 */ 857 @GIT_EXTERN 858 const (char)* git_reference_shorthand(const (libgit2.types.git_reference)* ref_); 859 860 /* @} */