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