]>
Commit | Line | Data |
---|---|---|
f5918330 VM |
1 | /* |
2 | * This file is free software; you can redistribute it and/or modify | |
3 | * it under the terms of the GNU General Public License, version 2, | |
4 | * as published by the Free Software Foundation. | |
5 | * | |
6 | * In addition to the permissions in the GNU General Public License, | |
7 | * the authors give you unlimited permission to link the compiled | |
8 | * version of this file into combinations with other programs, | |
9 | * and to distribute those combinations without any restriction | |
10 | * coming from the use of this file. (The General Public License | |
11 | * restrictions do apply in other respects; for example, they cover | |
12 | * modification of the file, and distribution when not linked into | |
13 | * a combined executable.) | |
14 | * | |
15 | * This file is distributed in the hope that it will be useful, but | |
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; see the file COPYING. If not, write to | |
22 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, | |
23 | * Boston, MA 02110-1301, USA. | |
24 | */ | |
68535125 VM |
25 | #ifndef INCLUDE_git_index_h__ |
26 | #define INCLUDE_git_index_h__ | |
27 | ||
28 | #include "common.h" | |
d12299fe | 29 | #include "types.h" |
fc70832a | 30 | #include "oid.h" |
68535125 VM |
31 | |
32 | /** | |
f5918330 | 33 | * @file git2/index.h |
68535125 VM |
34 | * @brief Git index parsing and manipulation routines |
35 | * @defgroup git_index Git index parsing and manipulation routines | |
36 | * @ingroup Git | |
37 | * @{ | |
38 | */ | |
39 | GIT_BEGIN_DECL | |
40 | ||
8c1f9e4d VM |
41 | #define GIT_IDXENTRY_NAMEMASK (0x0fff) |
42 | #define GIT_IDXENTRY_STAGEMASK (0x3000) | |
43 | #define GIT_IDXENTRY_EXTENDED (0x4000) | |
44 | #define GIT_IDXENTRY_VALID (0x8000) | |
45 | #define GIT_IDXENTRY_STAGESHIFT 12 | |
46 | ||
26f2c897 JP |
47 | /* |
48 | * Flags are divided into two parts: in-memory flags and | |
49 | * on-disk ones. Flags in GIT_IDXENTRY_EXTENDED_FLAGS | |
50 | * will get saved on-disk. | |
51 | * | |
52 | * In-memory only flags: | |
53 | */ | |
54 | #define GIT_IDXENTRY_UPDATE (1 << 16) | |
55 | #define GIT_IDXENTRY_REMOVE (1 << 17) | |
56 | #define GIT_IDXENTRY_UPTODATE (1 << 18) | |
57 | #define GIT_IDXENTRY_ADDED (1 << 19) | |
58 | ||
59 | #define GIT_IDXENTRY_HASHED (1 << 20) | |
60 | #define GIT_IDXENTRY_UNHASHED (1 << 21) | |
61 | #define GIT_IDXENTRY_WT_REMOVE (1 << 22) /* remove in work directory */ | |
62 | #define GIT_IDXENTRY_CONFLICTED (1 << 23) | |
63 | ||
64 | #define GIT_IDXENTRY_UNPACKED (1 << 24) | |
65 | #define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 25) | |
66 | ||
67 | /* | |
68 | * Extended on-disk flags: | |
69 | */ | |
70 | #define GIT_IDXENTRY_INTENT_TO_ADD (1 << 29) | |
71 | #define GIT_IDXENTRY_SKIP_WORKTREE (1 << 30) | |
72 | /* GIT_IDXENTRY_EXTENDED2 is for future extension */ | |
73 | #define GIT_IDXENTRY_EXTENDED2 (1 << 31) | |
74 | ||
75 | #define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE) | |
76 | ||
77 | /* | |
78 | * Safeguard to avoid saving wrong flags: | |
79 | * - GIT_IDXENTRY_EXTENDED2 won't get saved until its semantic is known | |
80 | * - Bits in 0x0000FFFF have been saved in flags already | |
81 | * - Bits in 0x003F0000 are currently in-memory flags | |
82 | */ | |
83 | #if GIT_IDXENTRY_EXTENDED_FLAGS & 0x803FFFFF | |
84 | #error "GIT_IDXENTRY_EXTENDED_FLAGS out of range" | |
85 | #endif | |
86 | ||
6fd195d7 VM |
87 | /** Time used in a git index entry */ |
88 | typedef struct { | |
f0bde7fa AB |
89 | git_time_t seconds; |
90 | /* nsec should not be stored as time_t compatible */ | |
073fa812 | 91 | unsigned int nanoseconds; |
6fd195d7 VM |
92 | } git_index_time; |
93 | ||
68535125 | 94 | /** Memory representation of a file entry in the index. */ |
6fd195d7 VM |
95 | typedef struct git_index_entry { |
96 | git_index_time ctime; | |
97 | git_index_time mtime; | |
98 | ||
322086f9 VM |
99 | unsigned int dev; |
100 | unsigned int ino; | |
101 | unsigned int mode; | |
102 | unsigned int uid; | |
103 | unsigned int gid; | |
f0bde7fa | 104 | git_off_t file_size; |
6fd195d7 VM |
105 | |
106 | git_oid oid; | |
107 | ||
322086f9 VM |
108 | unsigned short flags; |
109 | unsigned short flags_extended; | |
6fd195d7 VM |
110 | |
111 | char *path; | |
112 | } git_index_entry; | |
68535125 | 113 | |
4c0b6a6d JP |
114 | /** Representation of an unmerged file entry in the index. */ |
115 | typedef struct git_index_entry_unmerged { | |
116 | unsigned int mode[3]; | |
117 | git_oid oid[3]; | |
118 | char *path; | |
119 | } git_index_entry_unmerged; | |
68535125 VM |
120 | |
121 | /** | |
122 | * Create a new Git index object as a memory representation | |
c3a20d5c VM |
123 | * of the Git index file in 'index_path', without a repository |
124 | * to back it. | |
68535125 | 125 | * |
c3a20d5c VM |
126 | * Since there is no ODB behind this index, any Index methods |
127 | * which rely on the ODB (e.g. index_add) will fail with the | |
128 | * GIT_EBAREINDEX error code. | |
6fd195d7 | 129 | * |
1795f879 | 130 | * @param index the pointer for the new index |
68535125 | 131 | * @param index_path the path to the index file in disk |
1795f879 | 132 | * @return 0 on success; error code otherwise |
68535125 | 133 | */ |
c3a20d5c VM |
134 | GIT_EXTERN(int) git_index_open_bare(git_index **index, const char *index_path); |
135 | ||
136 | /** | |
137 | * Open the Index inside the git repository pointed | |
138 | * by 'repo'. | |
139 | * | |
12f6d8e1 | 140 | * @param index the pointer for the new index |
c3a20d5c | 141 | * @param repo the git repo which owns the index |
c3a20d5c VM |
142 | * @return 0 on success; error code otherwise |
143 | */ | |
144 | GIT_EXTERN(int) git_index_open_inrepo(git_index **index, git_repository *repo); | |
68535125 VM |
145 | |
146 | /** | |
147 | * Clear the contents (all the entries) of an index object. | |
148 | * This clears the index object in memory; changes must be manually | |
149 | * written to disk for them to take effect. | |
150 | * | |
151 | * @param index an existing index object | |
152 | */ | |
153 | GIT_EXTERN(void) git_index_clear(git_index *index); | |
154 | ||
155 | /** | |
156 | * Free an existing index object. | |
157 | * | |
158 | * @param index an existing index object | |
159 | */ | |
160 | GIT_EXTERN(void) git_index_free(git_index *index); | |
161 | ||
162 | /** | |
163 | * Update the contents of an existing index object in memory | |
164 | * by reading from the hard disk. | |
165 | * | |
166 | * @param index an existing index object | |
167 | * @return 0 on success, otherwise an error code | |
168 | */ | |
169 | GIT_EXTERN(int) git_index_read(git_index *index); | |
170 | ||
171 | /** | |
172 | * Write an existing index object from memory back to disk | |
173 | * using an atomic file lock. | |
174 | * | |
175 | * @param index an existing index object | |
176 | * @return 0 on success, otherwise an error code | |
177 | */ | |
178 | GIT_EXTERN(int) git_index_write(git_index *index); | |
179 | ||
180 | /** | |
051d6915 | 181 | * Find the first index of any entries which point to given |
68535125 VM |
182 | * path in the Git index. |
183 | * | |
184 | * @param index an existing index object | |
185 | * @param path path to search | |
186 | * @return an index >= 0 if found, -1 otherwise | |
187 | */ | |
188 | GIT_EXTERN(int) git_index_find(git_index *index, const char *path); | |
189 | ||
190 | /** | |
c3a20d5c | 191 | * Add or update an index entry from a file in disk. |
68535125 VM |
192 | * |
193 | * @param index an existing index object | |
c3a20d5c | 194 | * @param path filename to add |
68535125 VM |
195 | * @param stage stage for the entry |
196 | * @return 0 on success, otherwise an error code | |
197 | */ | |
c3a20d5c | 198 | GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage); |
3f43678e VM |
199 | |
200 | /** | |
201 | * Remove an entry from the index | |
202 | * | |
203 | * @param index an existing index object | |
204 | * @param position position of the entry to remove | |
205 | * @return 0 on success, otherwise an error code | |
206 | */ | |
207 | GIT_EXTERN(int) git_index_remove(git_index *index, int position); | |
208 | ||
209 | /** | |
c3a20d5c VM |
210 | * Insert an entry into the index. |
211 | * A full copy (including the 'path' string) of the given | |
212 | * 'source_entry' will be inserted on the index; if the index | |
213 | * already contains an entry for the same path, the entry | |
214 | * will be updated. | |
3f43678e VM |
215 | * |
216 | * @param index an existing index object | |
217 | * @param source_entry new entry object | |
218 | * @return 0 on success, otherwise an error code | |
219 | */ | |
c3a20d5c | 220 | GIT_EXTERN(int) git_index_insert(git_index *index, const git_index_entry *source_entry); |
68535125 | 221 | |
6fd195d7 VM |
222 | /** |
223 | * Get a pointer to one of the entries in the index | |
224 | * | |
225 | * This entry can be modified, and the changes will be written | |
226 | * back to disk on the next write() call. | |
227 | * | |
228 | * @param index an existing index object | |
229 | * @param n the position of the entry | |
230 | * @return a pointer to the entry; NULL if out of bounds | |
231 | */ | |
232 | GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, int n); | |
233 | ||
0be42199 SC |
234 | /** |
235 | * Get the count of entries currently in the index | |
236 | * | |
237 | * @param index an existing index object | |
238 | * @return integer of count of current entries | |
239 | */ | |
240 | GIT_EXTERN(unsigned int) git_index_entrycount(git_index *index); | |
241 | ||
4c0b6a6d JP |
242 | /** |
243 | * Get the count of unmerged entries currently in the index | |
244 | * | |
245 | * @param index an existing index object | |
246 | * @return integer of count of current unmerged entries | |
247 | */ | |
248 | GIT_EXTERN(unsigned int) git_index_unmerged_entrycount(git_index *index); | |
249 | ||
250 | /** | |
251 | * Get an unmerged entry from the index. | |
252 | * | |
253 | * @param entry the pointer to the new unmerged entry | |
254 | * @param index an existing index object | |
255 | * @param path path to search | |
256 | * @return 0 on success, otherwise an error code | |
257 | */ | |
258 | GIT_EXTERN(int) git_index_get_unmerged(git_index_entry_unmerged **entry, git_index *index, const char *path); | |
259 | ||
6fd195d7 | 260 | |
68535125 VM |
261 | /** @} */ |
262 | GIT_END_DECL | |
263 | #endif |