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