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