Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:37

0001 /*
0002  * Copyright (C) the libgit2 contributors. All rights reserved.
0003  *
0004  * This file is part of libgit2, distributed under the GNU GPL v2 with
0005  * a Linking Exception. For full terms see the included COPYING file.
0006  */
0007 #ifndef INCLUDE_git_index_h__
0008 #define INCLUDE_git_index_h__
0009 
0010 #include "common.h"
0011 #include "indexer.h"
0012 #include "types.h"
0013 #include "oid.h"
0014 #include "strarray.h"
0015 
0016 /**
0017  * @file git2/index.h
0018  * @brief Git index parsing and manipulation routines
0019  * @defgroup git_index Git index parsing and manipulation routines
0020  * @ingroup Git
0021  * @{
0022  */
0023 GIT_BEGIN_DECL
0024 
0025 /** Time structure used in a git index entry */
0026 typedef struct {
0027     int32_t seconds;
0028     /* nsec should not be stored as time_t compatible */
0029     uint32_t nanoseconds;
0030 } git_index_time;
0031 
0032 /**
0033  * In-memory representation of a file entry in the index.
0034  *
0035  * This is a public structure that represents a file entry in the index.
0036  * The meaning of the fields corresponds to core Git's documentation (in
0037  * "Documentation/technical/index-format.txt").
0038  *
0039  * The `flags` field consists of a number of bit fields which can be
0040  * accessed via the first set of `GIT_INDEX_ENTRY_...` bitmasks below.
0041  * These flags are all read from and persisted to disk.
0042  *
0043  * The `flags_extended` field also has a number of bit fields which can be
0044  * accessed via the later `GIT_INDEX_ENTRY_...` bitmasks below.  Some of
0045  * these flags are read from and written to disk, but some are set aside
0046  * for in-memory only reference.
0047  *
0048  * Note that the time and size fields are truncated to 32 bits. This
0049  * is enough to detect changes, which is enough for the index to
0050  * function as a cache, but it should not be taken as an authoritative
0051  * source for that data.
0052  */
0053 typedef struct git_index_entry {
0054     git_index_time ctime;
0055     git_index_time mtime;
0056 
0057     uint32_t dev;
0058     uint32_t ino;
0059     uint32_t mode;
0060     uint32_t uid;
0061     uint32_t gid;
0062     uint32_t file_size;
0063 
0064     git_oid id;
0065 
0066     uint16_t flags;
0067     uint16_t flags_extended;
0068 
0069     const char *path;
0070 } git_index_entry;
0071 
0072 /**
0073  * Bitmasks for on-disk fields of `git_index_entry`'s `flags`
0074  *
0075  * These bitmasks match the four fields in the `git_index_entry` `flags`
0076  * value both in memory and on disk.  You can use them to interpret the
0077  * data in the `flags`.
0078  */
0079 
0080 #define GIT_INDEX_ENTRY_NAMEMASK  (0x0fff)
0081 #define GIT_INDEX_ENTRY_STAGEMASK (0x3000)
0082 #define GIT_INDEX_ENTRY_STAGESHIFT 12
0083 
0084 /**
0085  * Flags for index entries
0086  */
0087 typedef enum {
0088     GIT_INDEX_ENTRY_EXTENDED  = (0x4000),
0089     GIT_INDEX_ENTRY_VALID     = (0x8000)
0090 } git_index_entry_flag_t;
0091 
0092 #define GIT_INDEX_ENTRY_STAGE(E) \
0093     (((E)->flags & GIT_INDEX_ENTRY_STAGEMASK) >> GIT_INDEX_ENTRY_STAGESHIFT)
0094 
0095 #define GIT_INDEX_ENTRY_STAGE_SET(E,S) do { \
0096     (E)->flags = ((E)->flags & ~GIT_INDEX_ENTRY_STAGEMASK) | \
0097         (((S) & 0x03) << GIT_INDEX_ENTRY_STAGESHIFT); } while (0)
0098 
0099 /**
0100  * Bitmasks for on-disk fields of `git_index_entry`'s `flags_extended`
0101  *
0102  * In memory, the `flags_extended` fields are divided into two parts: the
0103  * fields that are read from and written to disk, and other fields that
0104  * in-memory only and used by libgit2.  Only the flags in
0105  * `GIT_INDEX_ENTRY_EXTENDED_FLAGS` will get saved on-disk.
0106  *
0107  * Thee first three bitmasks match the three fields in the
0108  * `git_index_entry` `flags_extended` value that belong on disk.  You
0109  * can use them to interpret the data in the `flags_extended`.
0110  *
0111  * The rest of the bitmasks match the other fields in the `git_index_entry`
0112  * `flags_extended` value that are only used in-memory by libgit2.
0113  * You can use them to interpret the data in the `flags_extended`.
0114  *
0115  */
0116 typedef enum {
0117     GIT_INDEX_ENTRY_INTENT_TO_ADD  =  (1 << 13),
0118     GIT_INDEX_ENTRY_SKIP_WORKTREE  =  (1 << 14),
0119 
0120     GIT_INDEX_ENTRY_EXTENDED_FLAGS =  (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE),
0121 
0122     GIT_INDEX_ENTRY_UPTODATE       =  (1 << 2)
0123 } git_index_entry_extended_flag_t;
0124 
0125 /** Capabilities of system that affect index actions. */
0126 typedef enum {
0127     GIT_INDEX_CAPABILITY_IGNORE_CASE = 1,
0128     GIT_INDEX_CAPABILITY_NO_FILEMODE = 2,
0129     GIT_INDEX_CAPABILITY_NO_SYMLINKS = 4,
0130     GIT_INDEX_CAPABILITY_FROM_OWNER  = -1
0131 } git_index_capability_t;
0132 
0133 
0134 /** Callback for APIs that add/remove/update files matching pathspec */
0135 typedef int GIT_CALLBACK(git_index_matched_path_cb)(
0136     const char *path, const char *matched_pathspec, void *payload);
0137 
0138 /** Flags for APIs that add files matching pathspec */
0139 typedef enum {
0140     GIT_INDEX_ADD_DEFAULT = 0,
0141     GIT_INDEX_ADD_FORCE = (1u << 0),
0142     GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = (1u << 1),
0143     GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2)
0144 } git_index_add_option_t;
0145 
0146 /** Git index stage states */
0147 typedef enum {
0148     /**
0149      * Match any index stage.
0150      *
0151      * Some index APIs take a stage to match; pass this value to match
0152      * any entry matching the path regardless of stage.
0153      */
0154     GIT_INDEX_STAGE_ANY = -1,
0155 
0156     /** A normal staged file in the index. */
0157     GIT_INDEX_STAGE_NORMAL = 0,
0158 
0159     /** The ancestor side of a conflict. */
0160     GIT_INDEX_STAGE_ANCESTOR = 1,
0161 
0162     /** The "ours" side of a conflict. */
0163     GIT_INDEX_STAGE_OURS = 2,
0164 
0165     /** The "theirs" side of a conflict. */
0166     GIT_INDEX_STAGE_THEIRS = 3
0167 } git_index_stage_t;
0168 
0169 /**
0170  * Create a new bare Git index object as a memory representation
0171  * of the Git index file in 'index_path', without a repository
0172  * to back it.
0173  *
0174  * Since there is no ODB or working directory behind this index,
0175  * any Index methods which rely on these (e.g. index_add_bypath)
0176  * will fail with the GIT_ERROR error code.
0177  *
0178  * If you need to access the index of an actual repository,
0179  * use the `git_repository_index` wrapper.
0180  *
0181  * The index must be freed once it's no longer in use.
0182  *
0183  * @param out the pointer for the new index
0184  * @param index_path the path to the index file in disk
0185  * @return 0 or an error code
0186  */
0187 
0188 #ifdef GIT_EXPERIMENTAL_SHA256
0189 GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path, git_oid_t oid_type);
0190 #else
0191 GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
0192 #endif
0193 
0194 /**
0195  * Create an in-memory index object.
0196  *
0197  * This index object cannot be read/written to the filesystem,
0198  * but may be used to perform in-memory index operations.
0199  *
0200  * The index must be freed once it's no longer in use.
0201  *
0202  * @param out the pointer for the new index
0203  * @return 0 or an error code
0204  */
0205 #ifdef GIT_EXPERIMENTAL_SHA256
0206 GIT_EXTERN(int) git_index_new(git_index **out, git_oid_t oid_type);
0207 #else
0208 GIT_EXTERN(int) git_index_new(git_index **out);
0209 #endif
0210 
0211 /**
0212  * Free an existing index object.
0213  *
0214  * @param index an existing index object
0215  */
0216 GIT_EXTERN(void) git_index_free(git_index *index);
0217 
0218 /**
0219  * Get the repository this index relates to
0220  *
0221  * @param index The index
0222  * @return A pointer to the repository
0223  */
0224 GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
0225 
0226 /**
0227  * Read index capabilities flags.
0228  *
0229  * @param index An existing index object
0230  * @return A combination of GIT_INDEX_CAPABILITY values
0231  */
0232 GIT_EXTERN(int) git_index_caps(const git_index *index);
0233 
0234 /**
0235  * Set index capabilities flags.
0236  *
0237  * If you pass `GIT_INDEX_CAPABILITY_FROM_OWNER` for the caps, then
0238  * capabilities will be read from the config of the owner object,
0239  * looking at `core.ignorecase`, `core.filemode`, `core.symlinks`.
0240  *
0241  * @param index An existing index object
0242  * @param caps A combination of GIT_INDEX_CAPABILITY values
0243  * @return 0 on success, -1 on failure
0244  */
0245 GIT_EXTERN(int) git_index_set_caps(git_index *index, int caps);
0246 
0247 /**
0248  * Get index on-disk version.
0249  *
0250  * Valid return values are 2, 3, or 4.  If 3 is returned, an index
0251  * with version 2 may be written instead, if the extension data in
0252  * version 3 is not necessary.
0253  *
0254  * @param index An existing index object
0255  * @return the index version
0256  */
0257 GIT_EXTERN(unsigned int) git_index_version(git_index *index);
0258 
0259 /**
0260  * Set index on-disk version.
0261  *
0262  * Valid values are 2, 3, or 4.  If 2 is given, git_index_write may
0263  * write an index with version 3 instead, if necessary to accurately
0264  * represent the index.
0265  *
0266  * @param index An existing index object
0267  * @param version The new version number
0268  * @return 0 on success, -1 on failure
0269  */
0270 GIT_EXTERN(int) git_index_set_version(git_index *index, unsigned int version);
0271 
0272 /**
0273  * Update the contents of an existing index object in memory by reading
0274  * from the hard disk.
0275  *
0276  * If `force` is true, this performs a "hard" read that discards in-memory
0277  * changes and always reloads the on-disk index data.  If there is no
0278  * on-disk version, the index will be cleared.
0279  *
0280  * If `force` is false, this does a "soft" read that reloads the index
0281  * data from disk only if it has changed since the last time it was
0282  * loaded.  Purely in-memory index data will be untouched.  Be aware: if
0283  * there are changes on disk, unwritten in-memory changes are discarded.
0284  *
0285  * @param index an existing index object
0286  * @param force if true, always reload, vs. only read if file has changed
0287  * @return 0 or an error code
0288  */
0289 GIT_EXTERN(int) git_index_read(git_index *index, int force);
0290 
0291 /**
0292  * Write an existing index object from memory back to disk
0293  * using an atomic file lock.
0294  *
0295  * @param index an existing index object
0296  * @return 0 or an error code
0297  */
0298 GIT_EXTERN(int) git_index_write(git_index *index);
0299 
0300 /**
0301  * Get the full path to the index file on disk.
0302  *
0303  * @param index an existing index object
0304  * @return path to index file or NULL for in-memory index
0305  */
0306 GIT_EXTERN(const char *) git_index_path(const git_index *index);
0307 
0308 #ifndef GIT_DEPRECATE_HARD
0309 /**
0310  * Get the checksum of the index
0311  *
0312  * This checksum is the SHA-1 hash over the index file (except the
0313  * last 20 bytes which are the checksum itself). In cases where the
0314  * index does not exist on-disk, it will be zeroed out.
0315  *
0316  * @deprecated this function is deprecated with no replacement
0317  * @param index an existing index object
0318  * @return a pointer to the checksum of the index
0319  */
0320 GIT_EXTERN(const git_oid *) git_index_checksum(git_index *index);
0321 #endif
0322 
0323 /**
0324  * Read a tree into the index file with stats
0325  *
0326  * The current index contents will be replaced by the specified tree.
0327  *
0328  * @param index an existing index object
0329  * @param tree tree to read
0330  * @return 0 or an error code
0331  */
0332 GIT_EXTERN(int) git_index_read_tree(git_index *index, const git_tree *tree);
0333 
0334 /**
0335  * Write the index as a tree
0336  *
0337  * This method will scan the index and write a representation
0338  * of its current state back to disk; it recursively creates
0339  * tree objects for each of the subtrees stored in the index,
0340  * but only returns the OID of the root tree. This is the OID
0341  * that can be used e.g. to create a commit.
0342  *
0343  * The index instance cannot be bare, and needs to be associated
0344  * to an existing repository.
0345  *
0346  * The index must not contain any file in conflict.
0347  *
0348  * @param out Pointer where to store the OID of the written tree
0349  * @param index Index to write
0350  * @return 0 on success, GIT_EUNMERGED when the index is not clean
0351  * or an error code
0352  */
0353 GIT_EXTERN(int) git_index_write_tree(git_oid *out, git_index *index);
0354 
0355 /**
0356  * Write the index as a tree to the given repository
0357  *
0358  * This method will do the same as `git_index_write_tree`, but
0359  * letting the user choose the repository where the tree will
0360  * be written.
0361  *
0362  * The index must not contain any file in conflict.
0363  *
0364  * @param out Pointer where to store OID of the written tree
0365  * @param index Index to write
0366  * @param repo Repository where to write the tree
0367  * @return 0 on success, GIT_EUNMERGED when the index is not clean
0368  * or an error code
0369  */
0370 GIT_EXTERN(int) git_index_write_tree_to(git_oid *out, git_index *index, git_repository *repo);
0371 
0372 /**@}*/
0373 
0374 /** @name Raw Index Entry Functions
0375  *
0376  * These functions work on index entries, and allow for raw manipulation
0377  * of the entries.
0378  */
0379 /**@{*/
0380 
0381 /* Index entry manipulation */
0382 
0383 /**
0384  * Get the count of entries currently in the index
0385  *
0386  * @param index an existing index object
0387  * @return integer of count of current entries
0388  */
0389 GIT_EXTERN(size_t) git_index_entrycount(const git_index *index);
0390 
0391 /**
0392  * Clear the contents (all the entries) of an index object.
0393  *
0394  * This clears the index object in memory; changes must be explicitly
0395  * written to disk for them to take effect persistently.
0396  *
0397  * @param index an existing index object
0398  * @return 0 on success, error code < 0 on failure
0399  */
0400 GIT_EXTERN(int) git_index_clear(git_index *index);
0401 
0402 /**
0403  * Get a pointer to one of the entries in the index
0404  *
0405  * The entry is not modifiable and should not be freed.  Because the
0406  * `git_index_entry` struct is a publicly defined struct, you should
0407  * be able to make your own permanent copy of the data if necessary.
0408  *
0409  * @param index an existing index object
0410  * @param n the position of the entry
0411  * @return a pointer to the entry; NULL if out of bounds
0412  */
0413 GIT_EXTERN(const git_index_entry *) git_index_get_byindex(
0414     git_index *index, size_t n);
0415 
0416 /**
0417  * Get a pointer to one of the entries in the index
0418  *
0419  * The entry is not modifiable and should not be freed.  Because the
0420  * `git_index_entry` struct is a publicly defined struct, you should
0421  * be able to make your own permanent copy of the data if necessary.
0422  *
0423  * @param index an existing index object
0424  * @param path path to search
0425  * @param stage stage to search
0426  * @return a pointer to the entry; NULL if it was not found
0427  */
0428 GIT_EXTERN(const git_index_entry *) git_index_get_bypath(
0429     git_index *index, const char *path, int stage);
0430 
0431 /**
0432  * Remove an entry from the index
0433  *
0434  * @param index an existing index object
0435  * @param path path to search
0436  * @param stage stage to search
0437  * @return 0 or an error code
0438  */
0439 GIT_EXTERN(int) git_index_remove(git_index *index, const char *path, int stage);
0440 
0441 /**
0442  * Remove all entries from the index under a given directory
0443  *
0444  * @param index an existing index object
0445  * @param dir container directory path
0446  * @param stage stage to search
0447  * @return 0 or an error code
0448  */
0449 GIT_EXTERN(int) git_index_remove_directory(
0450     git_index *index, const char *dir, int stage);
0451 
0452 /**
0453  * Add or update an index entry from an in-memory struct
0454  *
0455  * If a previous index entry exists that has the same path and stage
0456  * as the given 'source_entry', it will be replaced.  Otherwise, the
0457  * 'source_entry' will be added.
0458  *
0459  * A full copy (including the 'path' string) of the given
0460  * 'source_entry' will be inserted on the index.
0461  *
0462  * @param index an existing index object
0463  * @param source_entry new entry object
0464  * @return 0 or an error code
0465  */
0466 GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_entry);
0467 
0468 /**
0469  * Return the stage number from a git index entry
0470  *
0471  * This entry is calculated from the entry's flag attribute like this:
0472  *
0473  *    (entry->flags & GIT_INDEX_ENTRY_STAGEMASK) >> GIT_INDEX_ENTRY_STAGESHIFT
0474  *
0475  * @param entry The entry
0476  * @return the stage number
0477  */
0478 GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
0479 
0480 /**
0481  * Return whether the given index entry is a conflict (has a high stage
0482  * entry).  This is simply shorthand for `git_index_entry_stage > 0`.
0483  *
0484  * @param entry The entry
0485  * @return 1 if the entry is a conflict entry, 0 otherwise
0486  */
0487 GIT_EXTERN(int) git_index_entry_is_conflict(const git_index_entry *entry);
0488 
0489 /**@}*/
0490 
0491 /** @name Index Entry Iteration Functions
0492  *
0493  * These functions provide an iterator for index entries.
0494  */
0495 /**@{*/
0496 
0497 /**
0498  * Create an iterator that will return every entry contained in the
0499  * index at the time of creation.  Entries are returned in order,
0500  * sorted by path.  This iterator is backed by a snapshot that allows
0501  * callers to modify the index while iterating without affecting the
0502  * iterator.
0503  *
0504  * @param iterator_out The newly created iterator
0505  * @param index The index to iterate
0506  * @return 0 or an error code.
0507  */
0508 GIT_EXTERN(int) git_index_iterator_new(
0509     git_index_iterator **iterator_out,
0510     git_index *index);
0511 
0512 /**
0513  * Return the next index entry in-order from the iterator.
0514  *
0515  * @param out Pointer to store the index entry in
0516  * @param iterator The iterator
0517  * @return 0, GIT_ITEROVER on iteration completion or an error code
0518  */
0519 GIT_EXTERN(int) git_index_iterator_next(
0520     const git_index_entry **out,
0521     git_index_iterator *iterator);
0522 
0523 /**
0524  * Free the index iterator
0525  *
0526  * @param iterator The iterator to free
0527  */
0528 GIT_EXTERN(void) git_index_iterator_free(git_index_iterator *iterator);
0529 
0530 /**@}*/
0531 
0532 /** @name Workdir Index Entry Functions
0533  *
0534  * These functions work on index entries specifically in the working
0535  * directory (ie, stage 0).
0536  */
0537 /**@{*/
0538 
0539 /**
0540  * Add or update an index entry from a file on disk
0541  *
0542  * The file `path` must be relative to the repository's
0543  * working folder and must be readable.
0544  *
0545  * This method will fail in bare index instances.
0546  *
0547  * This forces the file to be added to the index, not looking
0548  * at gitignore rules.  Those rules can be evaluated through
0549  * the git_status APIs (in status.h) before calling this.
0550  *
0551  * If this file currently is the result of a merge conflict, this
0552  * file will no longer be marked as conflicting.  The data about
0553  * the conflict will be moved to the "resolve undo" (REUC) section.
0554  *
0555  * @param index an existing index object
0556  * @param path filename to add
0557  * @return 0 or an error code
0558  */
0559 GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path);
0560 
0561 /**
0562  * Add or update an index entry from a buffer in memory
0563  *
0564  * This method will create a blob in the repository that owns the
0565  * index and then add the index entry to the index.  The `path` of the
0566  * entry represents the position of the blob relative to the
0567  * repository's root folder.
0568  *
0569  * If a previous index entry exists that has the same path as the
0570  * given 'entry', it will be replaced.  Otherwise, the 'entry' will be
0571  * added.
0572  *
0573  * This forces the file to be added to the index, not looking
0574  * at gitignore rules.  Those rules can be evaluated through
0575  * the git_status APIs (in status.h) before calling this.
0576  *
0577  * If this file currently is the result of a merge conflict, this
0578  * file will no longer be marked as conflicting.  The data about
0579  * the conflict will be moved to the "resolve undo" (REUC) section.
0580  *
0581  * @param index an existing index object
0582  * @param entry filename to add
0583  * @param buffer data to be written into the blob
0584  * @param len length of the data
0585  * @return 0 or an error code
0586  */
0587 GIT_EXTERN(int) git_index_add_from_buffer(
0588     git_index *index,
0589     const git_index_entry *entry,
0590     const void *buffer, size_t len);
0591 
0592 /**
0593  * Remove an index entry corresponding to a file on disk
0594  *
0595  * The file `path` must be relative to the repository's
0596  * working folder.  It may exist.
0597  *
0598  * If this file currently is the result of a merge conflict, this
0599  * file will no longer be marked as conflicting.  The data about
0600  * the conflict will be moved to the "resolve undo" (REUC) section.
0601  *
0602  * @param index an existing index object
0603  * @param path filename to remove
0604  * @return 0 or an error code
0605  */
0606 GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path);
0607 
0608 /**
0609  * Add or update index entries matching files in the working directory.
0610  *
0611  * This method will fail in bare index instances.
0612  *
0613  * The `pathspec` is a list of file names or shell glob patterns that will
0614  * be matched against files in the repository's working directory.  Each
0615  * file that matches will be added to the index (either updating an
0616  * existing entry or adding a new entry).  You can disable glob expansion
0617  * and force exact matching with the `GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH`
0618  * flag.
0619  *
0620  * Files that are ignored will be skipped (unlike `git_index_add_bypath`).
0621  * If a file is already tracked in the index, then it *will* be updated
0622  * even if it is ignored.  Pass the `GIT_INDEX_ADD_FORCE` flag to skip
0623  * the checking of ignore rules.
0624  *
0625  * To emulate `git add -A` and generate an error if the pathspec contains
0626  * the exact path of an ignored file (when not using FORCE), add the
0627  * `GIT_INDEX_ADD_CHECK_PATHSPEC` flag.  This checks that each entry
0628  * in the `pathspec` that is an exact match to a filename on disk is
0629  * either not ignored or already in the index.  If this check fails, the
0630  * function will return GIT_EINVALIDSPEC.
0631  *
0632  * To emulate `git add -A` with the "dry-run" option, just use a callback
0633  * function that always returns a positive value.  See below for details.
0634  *
0635  * If any files are currently the result of a merge conflict, those files
0636  * will no longer be marked as conflicting.  The data about the conflicts
0637  * will be moved to the "resolve undo" (REUC) section.
0638  *
0639  * If you provide a callback function, it will be invoked on each matching
0640  * item in the working directory immediately *before* it is added to /
0641  * updated in the index.  Returning zero will add the item to the index,
0642  * greater than zero will skip the item, and less than zero will abort the
0643  * scan and return that value to the caller.
0644  *
0645  * @param index an existing index object
0646  * @param pathspec array of path patterns
0647  * @param flags combination of git_index_add_option_t flags
0648  * @param callback notification callback for each added/updated path (also
0649  *                 gets index of matching pathspec entry); can be NULL;
0650  *                 return 0 to add, >0 to skip, <0 to abort scan.
0651  * @param payload payload passed through to callback function
0652  * @return 0 on success, negative callback return value, or error code
0653  */
0654 GIT_EXTERN(int) git_index_add_all(
0655     git_index *index,
0656     const git_strarray *pathspec,
0657     unsigned int flags,
0658     git_index_matched_path_cb callback,
0659     void *payload);
0660 
0661 /**
0662  * Remove all matching index entries.
0663  *
0664  * If you provide a callback function, it will be invoked on each matching
0665  * item in the index immediately *before* it is removed.  Return 0 to
0666  * remove the item, > 0 to skip the item, and < 0 to abort the scan.
0667  *
0668  * @param index An existing index object
0669  * @param pathspec array of path patterns
0670  * @param callback notification callback for each removed path (also
0671  *                 gets index of matching pathspec entry); can be NULL;
0672  *                 return 0 to add, >0 to skip, <0 to abort scan.
0673  * @param payload payload passed through to callback function
0674  * @return 0 on success, negative callback return value, or error code
0675  */
0676 GIT_EXTERN(int) git_index_remove_all(
0677     git_index *index,
0678     const git_strarray *pathspec,
0679     git_index_matched_path_cb callback,
0680     void *payload);
0681 
0682 /**
0683  * Update all index entries to match the working directory
0684  *
0685  * This method will fail in bare index instances.
0686  *
0687  * This scans the existing index entries and synchronizes them with the
0688  * working directory, deleting them if the corresponding working directory
0689  * file no longer exists otherwise updating the information (including
0690  * adding the latest version of file to the ODB if needed).
0691  *
0692  * If you provide a callback function, it will be invoked on each matching
0693  * item in the index immediately *before* it is updated (either refreshed
0694  * or removed depending on working directory state).  Return 0 to proceed
0695  * with updating the item, > 0 to skip the item, and < 0 to abort the scan.
0696  *
0697  * @param index An existing index object
0698  * @param pathspec array of path patterns
0699  * @param callback notification callback for each updated path (also
0700  *                 gets index of matching pathspec entry); can be NULL;
0701  *                 return 0 to add, >0 to skip, <0 to abort scan.
0702  * @param payload payload passed through to callback function
0703  * @return 0 on success, negative callback return value, or error code
0704  */
0705 GIT_EXTERN(int) git_index_update_all(
0706     git_index *index,
0707     const git_strarray *pathspec,
0708     git_index_matched_path_cb callback,
0709     void *payload);
0710 
0711 /**
0712  * Find the first position of any entries which point to given
0713  * path in the Git index.
0714  *
0715  * @param at_pos the address to which the position of the index entry is written (optional)
0716  * @param index an existing index object
0717  * @param path path to search
0718  * @return 0 or an error code
0719  */
0720 GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *path);
0721 
0722 /**
0723  * Find the first position of any entries matching a prefix. To find the first position
0724  * of a path inside a given folder, suffix the prefix with a '/'.
0725  *
0726  * @param at_pos the address to which the position of the index entry is written (optional)
0727  * @param index an existing index object
0728  * @param prefix the prefix to search for
0729  * @return 0 or an error code
0730  */
0731 GIT_EXTERN(int) git_index_find_prefix(size_t *at_pos, git_index *index, const char *prefix);
0732 
0733 /**@}*/
0734 
0735 /** @name Conflict Index Entry Functions
0736  *
0737  * These functions work on conflict index entries specifically (ie, stages 1-3)
0738  */
0739 /**@{*/
0740 
0741 /**
0742  * Add or update index entries to represent a conflict.  Any staged
0743  * entries that exist at the given paths will be removed.
0744  *
0745  * The entries are the entries from the tree included in the merge.  Any
0746  * entry may be null to indicate that that file was not present in the
0747  * trees during the merge.  For example, ancestor_entry may be NULL to
0748  * indicate that a file was added in both branches and must be resolved.
0749  *
0750  * @param index an existing index object
0751  * @param ancestor_entry the entry data for the ancestor of the conflict
0752  * @param our_entry the entry data for our side of the merge conflict
0753  * @param their_entry the entry data for their side of the merge conflict
0754  * @return 0 or an error code
0755  */
0756 GIT_EXTERN(int) git_index_conflict_add(
0757     git_index *index,
0758     const git_index_entry *ancestor_entry,
0759     const git_index_entry *our_entry,
0760     const git_index_entry *their_entry);
0761 
0762 /**
0763  * Get the index entries that represent a conflict of a single file.
0764  *
0765  * The entries are not modifiable and should not be freed.  Because the
0766  * `git_index_entry` struct is a publicly defined struct, you should
0767  * be able to make your own permanent copy of the data if necessary.
0768  *
0769  * @param ancestor_out Pointer to store the ancestor entry
0770  * @param our_out Pointer to store the our entry
0771  * @param their_out Pointer to store the their entry
0772  * @param index an existing index object
0773  * @param path path to search
0774  * @return 0 or an error code
0775  */
0776 GIT_EXTERN(int) git_index_conflict_get(
0777     const git_index_entry **ancestor_out,
0778     const git_index_entry **our_out,
0779     const git_index_entry **their_out,
0780     git_index *index,
0781     const char *path);
0782 
0783 /**
0784  * Removes the index entries that represent a conflict of a single file.
0785  *
0786  * @param index an existing index object
0787  * @param path path to remove conflicts for
0788  * @return 0 or an error code
0789  */
0790 GIT_EXTERN(int) git_index_conflict_remove(git_index *index, const char *path);
0791 
0792 /**
0793  * Remove all conflicts in the index (entries with a stage greater than 0).
0794  *
0795  * @param index an existing index object
0796  * @return 0 or an error code
0797  */
0798 GIT_EXTERN(int) git_index_conflict_cleanup(git_index *index);
0799 
0800 /**
0801  * Determine if the index contains entries representing file conflicts.
0802  *
0803  * @param index An existing index object.
0804  * @return 1 if at least one conflict is found, 0 otherwise.
0805  */
0806 GIT_EXTERN(int) git_index_has_conflicts(const git_index *index);
0807 
0808 /**
0809  * Create an iterator for the conflicts in the index.
0810  *
0811  * The index must not be modified while iterating; the results are undefined.
0812  *
0813  * @param iterator_out The newly created conflict iterator
0814  * @param index The index to scan
0815  * @return 0 or an error code
0816  */
0817 GIT_EXTERN(int) git_index_conflict_iterator_new(
0818     git_index_conflict_iterator **iterator_out,
0819     git_index *index);
0820 
0821 /**
0822  * Returns the current conflict (ancestor, ours and theirs entry) and
0823  * advance the iterator internally to the next value.
0824  *
0825  * @param ancestor_out Pointer to store the ancestor side of the conflict
0826  * @param our_out Pointer to store our side of the conflict
0827  * @param their_out Pointer to store their side of the conflict
0828  * @param iterator The conflict iterator.
0829  * @return 0 (no error), GIT_ITEROVER (iteration is done) or an error code
0830  *         (negative value)
0831  */
0832 GIT_EXTERN(int) git_index_conflict_next(
0833     const git_index_entry **ancestor_out,
0834     const git_index_entry **our_out,
0835     const git_index_entry **their_out,
0836     git_index_conflict_iterator *iterator);
0837 
0838 /**
0839  * Frees a `git_index_conflict_iterator`.
0840  *
0841  * @param iterator pointer to the iterator
0842  */
0843 GIT_EXTERN(void) git_index_conflict_iterator_free(
0844     git_index_conflict_iterator *iterator);
0845 
0846 /** @} */
0847 GIT_END_DECL
0848 #endif