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