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 #ifndef INCLUDE_sys_git_index_h__ 8 #define INCLUDE_sys_git_index_h__ 9 10 #include "git2/common.h" 11 #include "git2/types.h" 12 13 /** 14 * @file git2/sys/index.h 15 * @brief Low-level Git index manipulation routines 16 * @defgroup git_backend Git custom backend APIs 17 * @ingroup Git 18 * @{ 19 */ 20 GIT_BEGIN_DECL 21 22 /** Representation of a rename conflict entry in the index. */ 23 typedef struct git_index_name_entry { 24 char *ancestor; 25 char *ours; 26 char *theirs; 27 } git_index_name_entry; 28 29 /** Representation of a resolve undo entry in the index. */ 30 typedef struct git_index_reuc_entry { 31 uint32_t mode[3]; 32 git_oid oid[3]; 33 char *path; 34 } git_index_reuc_entry; 35 36 /** @name Conflict Name entry functions 37 * 38 * These functions work on rename conflict entries. 39 */ 40 /**@{*/ 41 42 /** 43 * Get the count of filename conflict entries currently in the index. 44 * 45 * @param index an existing index object 46 * @return integer of count of current filename conflict entries 47 */ 48 GIT_EXTERN(size_t) git_index_name_entrycount(git_index *index); 49 50 /** 51 * Get a filename conflict entry from the index. 52 * 53 * The returned entry is read-only and should not be modified 54 * or freed by the caller. 55 * 56 * @param index an existing index object 57 * @param n the position of the entry 58 * @return a pointer to the filename conflict entry; NULL if out of bounds 59 */ 60 GIT_EXTERN(const git_index_name_entry *) git_index_name_get_byindex( 61 git_index *index, size_t n); 62 63 /** 64 * Record the filenames involved in a rename conflict. 65 * 66 * @param index an existing index object 67 * @param ancestor the path of the file as it existed in the ancestor 68 * @param ours the path of the file as it existed in our tree 69 * @param theirs the path of the file as it existed in their tree 70 */ 71 GIT_EXTERN(int) git_index_name_add(git_index *index, 72 const char *ancestor, const char *ours, const char *theirs); 73 74 /** 75 * Remove all filename conflict entries. 76 * 77 * @param index an existing index object 78 * @return 0 or an error code 79 */ 80 GIT_EXTERN(int) git_index_name_clear(git_index *index); 81 82 /**@}*/ 83 84 /** @name Resolve Undo (REUC) index entry manipulation. 85 * 86 * These functions work on the Resolve Undo index extension and contains 87 * data about the original files that led to a merge conflict. 88 */ 89 /**@{*/ 90 91 /** 92 * Get the count of resolve undo entries currently in the index. 93 * 94 * @param index an existing index object 95 * @return integer of count of current resolve undo entries 96 */ 97 GIT_EXTERN(size_t) git_index_reuc_entrycount(git_index *index); 98 99 /** 100 * Finds the resolve undo entry that points to the given path in the Git 101 * index. 102 * 103 * @param at_pos the address to which the position of the reuc entry is written (optional) 104 * @param index an existing index object 105 * @param path path to search 106 * @return 0 if found, < 0 otherwise (GIT_ENOTFOUND) 107 */ 108 GIT_EXTERN(int) git_index_reuc_find(size_t *at_pos, git_index *index, const char *path); 109 110 /** 111 * Get a resolve undo entry from the index. 112 * 113 * The returned entry is read-only and should not be modified 114 * or freed by the caller. 115 * 116 * @param index an existing index object 117 * @param path path to search 118 * @return the resolve undo entry; NULL if not found 119 */ 120 GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *index, const char *path); 121 122 /** 123 * Get a resolve undo entry from the index. 124 * 125 * The returned entry is read-only and should not be modified 126 * or freed by the caller. 127 * 128 * @param index an existing index object 129 * @param n the position of the entry 130 * @return a pointer to the resolve undo entry; NULL if out of bounds 131 */ 132 GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *index, size_t n); 133 134 /** 135 * Adds a resolve undo entry for a file based on the given parameters. 136 * 137 * The resolve undo entry contains the OIDs of files that were involved 138 * in a merge conflict after the conflict has been resolved. This allows 139 * conflicts to be re-resolved later. 140 * 141 * If there exists a resolve undo entry for the given path in the index, 142 * it will be removed. 143 * 144 * This method will fail in bare index instances. 145 * 146 * @param index an existing index object 147 * @param path filename to add 148 * @param ancestor_mode mode of the ancestor file 149 * @param ancestor_id oid of the ancestor file 150 * @param our_mode mode of our file 151 * @param our_id oid of our file 152 * @param their_mode mode of their file 153 * @param their_id oid of their file 154 * @return 0 or an error code 155 */ 156 GIT_EXTERN(int) git_index_reuc_add(git_index *index, const char *path, 157 int ancestor_mode, const git_oid *ancestor_id, 158 int our_mode, const git_oid *our_id, 159 int their_mode, const git_oid *their_id); 160 161 /** 162 * Remove an resolve undo entry from the index 163 * 164 * @param index an existing index object 165 * @param n position of the resolve undo entry to remove 166 * @return 0 or an error code 167 */ 168 GIT_EXTERN(int) git_index_reuc_remove(git_index *index, size_t n); 169 170 /** 171 * Remove all resolve undo entries from the index 172 * 173 * @param index an existing index object 174 * @return 0 or an error code 175 */ 176 GIT_EXTERN(int) git_index_reuc_clear(git_index *index); 177 178 /**@}*/ 179 180 /** @} */ 181 GIT_END_DECL 182 #endif 183