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 * @param out_ the pointer for the new index 222 * @param index_path the path to the index file in disk 223 * @return 0 or an error code 224 */ 225 //GIT_EXTERN 226 int git_index_open(libgit2_d.types.git_index** out_, const (char)* index_path); 227 228 /** 229 * Create an in-memory index object. 230 * 231 * This index object cannot be read/written to the filesystem, 232 * but may be used to perform in-memory index operations. 233 * 234 * The index must be freed once it's no longer in use. 235 * 236 * @param out_ the pointer for the new index 237 * @return 0 or an error code 238 */ 239 //GIT_EXTERN 240 int git_index_new(libgit2_d.types.git_index** out_); 241 242 /** 243 * Free an existing index object. 244 * 245 * @param index an existing index object 246 */ 247 //GIT_EXTERN 248 void git_index_free(libgit2_d.types.git_index* index); 249 250 /** 251 * Get the repository this index relates to 252 * 253 * @param index The index 254 * @return A pointer to the repository 255 */ 256 //GIT_EXTERN 257 libgit2_d.types.git_repository* git_index_owner(const (libgit2_d.types.git_index)* index); 258 259 /** 260 * Read index capabilities flags. 261 * 262 * @param index An existing index object 263 * @return A combination of GIT_INDEX_CAPABILITY values 264 */ 265 //GIT_EXTERN 266 int git_index_caps(const (libgit2_d.types.git_index)* index); 267 268 /** 269 * Set index capabilities flags. 270 * 271 * If you pass `git_index_capability_t.GIT_INDEX_CAPABILITY_FROM_OWNER` for the caps, then 272 * capabilities will be read from the config of the owner object, 273 * looking at `core.ignorecase`, `core.filemode`, `core.symlinks`. 274 * 275 * @param index An existing index object 276 * @param caps A combination of GIT_INDEX_CAPABILITY values 277 * @return 0 on success, -1 on failure 278 */ 279 //GIT_EXTERN 280 int git_index_set_caps(libgit2_d.types.git_index* index, int caps); 281 282 /** 283 * Get index on-disk version. 284 * 285 * Valid return values are 2, 3, or 4. If 3 is returned, an index 286 * with version 2 may be written instead, if the extension data in 287 * version 3 is not necessary. 288 * 289 * @param index An existing index object 290 * @return the index version 291 */ 292 //GIT_EXTERN 293 uint git_index_version(libgit2_d.types.git_index* index); 294 295 /** 296 * Set index on-disk version. 297 * 298 * Valid values are 2, 3, or 4. If 2 is given, git_index_write may 299 * write an index with version 3 instead, if necessary to accurately 300 * represent the index. 301 * 302 * @param index An existing index object 303 * @param version_ The new version number 304 * @return 0 on success, -1 on failure 305 */ 306 //GIT_EXTERN 307 int git_index_set_version(libgit2_d.types.git_index* index, uint version_); 308 309 /** 310 * Update the contents of an existing index object in memory by reading 311 * from the hard disk. 312 * 313 * If `force` is true, this performs a "hard" read that discards in-memory 314 * changes and always reloads the on-disk index data. If there is no 315 * on-disk version, the index will be cleared. 316 * 317 * If `force` is false, this does a "soft" read that reloads the index 318 * data from disk only if it has changed since the last time it was 319 * loaded. Purely in-memory index data will be untouched. Be aware: if 320 * there are changes on disk, unwritten in-memory changes are discarded. 321 * 322 * @param index an existing index object 323 * @param force if true, always reload, vs. only read if file has changed 324 * @return 0 or an error code 325 */ 326 //GIT_EXTERN 327 int git_index_read(libgit2_d.types.git_index* index, int force); 328 329 /** 330 * Write an existing index object from memory back to disk 331 * using an atomic file lock. 332 * 333 * @param index an existing index object 334 * @return 0 or an error code 335 */ 336 //GIT_EXTERN 337 int git_index_write(libgit2_d.types.git_index* index); 338 339 /** 340 * Get the full path to the index file on disk. 341 * 342 * @param index an existing index object 343 * @return path to index file or null for in-memory index 344 */ 345 //GIT_EXTERN 346 const (char)* git_index_path(const (libgit2_d.types.git_index)* index); 347 348 /** 349 * Get the checksum of the index 350 * 351 * This checksum is the SHA-1 hash over the index file (except the 352 * last 20 bytes which are the checksum itself). In cases where the 353 * index does not exist on-disk, it will be zeroed out. 354 * 355 * @param index an existing index object 356 * @return a pointer to the checksum of the index 357 */ 358 //GIT_EXTERN 359 const (libgit2_d.oid.git_oid)* git_index_checksum(libgit2_d.types.git_index* index); 360 361 /** 362 * Read a tree into the index file with stats 363 * 364 * The current index contents will be replaced by the specified tree. 365 * 366 * @param index an existing index object 367 * @param tree tree to read 368 * @return 0 or an error code 369 */ 370 //GIT_EXTERN 371 int git_index_read_tree(libgit2_d.types.git_index* index, const (libgit2_d.types.git_tree)* tree); 372 373 /** 374 * Write the index as a tree 375 * 376 * This method will scan the index and write a representation 377 * of its current state back to disk; it recursively creates 378 * tree objects for each of the subtrees stored in the index, 379 * but only returns the OID of the root tree. This is the OID 380 * that can be used e.g. to create a commit. 381 * 382 * The index instance cannot be bare, and needs to be associated 383 * to an existing repository. 384 * 385 * The index must not contain any file in conflict. 386 * 387 * @param out_ Pointer where to store the OID of the written tree 388 * @param index Index to write 389 * @return 0 on success, git_error_code.GIT_EUNMERGED when the index is not clean 390 * or an error code 391 */ 392 //GIT_EXTERN 393 int git_index_write_tree(libgit2_d.oid.git_oid* out_, libgit2_d.types.git_index* index); 394 395 /** 396 * Write the index as a tree to the given repository 397 * 398 * This method will do the same as `git_index_write_tree`, but 399 * letting the user choose the repository where the tree will 400 * be written. 401 * 402 * The index must not contain any file in conflict. 403 * 404 * @param out_ Pointer where to store OID of the the written tree 405 * @param index Index to write 406 * @param repo Repository where to write the tree 407 * @return 0 on success, git_error_code.GIT_EUNMERGED when the index is not clean 408 * or an error code 409 */ 410 //GIT_EXTERN 411 int git_index_write_tree_to(libgit2_d.oid.git_oid* out_, libgit2_d.types.git_index* index, libgit2_d.types.git_repository* repo); 412 413 /**@}*/ 414 415 /** 416 * @name Raw Index Entry Functions 417 * 418 * These functions work on index entries, and allow for raw manipulation 419 * of the entries. 420 */ 421 /**@{*/ 422 423 /* Index entry manipulation */ 424 425 /** 426 * Get the count of entries currently in the index 427 * 428 * @param index an existing index object 429 * @return integer of count of current entries 430 */ 431 //GIT_EXTERN 432 size_t git_index_entrycount(const (libgit2_d.types.git_index)* index); 433 434 /** 435 * Clear the contents (all the entries) of an index object. 436 * 437 * This clears the index object in memory; changes must be explicitly 438 * written to disk for them to take effect persistently. 439 * 440 * @param index an existing index object 441 * @return 0 on success, error code < 0 on failure 442 */ 443 //GIT_EXTERN 444 int git_index_clear(libgit2_d.types.git_index* index); 445 446 /** 447 * Get a pointer to one of the entries in the index 448 * 449 * The entry is not modifiable and should not be freed. Because the 450 * `git_index_entry` struct is a publicly defined struct, you should 451 * be able to make your own permanent copy of the data if necessary. 452 * 453 * @param index an existing index object 454 * @param n the position of the entry 455 * @return a pointer to the entry; null if out of bounds 456 */ 457 //GIT_EXTERN 458 const (.git_index_entry)* git_index_get_byindex(libgit2_d.types.git_index* index, size_t n); 459 460 /** 461 * Get a pointer to one of the entries in the index 462 * 463 * The entry is not modifiable and should not be freed. Because the 464 * `git_index_entry` struct is a publicly defined struct, you should 465 * be able to make your own permanent copy of the data if necessary. 466 * 467 * @param index an existing index object 468 * @param path path to search 469 * @param stage stage to search 470 * @return a pointer to the entry; null if it was not found 471 */ 472 //GIT_EXTERN 473 const (.git_index_entry)* git_index_get_bypath(libgit2_d.types.git_index* index, const (char)* path, int stage); 474 475 /** 476 * Remove an entry from the index 477 * 478 * @param index an existing index object 479 * @param path path to search 480 * @param stage stage to search 481 * @return 0 or an error code 482 */ 483 //GIT_EXTERN 484 int git_index_remove(libgit2_d.types.git_index* index, const (char)* path, int stage); 485 486 /** 487 * Remove all entries from the index under a given directory 488 * 489 * @param index an existing index object 490 * @param dir container directory path 491 * @param stage stage to search 492 * @return 0 or an error code 493 */ 494 //GIT_EXTERN 495 int git_index_remove_directory(libgit2_d.types.git_index* index, const (char)* dir, int stage); 496 497 /** 498 * Add or update an index entry from an in-memory struct 499 * 500 * If a previous index entry exists that has the same path and stage 501 * as the given 'source_entry', it will be replaced. Otherwise, the 502 * 'source_entry' will be added. 503 * 504 * A full copy (including the 'path' string) of the given 505 * 'source_entry' will be inserted on the index. 506 * 507 * @param index an existing index object 508 * @param source_entry new entry object 509 * @return 0 or an error code 510 */ 511 //GIT_EXTERN 512 int git_index_add(libgit2_d.types.git_index* index, const (.git_index_entry)* source_entry); 513 514 /** 515 * Return the stage number from a git index entry 516 * 517 * This entry is calculated from the entry's flag attribute like this: 518 * 519 * (entry->flags & GIT_INDEX_ENTRY_STAGEMASK) >> GIT_INDEX_ENTRY_STAGESHIFT 520 * 521 * @param entry The entry 522 * @return the stage number 523 */ 524 //GIT_EXTERN 525 int git_index_entry_stage(const (.git_index_entry)* entry); 526 527 /** 528 * Return whether the given index entry is a conflict (has a high stage 529 * entry). This is simply shorthand for `git_index_entry_stage > 0`. 530 * 531 * @param entry The entry 532 * @return 1 if the entry is a conflict entry, 0 otherwise 533 */ 534 //GIT_EXTERN 535 int git_index_entry_is_conflict(const (.git_index_entry)* entry); 536 537 /**@}*/ 538 539 /** @name Index Entry Iteration Functions 540 * 541 * These functions provide an iterator for index entries. 542 */ 543 /**@{*/ 544 545 /** 546 * Create an iterator that will return every entry contained in the 547 * index at the time of creation. Entries are returned in order, 548 * sorted by path. This iterator is backed by a snapshot that allows 549 * callers to modify the index while iterating without affecting the 550 * iterator. 551 * 552 * @param iterator_out The newly created iterator 553 * @param index The index to iterate 554 */ 555 //GIT_EXTERN 556 int git_index_iterator_new(libgit2_d.types.git_index_iterator** iterator_out, libgit2_d.types.git_index* index); 557 558 /** 559 * Return the next index entry in-order from the iterator. 560 * 561 * @param out_ Pointer to store the index entry in 562 * @param iterator The iterator 563 * @return 0, git_error_code.GIT_ITEROVER on iteration completion or an error code 564 */ 565 //GIT_EXTERN 566 int git_index_iterator_next(const (.git_index_entry)** out_, libgit2_d.types.git_index_iterator* iterator); 567 568 /** 569 * Free the index iterator 570 * 571 * @param iterator The iterator to free 572 */ 573 //GIT_EXTERN 574 void git_index_iterator_free(libgit2_d.types.git_index_iterator* iterator); 575 576 /**@}*/ 577 578 /** 579 * @name Workdir Index Entry Functions 580 * 581 * These functions work on index entries specifically in the working 582 * directory (ie, stage 0). 583 */ 584 /**@{*/ 585 586 /** 587 * Add or update an index entry from a file on disk 588 * 589 * The file `path` must be relative to the repository's 590 * working folder and must be readable. 591 * 592 * This method will fail in bare index instances. 593 * 594 * This forces the file to be added to the index, not looking 595 * at gitignore rules. Those rules can be evaluated through 596 * the git_status APIs (in status.h) before calling this. 597 * 598 * If this file currently is the result of a merge conflict, this 599 * file will no longer be marked as conflicting. The data about 600 * the conflict will be moved to the "resolve undo" (REUC) section. 601 * 602 * @param index an existing index object 603 * @param path filename to add 604 * @return 0 or an error code 605 */ 606 //GIT_EXTERN 607 int git_index_add_bypath(libgit2_d.types.git_index* index, const (char)* path); 608 609 /** 610 * Add or update an index entry from a buffer in memory 611 * 612 * This method will create a blob in the repository that owns the 613 * index and then add the index entry to the index. The `path` of the 614 * entry represents the position of the blob relative to the 615 * repository's root folder. 616 * 617 * If a previous index entry exists that has the same path as the 618 * given 'entry', it will be replaced. Otherwise, the 'entry' will be 619 * added. The `id` and the `file_size` of the 'entry' are updated with the 620 * real value of the blob. 621 * 622 * This forces the file to be added to the index, not looking 623 * at gitignore rules. Those rules can be evaluated through 624 * the git_status APIs (in status.h) before calling this. 625 * 626 * If this file currently is the result of a merge conflict, this 627 * file will no longer be marked as conflicting. The data about 628 * the conflict will be moved to the "resolve undo" (REUC) section. 629 * 630 * @param index an existing index object 631 * @param entry filename to add 632 * @param buffer data to be written into the blob 633 * @param len length of the data 634 * @return 0 or an error code 635 */ 636 //GIT_EXTERN 637 int git_index_add_from_buffer(libgit2_d.types.git_index* index, const (.git_index_entry)* entry, const (void)* buffer, size_t len); 638 639 /** 640 * Remove an index entry corresponding to a file on disk 641 * 642 * The file `path` must be relative to the repository's 643 * working folder. It may exist. 644 * 645 * If this file currently is the result of a merge conflict, this 646 * file will no longer be marked as conflicting. The data about 647 * the conflict will be moved to the "resolve undo" (REUC) section. 648 * 649 * @param index an existing index object 650 * @param path filename to remove 651 * @return 0 or an error code 652 */ 653 //GIT_EXTERN 654 int git_index_remove_bypath(libgit2_d.types.git_index* index, const (char)* path); 655 656 /** 657 * Add or update index entries matching files in the working directory. 658 * 659 * This method will fail in bare index instances. 660 * 661 * The `pathspec` is a list of file names or shell glob patterns that will 662 * be matched against files in the repository's working directory. Each 663 * file that matches will be added to the index (either updating an 664 * existing entry or adding a new entry). You can disable glob expansion 665 * and force exact matching with the `git_index_add_option_t.GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH` 666 * flag. 667 * 668 * Files that are ignored will be skipped (unlike `git_index_add_bypath`). 669 * If a file is already tracked in the index, then it *will* be updated 670 * even if it is ignored. Pass the `git_index_add_option_t.GIT_INDEX_ADD_FORCE` flag to skip 671 * the checking of ignore rules. 672 * 673 * To emulate `git add -A` and generate an error if the pathspec contains 674 * the exact path of an ignored file (when not using FORCE), add the 675 * `git_index_add_option_t.GIT_INDEX_ADD_CHECK_PATHSPEC` flag. This checks that each entry 676 * in the `pathspec` that is an exact match to a filename on disk is 677 * either not ignored or already in the index. If this check fails, the 678 * function will return git_error_code.GIT_EINVALIDSPEC. 679 * 680 * To emulate `git add -A` with the "dry-run" option, just use a callback 681 * function that always returns a positive value. See below for details. 682 * 683 * If any files are currently the result of a merge conflict, those files 684 * will no longer be marked as conflicting. The data about the conflicts 685 * will be moved to the "resolve undo" (REUC) section. 686 * 687 * If you provide a callback function, it will be invoked on each matching 688 * item in the working directory immediately *before* it is added to / 689 * updated in the index. Returning zero will add the item to the index, 690 * greater than zero will skip the item, and less than zero will abort the 691 * scan and return that value to the caller. 692 * 693 * @param index an existing index object 694 * @param pathspec array of path patterns 695 * @param flags combination of git_index_add_option_t flags 696 * @param callback notification callback for each added/updated path (also 697 * gets index of matching pathspec entry); can be null; 698 * return 0 to add, >0 to skip, <0 to abort scan. 699 * @param payload payload passed through to callback function 700 * @return 0 on success, negative callback return value, or error code 701 */ 702 //GIT_EXTERN 703 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); 704 705 /** 706 * Remove all matching index entries. 707 * 708 * If you provide a callback function, it will be invoked on each matching 709 * item in the index immediately *before* it is removed. Return 0 to 710 * remove the item, > 0 to skip the item, and < 0 to abort the scan. 711 * 712 * @param index An existing index object 713 * @param pathspec array of path patterns 714 * @param callback notification callback for each removed path (also 715 * gets index of matching pathspec entry); can be null; 716 * return 0 to add, >0 to skip, <0 to abort scan. 717 * @param payload payload passed through to callback function 718 * @return 0 on success, negative callback return value, or error code 719 */ 720 //GIT_EXTERN 721 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); 722 723 /** 724 * Update all index entries to match the working directory 725 * 726 * This method will fail in bare index instances. 727 * 728 * This scans the existing index entries and synchronizes them with the 729 * working directory, deleting them if the corresponding working directory 730 * file no longer exists otherwise updating the information (including 731 * adding the latest version of file to the ODB if needed). 732 * 733 * If you provide a callback function, it will be invoked on each matching 734 * item in the index immediately *before* it is updated (either refreshed 735 * or removed depending on working directory state). Return 0 to proceed 736 * with updating the item, > 0 to skip the item, and < 0 to abort the scan. 737 * 738 * @param index An existing index object 739 * @param pathspec array of path patterns 740 * @param callback notification callback for each updated path (also 741 * gets index of matching pathspec entry); can be null; 742 * return 0 to add, >0 to skip, <0 to abort scan. 743 * @param payload payload passed through to callback function 744 * @return 0 on success, negative callback return value, or error code 745 */ 746 //GIT_EXTERN 747 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); 748 749 /** 750 * Find the first position of any entries which point to given 751 * path in the Git index. 752 * 753 * @param at_pos the address to which the position of the index entry is written 754 * (optional) 755 * @param index an existing index object 756 * @param path path to search 757 * @return a zero-based position in the index if found; git_error_code.GIT_ENOTFOUND otherwise 758 */ 759 //GIT_EXTERN 760 int git_index_find(size_t* at_pos, libgit2_d.types.git_index* index, const (char)* path); 761 762 /** 763 * Find the first position of any entries matching a prefix. To find the first 764 * position of a path inside a given folder, suffix the prefix with a '/'. 765 * 766 * @param at_pos the address to which the position of the index entry is written 767 * (optional) 768 * @param index an existing index object 769 * @param prefix the prefix to search for 770 * @return 0 with valid value in at_pos; an error code otherwise 771 */ 772 //GIT_EXTERN 773 int git_index_find_prefix(size_t* at_pos, libgit2_d.types.git_index* index, const (char)* prefix); 774 775 /**@}*/ 776 777 /** 778 * @name Conflict Index Entry Functions 779 * 780 * These functions work on conflict index entries specifically (ie, stages 1-3) 781 */ 782 /**@{*/ 783 784 /** 785 * Add or update index entries to represent a conflict. Any staged 786 * entries that exist at the given paths will be removed. 787 * 788 * The entries are the entries from the tree included in the merge. Any 789 * entry may be null to indicate that that file was not present in the 790 * trees during the merge. For example, ancestor_entry may be null to 791 * indicate that a file was added in both branches and must be resolved. 792 * 793 * @param index an existing index object 794 * @param ancestor_entry the entry data for the ancestor of the conflict 795 * @param our_entry the entry data for our side of the merge conflict 796 * @param their_entry the entry data for their side of the merge conflict 797 * @return 0 or an error code 798 */ 799 //GIT_EXTERN 800 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); 801 802 /** 803 * Get the index entries that represent a conflict of a single file. 804 * 805 * The entries are not modifiable and should not be freed. Because the 806 * `git_index_entry` struct is a publicly defined struct, you should 807 * be able to make your own permanent copy of the data if necessary. 808 * 809 * @param ancestor_out Pointer to store the ancestor entry 810 * @param our_out Pointer to store the our entry 811 * @param their_out Pointer to store the their entry 812 * @param index an existing index object 813 * @param path path to search 814 * @return 0 or an error code 815 */ 816 //GIT_EXTERN 817 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); 818 819 /** 820 * Removes the index entries that represent a conflict of a single file. 821 * 822 * @param index an existing index object 823 * @param path path to remove conflicts for 824 * @return 0 or an error code 825 */ 826 //GIT_EXTERN 827 int git_index_conflict_remove(libgit2_d.types.git_index* index, const (char)* path); 828 829 /** 830 * Remove all conflicts in the index (entries with a stage greater than 0). 831 * 832 * @param index an existing index object 833 * @return 0 or an error code 834 */ 835 //GIT_EXTERN 836 int git_index_conflict_cleanup(libgit2_d.types.git_index* index); 837 838 /** 839 * Determine if the index contains entries representing file conflicts. 840 * 841 * @return 1 if at least one conflict is found, 0 otherwise. 842 */ 843 //GIT_EXTERN 844 int git_index_has_conflicts(const (libgit2_d.types.git_index)* index); 845 846 /** 847 * Create an iterator for the conflicts in the index. 848 * 849 * The index must not be modified while iterating; the results are undefined. 850 * 851 * @param iterator_out The newly created conflict iterator 852 * @param index The index to scan 853 * @return 0 or an error code 854 */ 855 //GIT_EXTERN 856 int git_index_conflict_iterator_new(libgit2_d.types.git_index_conflict_iterator** iterator_out, libgit2_d.types.git_index* index); 857 858 /** 859 * Returns the current conflict (ancestor, ours and theirs entry) and 860 * advance the iterator internally to the next value. 861 * 862 * @param ancestor_out Pointer to store the ancestor side of the conflict 863 * @param our_out Pointer to store our side of the conflict 864 * @param their_out Pointer to store their side of the conflict 865 * @return 0 (no error), git_error_code.GIT_ITEROVER (iteration is done) or an error code 866 * (negative value) 867 */ 868 //GIT_EXTERN 869 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); 870 871 /** 872 * Frees a `git_index_conflict_iterator`. 873 * 874 * @param iterator pointer to the iterator 875 */ 876 //GIT_EXTERN 877 void git_index_conflict_iterator_free(libgit2_d.types.git_index_conflict_iterator* iterator); 878 879 /** @} */