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.index; 8 9 10 private static import libgit2_d.oid; 11 private static import libgit2_d.strarray; 12 private static import libgit2_d.types; 13 private static import std.traits; 14 15 /** 16 * @file git2/index.h 17 * @brief Git index parsing and manipulation routines 18 * @defgroup git_index Git index parsing and manipulation routines 19 * @ingroup Git 20 * @{ 21 */ 22 extern (C): 23 nothrow @nogc: 24 public: 25 26 /** 27 * Time structure used in a git index entry 28 */ 29 struct git_index_time 30 { 31 int seconds; 32 33 /** 34 * nsec should not be stored as time_t compatible 35 */ 36 uint nanoseconds; 37 } 38 39 /** 40 * In-memory representation of a file entry in the index. 41 * 42 * This is a public structure that represents a file entry in the index. 43 * The meaning of the fields corresponds to core Git's documentation (in 44 * "Documentation/technical/index-format.txt"). 45 * 46 * The `flags` field consists of a number of bit fields which can be 47 * accessed via the first set of `GIT_INDEX_ENTRY_...` bitmasks below. 48 * These flags are all read from and persisted to disk. 49 * 50 * The `flags_extended` field also has a number of bit fields which can be 51 * accessed via the later `GIT_INDEX_ENTRY_...` bitmasks below. Some of 52 * these flags are read from and written to disk, but some are set aside 53 * for in-memory only reference. 54 * 55 * Note that the time and size fields are truncated to 32 bits. This 56 * is enough to detect changes, which is enough for the index to 57 * function as a cache, but it should not be taken as an authoritative 58 * source for that data. 59 */ 60 struct git_index_entry 61 { 62 .git_index_time ctime; 63 .git_index_time mtime; 64 65 uint dev; 66 uint ino; 67 uint mode; 68 uint uid; 69 uint gid; 70 uint file_size; 71 72 libgit2_d.oid.git_oid id; 73 74 ushort flags; 75 ushort flags_extended; 76 77 const (char)* path; 78 } 79 80 /** 81 * Bitmasks for on-disk fields of `git_index_entry`'s `flags` 82 * 83 * These bitmasks match the four fields in the `git_index_entry` `flags` 84 * value both in memory and on disk. You can use them to interpret the 85 * data in the `flags`. 86 */ 87 enum GIT_INDEX_ENTRY_NAMEMASK = 0x0FFF; 88 enum GIT_INDEX_ENTRY_STAGEMASK = 0x3000; 89 enum GIT_INDEX_ENTRY_STAGESHIFT = 12; 90 91 /** 92 * Flags for index entries 93 */ 94 enum git_index_entry_flag_t 95 { 96 GIT_INDEX_ENTRY_EXTENDED = 0x4000, 97 GIT_INDEX_ENTRY_VALID = 0x8000, 98 } 99 100 pragma(inline, true) 101 pure nothrow @safe @nogc 102 ushort GIT_INDEX_ENTRY_STAGE(const ref .git_index_entry E) 103 104 do 105 { 106 return (E.flags & .GIT_INDEX_ENTRY_STAGEMASK) >> .GIT_INDEX_ENTRY_STAGESHIFT; 107 } 108 109 pragma(inline, true) 110 pure nothrow @safe @nogc 111 void GIT_INDEX_ENTRY_STAGE_SET(T)(ref .git_index_entry E, T S) 112 if (std.traits.isIntegral!(T)) 113 114 do 115 { 116 E.flags = (E.flags & ~.GIT_INDEX_ENTRY_STAGEMASK) | ((S & 0x03) << .GIT_INDEX_ENTRY_STAGESHIFT); 117 } 118 119 /** 120 * Bitmasks for on-disk fields of `git_index_entry`'s `flags_extended` 121 * 122 * In memory, the `flags_extended` fields are divided into two parts: the 123 * fields that are read from and written to disk, and other fields that 124 * in-memory only and used by libgit2. Only the flags in 125 * `GIT_INDEX_ENTRY_EXTENDED_FLAGS` will get saved on-disk. 126 * 127 * Thee first three bitmasks match the three fields in the 128 * `git_index_entry` `flags_extended` value that belong on disk. You 129 * can use them to interpret the data in the `flags_extended`. 130 * 131 * The rest of the bitmasks match the other fields in the `git_index_entry` 132 * `flags_extended` value that are only used in-memory by libgit2. 133 * You can use them to interpret the data in the `flags_extended`. 134 * 135 */ 136 enum git_index_entry_extended_flag_t 137 { 138 GIT_INDEX_ENTRY_INTENT_TO_ADD = 1 << 13, 139 GIT_INDEX_ENTRY_SKIP_WORKTREE = 1 << 14, 140 141 GIT_INDEX_ENTRY_EXTENDED_FLAGS = GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE, 142 143 GIT_INDEX_ENTRY_UPTODATE = 1 << 2, 144 } 145 146 /** 147 * Capabilities of system that affect index actions. 148 */ 149 enum git_index_capability_t 150 { 151 GIT_INDEX_CAPABILITY_IGNORE_CASE = 1, 152 GIT_INDEX_CAPABILITY_NO_FILEMODE = 2, 153 GIT_INDEX_CAPABILITY_NO_SYMLINKS = 4, 154 GIT_INDEX_CAPABILITY_FROM_OWNER = -1, 155 } 156 157 /** 158 * Callback for APIs that add/remove/update files matching pathspec 159 */ 160 alias git_index_matched_path_cb = int function(const (char)* path, const (char)* matched_pathspec, void* payload); 161 162 /** 163 * Flags for APIs that add files matching pathspec 164 */ 165 enum git_index_add_option_t 166 { 167 GIT_INDEX_ADD_DEFAULT = 0, 168 GIT_INDEX_ADD_FORCE = 1u << 0, 169 GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = 1u << 1, 170 GIT_INDEX_ADD_CHECK_PATHSPEC = 1u << 2, 171 } 172 173 /** 174 * Git index stage states 175 */ 176 enum git_index_stage_t 177 { 178 /** 179 * Match any index stage. 180 * 181 * Some index APIs take a stage to match; pass this value to match 182 * any entry matching the path regardless of stage. 183 */ 184 GIT_INDEX_STAGE_ANY = -1, 185 186 /** 187 * A normal staged file in the index. 188 */ 189 GIT_INDEX_STAGE_NORMAL = 0, 190 191 /** 192 * The ancestor side of a conflict. 193 */ 194 GIT_INDEX_STAGE_ANCESTOR = 1, 195 196 /** 197 * The "ours" side of a conflict. 198 */ 199 GIT_INDEX_STAGE_OURS = 2, 200 201 /** 202 * The "theirs" side of a conflict. 203 */ 204 GIT_INDEX_STAGE_THEIRS = 3, 205 } 206 207 /** 208 * Create a new bare Git index object as a memory representation 209 * of the Git index file in 'index_path', without a repository 210 * to back it. 211 * 212 * Since there is no ODB or working directory behind this index, 213 * any Index methods which rely on these (e.g. index_add_bypath) 214 * will fail with the git_error_code.GIT_ERROR error code. 215 * 216 * If you need to access the index of an actual repository, 217 * use the `git_repository_index` wrapper. 218 * 219 * The index must be freed once it's no longer in use. 220 * 221 * Params: 222 * out_ = the pointer for the new index 223 * index_path = the path to the index file in disk 224 * 225 * Returns: 0 or an error code 226 */ 227 //GIT_EXTERN 228 int git_index_open(libgit2_d.types.git_index** out_, const (char)* index_path); 229 230 /** 231 * Create an in-memory index object. 232 * 233 * This index object cannot be read/written to the filesystem, 234 * but may be used to perform in-memory index operations. 235 * 236 * The index must be freed once it's no longer in use. 237 * 238 * Params: 239 * out_ = the pointer for the new index 240 * 241 * Returns: 0 or an error code 242 */ 243 //GIT_EXTERN 244 int git_index_new(libgit2_d.types.git_index** out_); 245 246 /** 247 * Free an existing index object. 248 * 249 * Params: 250 * index = an existing index object 251 */ 252 //GIT_EXTERN 253 void git_index_free(libgit2_d.types.git_index* index); 254 255 /** 256 * Get the repository this index relates to 257 * 258 * Params: 259 * index = The index 260 * 261 * Returns: A pointer to the repository 262 */ 263 //GIT_EXTERN 264 libgit2_d.types.git_repository* git_index_owner(const (libgit2_d.types.git_index)* index); 265 266 /** 267 * Read index capabilities flags. 268 * 269 * Params: 270 * index = An existing index object 271 * 272 * Returns: A combination of GIT_INDEX_CAPABILITY values 273 */ 274 //GIT_EXTERN 275 int git_index_caps(const (libgit2_d.types.git_index)* index); 276 277 /** 278 * Set index capabilities flags. 279 * 280 * If you pass `git_index_capability_t.GIT_INDEX_CAPABILITY_FROM_OWNER` for the caps, then 281 * capabilities will be read from the config of the owner object, 282 * looking at `core.ignorecase`, `core.filemode`, `core.symlinks`. 283 * 284 * Params: 285 * index = An existing index object 286 * caps = A combination of GIT_INDEX_CAPABILITY values 287 * 288 * Returns: 0 on success, -1 on failure 289 */ 290 //GIT_EXTERN 291 int git_index_set_caps(libgit2_d.types.git_index* index, int caps); 292 293 /** 294 * Get index on-disk version. 295 * 296 * Valid return values are 2, 3, or 4. If 3 is returned, an index 297 * with version 2 may be written instead, if the extension data in 298 * version 3 is not necessary. 299 * 300 * Params: 301 * index = An existing index object 302 * 303 * Returns: the index version 304 */ 305 //GIT_EXTERN 306 uint git_index_version(libgit2_d.types.git_index* index); 307 308 /** 309 * Set index on-disk version. 310 * 311 * Valid values are 2, 3, or 4. If 2 is given, git_index_write may 312 * write an index with version 3 instead, if necessary to accurately 313 * represent the index. 314 * 315 * Params: 316 * index = An existing index object 317 * version_ = The new version number 318 * 319 * Returns: 0 on success, -1 on failure 320 */ 321 //GIT_EXTERN 322 int git_index_set_version(libgit2_d.types.git_index* index, uint version_); 323 324 /** 325 * Update the contents of an existing index object in memory by reading 326 * from the hard disk. 327 * 328 * If `force` is true, this performs a "hard" read that discards in-memory 329 * changes and always reloads the on-disk index data. If there is no 330 * on-disk version, the index will be cleared. 331 * 332 * If `force` is false, this does a "soft" read that reloads the index 333 * data from disk only if it has changed since the last time it was 334 * loaded. Purely in-memory index data will be untouched. Be aware: if 335 * there are changes on disk, unwritten in-memory changes are discarded. 336 * 337 * Params: 338 * index = an existing index object 339 * force = if true, always reload, vs. only read if file has changed 340 * 341 * Returns: 0 or an error code 342 */ 343 //GIT_EXTERN 344 int git_index_read(libgit2_d.types.git_index* index, int force); 345 346 /** 347 * Write an existing index object from memory back to disk 348 * using an atomic file lock. 349 * 350 * Params: 351 * index = an existing index object 352 * 353 * Returns: 0 or an error code 354 */ 355 //GIT_EXTERN 356 int git_index_write(libgit2_d.types.git_index* index); 357 358 /** 359 * Get the full path to the index file on disk. 360 * 361 * Params: 362 * index = an existing index object 363 * 364 * Returns: path to index file or null for in-memory index 365 */ 366 //GIT_EXTERN 367 const (char)* git_index_path(const (libgit2_d.types.git_index)* index); 368 369 /** 370 * Get the checksum of the index 371 * 372 * This checksum is the SHA-1 hash over the index file (except the 373 * last 20 bytes which are the checksum itself). In cases where the 374 * index does not exist on-disk, it will be zeroed out. 375 * 376 * Params: 377 * index = an existing index object 378 * 379 * Returns: a pointer to the checksum of the index 380 */ 381 //GIT_EXTERN 382 const (libgit2_d.oid.git_oid)* git_index_checksum(libgit2_d.types.git_index* index); 383 384 /** 385 * Read a tree into the index file with stats 386 * 387 * The current index contents will be replaced by the specified tree. 388 * 389 * Params: 390 * index = an existing index object 391 * tree = tree to read 392 * 393 * Returns: 0 or an error code 394 */ 395 //GIT_EXTERN 396 int git_index_read_tree(libgit2_d.types.git_index* index, const (libgit2_d.types.git_tree)* tree); 397 398 /** 399 * Write the index as a tree 400 * 401 * This method will scan the index and write a representation 402 * of its current state back to disk; it recursively creates 403 * tree objects for each of the subtrees stored in the index, 404 * but only returns the OID of the root tree. This is the OID 405 * that can be used e.g. to create a commit. 406 * 407 * The index instance cannot be bare, and needs to be associated 408 * to an existing repository. 409 * 410 * The index must not contain any file in conflict. 411 * 412 * Params: 413 * out_ = Pointer where to store the OID of the written tree 414 * index = Index to write 415 * 416 * Returns: 0 on success, git_error_code.GIT_EUNMERGED when the index is not clean or an error code 417 */ 418 //GIT_EXTERN 419 int git_index_write_tree(libgit2_d.oid.git_oid* out_, libgit2_d.types.git_index* index); 420 421 /** 422 * Write the index as a tree to the given repository 423 * 424 * This method will do the same as `git_index_write_tree`, but 425 * letting the user choose the repository where the tree will 426 * be written. 427 * 428 * The index must not contain any file in conflict. 429 * 430 * Params: 431 * out_ = Pointer where to store OID of the the written tree 432 * index = Index to write 433 * repo = Repository where to write the tree 434 * 435 * Returns: 0 on success, git_error_code.GIT_EUNMERGED when the index is not clean or an error code 436 */ 437 //GIT_EXTERN 438 int git_index_write_tree_to(libgit2_d.oid.git_oid* out_, libgit2_d.types.git_index* index, libgit2_d.types.git_repository* repo); 439 440 /**@}*/ 441 442 /** 443 * @name Raw Index Entry Functions 444 * 445 * These functions work on index entries, and allow for raw manipulation 446 * of the entries. 447 */ 448 /**@{*/ 449 450 /* Index entry manipulation */ 451 452 /** 453 * Get the count of entries currently in the index 454 * 455 * Params: 456 * index = an existing index object 457 * 458 * Returns: integer of count of current entries 459 */ 460 //GIT_EXTERN 461 size_t git_index_entrycount(const (libgit2_d.types.git_index)* index); 462 463 /** 464 * Clear the contents (all the entries) of an index object. 465 * 466 * This clears the index object in memory; changes must be explicitly 467 * written to disk for them to take effect persistently. 468 * 469 * Params: 470 * index = an existing index object 471 * 472 * Returns: 0 on success, error code < 0 on failure 473 */ 474 //GIT_EXTERN 475 int git_index_clear(libgit2_d.types.git_index* index); 476 477 /** 478 * Get a pointer to one of the entries in the index 479 * 480 * The entry is not modifiable and should not be freed. Because the 481 * `git_index_entry` struct is a publicly defined struct, you should 482 * be able to make your own permanent copy of the data if necessary. 483 * 484 * Params: 485 * index = an existing index object 486 * n = the position of the entry 487 * 488 * Returns: a pointer to the entry; null if out of bounds 489 */ 490 //GIT_EXTERN 491 const (.git_index_entry)* git_index_get_byindex(libgit2_d.types.git_index* index, size_t n); 492 493 /** 494 * Get a pointer to one of the entries in the index 495 * 496 * The entry is not modifiable and should not be freed. Because the 497 * `git_index_entry` struct is a publicly defined struct, you should 498 * be able to make your own permanent copy of the data if necessary. 499 * 500 * Params: 501 * index = an existing index object 502 * path = path to search 503 * stage = stage to search 504 * 505 * Returns: a pointer to the entry; null if it was not found 506 */ 507 //GIT_EXTERN 508 const (.git_index_entry)* git_index_get_bypath(libgit2_d.types.git_index* index, const (char)* path, int stage); 509 510 /** 511 * Remove an entry from the index 512 * 513 * Params: 514 * index = an existing index object 515 * path = path to search 516 * stage = stage to search 517 * 518 * Returns: 0 or an error code 519 */ 520 //GIT_EXTERN 521 int git_index_remove(libgit2_d.types.git_index* index, const (char)* path, int stage); 522 523 /** 524 * Remove all entries from the index under a given directory 525 * 526 * Params: 527 * index = an existing index object 528 * dir = container directory path 529 * stage = stage to search 530 * 531 * Returns: 0 or an error code 532 */ 533 //GIT_EXTERN 534 int git_index_remove_directory(libgit2_d.types.git_index* index, const (char)* dir, int stage); 535 536 /** 537 * Add or update an index entry from an in-memory struct 538 * 539 * If a previous index entry exists that has the same path and stage 540 * as the given 'source_entry', it will be replaced. Otherwise, the 541 * 'source_entry' will be added. 542 * 543 * A full copy (including the 'path' string) of the given 544 * 'source_entry' will be inserted on the index. 545 * 546 * Params: 547 * index = an existing index object 548 * source_entry = new entry object 549 * 550 * Returns: 0 or an error code 551 */ 552 //GIT_EXTERN 553 int git_index_add(libgit2_d.types.git_index* index, const (.git_index_entry)* source_entry); 554 555 /** 556 * Return the stage number from a git index entry 557 * 558 * This entry is calculated from the entry's flag attribute like this: 559 * 560 * (entry->flags & GIT_INDEX_ENTRY_STAGEMASK) >> GIT_INDEX_ENTRY_STAGESHIFT 561 * 562 * Params: 563 * entry = The entry 564 * 565 * Returns: the stage number 566 */ 567 //GIT_EXTERN 568 int git_index_entry_stage(const (.git_index_entry)* entry); 569 570 /** 571 * Return whether the given index entry is a conflict (has a high stage 572 * entry). This is simply shorthand for `git_index_entry_stage > 0`. 573 * 574 * Params: 575 * entry = The entry 576 * 577 * Returns: 1 if the entry is a conflict entry, 0 otherwise 578 */ 579 //GIT_EXTERN 580 int git_index_entry_is_conflict(const (.git_index_entry)* entry); 581 582 /**@}*/ 583 584 /** @name Index Entry Iteration Functions 585 * 586 * These functions provide an iterator for index entries. 587 */ 588 /**@{*/ 589 590 /** 591 * Create an iterator that will return every entry contained in the 592 * index at the time of creation. Entries are returned in order, 593 * sorted by path. This iterator is backed by a snapshot that allows 594 * callers to modify the index while iterating without affecting the 595 * iterator. 596 * 597 * Params: 598 * iterator_out = The newly created iterator 599 * index = The index to iterate 600 */ 601 //GIT_EXTERN 602 int git_index_iterator_new(libgit2_d.types.git_index_iterator** iterator_out, libgit2_d.types.git_index* index); 603 604 /** 605 * Return the next index entry in-order from the iterator. 606 * 607 * Params: 608 * out_ = Pointer to store the index entry in 609 * iterator = The iterator 610 * 611 * Returns: 0, git_error_code.GIT_ITEROVER on iteration completion or an error code 612 */ 613 //GIT_EXTERN 614 int git_index_iterator_next(const (.git_index_entry)** out_, libgit2_d.types.git_index_iterator* iterator); 615 616 /** 617 * Free the index iterator 618 * 619 * Params: 620 * iterator = The iterator to free 621 */ 622 //GIT_EXTERN 623 void git_index_iterator_free(libgit2_d.types.git_index_iterator* iterator); 624 625 /**@}*/ 626 627 /** 628 * @name Workdir Index Entry Functions 629 * 630 * These functions work on index entries specifically in the working 631 * directory (ie, stage 0). 632 */ 633 /**@{*/ 634 635 /** 636 * Add or update an index entry from a file on disk 637 * 638 * The file `path` must be relative to the repository's 639 * working folder and must be readable. 640 * 641 * This method will fail in bare index instances. 642 * 643 * This forces the file to be added to the index, not looking 644 * at gitignore rules. Those rules can be evaluated through 645 * the git_status APIs (in status.h) before calling this. 646 * 647 * If this file currently is the result of a merge conflict, this 648 * file will no longer be marked as conflicting. The data about 649 * the conflict will be moved to the "resolve undo" (REUC) section. 650 * 651 * Params: 652 * index = an existing index object 653 * path = filename to add 654 * 655 * Returns: 0 or an error code 656 */ 657 //GIT_EXTERN 658 int git_index_add_bypath(libgit2_d.types.git_index* index, const (char)* path); 659 660 /** 661 * Add or update an index entry from a buffer in memory 662 * 663 * This method will create a blob in the repository that owns the 664 * index and then add the index entry to the index. The `path` of the 665 * entry represents the position of the blob relative to the 666 * repository's root folder. 667 * 668 * If a previous index entry exists that has the same path as the 669 * given 'entry', it will be replaced. Otherwise, the 'entry' will be 670 * added. The `id` and the `file_size` of the 'entry' are updated with the 671 * real value of the blob. 672 * 673 * This forces the file to be added to the index, not looking 674 * at gitignore rules. Those rules can be evaluated through 675 * the git_status APIs (in status.h) before calling this. 676 * 677 * If this file currently is the result of a merge conflict, this 678 * file will no longer be marked as conflicting. The data about 679 * the conflict will be moved to the "resolve undo" (REUC) section. 680 * 681 * Params: 682 * index = an existing index object 683 * entry = filename to add 684 * buffer = data to be written into the blob 685 * len = length of the data 686 * 687 * Returns: 0 or an error code 688 */ 689 //GIT_EXTERN 690 int git_index_add_from_buffer(libgit2_d.types.git_index* index, const (.git_index_entry)* entry, const (void)* buffer, size_t len); 691 692 /** 693 * Remove an index entry corresponding to a file on disk 694 * 695 * The file `path` must be relative to the repository's 696 * working folder. It may exist. 697 * 698 * If this file currently is the result of a merge conflict, this 699 * file will no longer be marked as conflicting. The data about 700 * the conflict will be moved to the "resolve undo" (REUC) section. 701 * 702 * Params: 703 * index = an existing index object 704 * path = filename to remove 705 * 706 * Returns: 0 or an error code 707 */ 708 //GIT_EXTERN 709 int git_index_remove_bypath(libgit2_d.types.git_index* index, const (char)* path); 710 711 /** 712 * Add or update index entries matching files in the working directory. 713 * 714 * This method will fail in bare index instances. 715 * 716 * The `pathspec` is a list of file names or shell glob patterns that will 717 * be matched against files in the repository's working directory. Each 718 * file that matches will be added to the index (either updating an 719 * existing entry or adding a new entry). You can disable glob expansion 720 * and force exact matching with the `git_index_add_option_t.GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH` 721 * flag. 722 * 723 * Files that are ignored will be skipped (unlike `git_index_add_bypath`). 724 * If a file is already tracked in the index, then it *will* be updated 725 * even if it is ignored. Pass the `git_index_add_option_t.GIT_INDEX_ADD_FORCE` flag to skip 726 * the checking of ignore rules. 727 * 728 * To emulate `git add -A` and generate an error if the pathspec contains 729 * the exact path of an ignored file (when not using FORCE), add the 730 * `git_index_add_option_t.GIT_INDEX_ADD_CHECK_PATHSPEC` flag. This checks that each entry 731 * in the `pathspec` that is an exact match to a filename on disk is 732 * either not ignored or already in the index. If this check fails, the 733 * function will return git_error_code.GIT_EINVALIDSPEC. 734 * 735 * To emulate `git add -A` with the "dry-run" option, just use a callback 736 * function that always returns a positive value. See below for details. 737 * 738 * If any files are currently the result of a merge conflict, those files 739 * will no longer be marked as conflicting. The data about the conflicts 740 * will be moved to the "resolve undo" (REUC) section. 741 * 742 * If you provide a callback function, it will be invoked on each matching 743 * item in the working directory immediately *before* it is added to / 744 * updated in the index. Returning zero will add the item to the index, 745 * greater than zero will skip the item, and less than zero will abort the 746 * scan and return that value to the caller. 747 * 748 * Params: 749 * index = an existing index object 750 * pathspec = array of path patterns 751 * flags = combination of git_index_add_option_t flags 752 * callback = notification callback for each added/updated path (also gets index of matching pathspec entry); can be null; return 0 to add, >0 to skip, <0 to abort scan. 753 * payload = payload passed through to callback function 754 * 755 * Returns: 0 on success, negative callback return value, or error code 756 */ 757 //GIT_EXTERN 758 int git_index_add_all(libgit2_d.types.git_index* index, const (libgit2_d.strarray.git_strarray)* pathspec, uint flags, .git_index_matched_path_cb callback, void* payload); 759 760 /** 761 * Remove all matching index entries. 762 * 763 * If you provide a callback function, it will be invoked on each matching 764 * item in the index immediately *before* it is removed. Return 0 to 765 * remove the item, > 0 to skip the item, and < 0 to abort the scan. 766 * 767 * Params: 768 * index = An existing index object 769 * pathspec = array of path patterns 770 * callback = notification callback for each removed path (also gets index of matching pathspec entry); can be null; return 0 to add, >0 to skip, <0 to abort scan. 771 * payload = payload passed through to callback function 772 * 773 * Returns: 0 on success, negative callback return value, or error code 774 */ 775 //GIT_EXTERN 776 int git_index_remove_all(libgit2_d.types.git_index* index, const (libgit2_d.strarray.git_strarray)* pathspec, .git_index_matched_path_cb callback, void* payload); 777 778 /** 779 * Update all index entries to match the working directory 780 * 781 * This method will fail in bare index instances. 782 * 783 * This scans the existing index entries and synchronizes them with the 784 * working directory, deleting them if the corresponding working directory 785 * file no longer exists otherwise updating the information (including 786 * adding the latest version of file to the ODB if needed). 787 * 788 * If you provide a callback function, it will be invoked on each matching 789 * item in the index immediately *before* it is updated (either refreshed 790 * or removed depending on working directory state). Return 0 to proceed 791 * with updating the item, > 0 to skip the item, and < 0 to abort the scan. 792 * 793 * Params: 794 * index = An existing index object 795 * pathspec = array of path patterns 796 * callback = notification callback for each updated path (also gets index of matching pathspec entry); can be null; return 0 to add, >0 to skip, <0 to abort scan. 797 * payload = payload passed through to callback function 798 * 799 * Returns: 0 on success, negative callback return value, or error code 800 */ 801 //GIT_EXTERN 802 int git_index_update_all(libgit2_d.types.git_index* index, const (libgit2_d.strarray.git_strarray)* pathspec, .git_index_matched_path_cb callback, void* payload); 803 804 /** 805 * Find the first position of any entries which point to given 806 * path in the Git index. 807 * 808 * Params: 809 * at_pos = the address to which the position of the index entry is written (optional) 810 * index = an existing index object 811 * path = path to search 812 * 813 * Returns: a zero-based position in the index if found; git_error_code.GIT_ENOTFOUND otherwise 814 */ 815 //GIT_EXTERN 816 int git_index_find(size_t* at_pos, libgit2_d.types.git_index* index, const (char)* path); 817 818 /** 819 * Find the first position of any entries matching a prefix. To find the first 820 * position of a path inside a given folder, suffix the prefix with a '/'. 821 * 822 * Params: 823 * at_pos = the address to which the position of the index entry is written (optional) 824 * index = an existing index object 825 * prefix = the prefix to search for 826 * 827 * Returns: 0 with valid value in at_pos; an error code otherwise 828 */ 829 //GIT_EXTERN 830 int git_index_find_prefix(size_t* at_pos, libgit2_d.types.git_index* index, const (char)* prefix); 831 832 /**@}*/ 833 834 /** 835 * @name Conflict Index Entry Functions 836 * 837 * These functions work on conflict index entries specifically (ie, stages 1-3) 838 */ 839 /**@{*/ 840 841 /** 842 * Add or update index entries to represent a conflict. Any staged 843 * entries that exist at the given paths will be removed. 844 * 845 * The entries are the entries from the tree included in the merge. Any 846 * entry may be null to indicate that that file was not present in the 847 * trees during the merge. For example, ancestor_entry may be null to 848 * indicate that a file was added in both branches and must be resolved. 849 * 850 * Params: 851 * index = an existing index object 852 * ancestor_entry = the entry data for the ancestor of the conflict 853 * our_entry = the entry data for our side of the merge conflict 854 * their_entry = the entry data for their side of the merge conflict 855 * 856 * Returns: 0 or an error code 857 */ 858 //GIT_EXTERN 859 int git_index_conflict_add(libgit2_d.types.git_index* index, const (.git_index_entry)* ancestor_entry, const (.git_index_entry)* our_entry, const (.git_index_entry)* their_entry); 860 861 /** 862 * Get the index entries that represent a conflict of a single file. 863 * 864 * The entries are not modifiable and should not be freed. Because the 865 * `git_index_entry` struct is a publicly defined struct, you should 866 * be able to make your own permanent copy of the data if necessary. 867 * 868 * Params: 869 * ancestor_out = Pointer to store the ancestor entry 870 * our_out = Pointer to store the our entry 871 * their_out = Pointer to store the their entry 872 * index = an existing index object 873 * path = path to search 874 * 875 * Returns: 0 or an error code 876 */ 877 //GIT_EXTERN 878 int git_index_conflict_get(const (.git_index_entry)** ancestor_out, const (.git_index_entry)** our_out, const (.git_index_entry)** their_out, libgit2_d.types.git_index* index, const (char)* path); 879 880 /** 881 * Removes the index entries that represent a conflict of a single file. 882 * 883 * Params: 884 * index = an existing index object 885 * path = path to remove conflicts for 886 * 887 * Returns: 0 or an error code 888 */ 889 //GIT_EXTERN 890 int git_index_conflict_remove(libgit2_d.types.git_index* index, const (char)* path); 891 892 /** 893 * Remove all conflicts in the index (entries with a stage greater than 0). 894 * 895 * Params: 896 * index = an existing index object 897 * 898 * Returns: 0 or an error code 899 */ 900 //GIT_EXTERN 901 int git_index_conflict_cleanup(libgit2_d.types.git_index* index); 902 903 /** 904 * Determine if the index contains entries representing file conflicts. 905 * 906 * Returns: 1 if at least one conflict is found, 0 otherwise. 907 */ 908 //GIT_EXTERN 909 int git_index_has_conflicts(const (libgit2_d.types.git_index)* index); 910 911 /** 912 * Create an iterator for the conflicts in the index. 913 * 914 * The index must not be modified while iterating; the results are undefined. 915 * 916 * Params: 917 * iterator_out = The newly created conflict iterator 918 * index = The index to scan 919 * 920 * Returns: 0 or an error code 921 */ 922 //GIT_EXTERN 923 int git_index_conflict_iterator_new(libgit2_d.types.git_index_conflict_iterator** iterator_out, libgit2_d.types.git_index* index); 924 925 /** 926 * Returns the current conflict (ancestor, ours and theirs entry) and 927 * advance the iterator internally to the next value. 928 * 929 * Params: 930 * ancestor_out = Pointer to store the ancestor side of the conflict 931 * our_out = Pointer to store our side of the conflict 932 * their_out = Pointer to store their side of the conflict 933 * 934 * Returns: 0 (no error), git_error_code.GIT_ITEROVER (iteration is done) or an error code (negative value) 935 */ 936 //GIT_EXTERN 937 int git_index_conflict_next(const (.git_index_entry)** ancestor_out, const (.git_index_entry)** our_out, const (.git_index_entry)** their_out, libgit2_d.types.git_index_conflict_iterator* iterator); 938 939 /** 940 * Frees a `git_index_conflict_iterator`. 941 * 942 * Params: 943 * iterator = pointer to the iterator 944 */ 945 //GIT_EXTERN 946 void git_index_conflict_iterator_free(libgit2_d.types.git_index_conflict_iterator* iterator); 947 948 /** @} */