]>
Commit | Line | Data |
---|---|---|
e83c5163 LT |
1 | #ifndef CACHE_H |
2 | #define CACHE_H | |
3 | ||
4050c0df | 4 | #include "git-compat-util.h" |
5ecd293d | 5 | #include "strbuf.h" |
e05881a4 | 6 | #include "hashmap.h" |
65784830 | 7 | #include "gettext.h" |
155ef25f | 8 | #include "string-list.h" |
ac48adf4 | 9 | #include "pathspec.h" |
a64215b6 | 10 | #include "object.h" |
ac48adf4 | 11 | #include "statinfo.h" |
e83c5163 | 12 | |
e83c5163 LT |
13 | /* |
14 | * Basic data structures for the directory cache | |
e83c5163 LT |
15 | */ |
16 | ||
17 | #define CACHE_SIGNATURE 0x44495243 /* "DIRC" */ | |
18 | struct cache_header { | |
7800c1eb TG |
19 | uint32_t hdr_signature; |
20 | uint32_t hdr_version; | |
21 | uint32_t hdr_entries; | |
e83c5163 LT |
22 | }; |
23 | ||
9d227781 JH |
24 | #define INDEX_FORMAT_LB 2 |
25 | #define INDEX_FORMAT_UB 4 | |
26 | ||
e83c5163 | 27 | struct cache_entry { |
8b013788 | 28 | struct hashmap_entry ent; |
c21d39d7 | 29 | struct stat_data ce_stat_data; |
ccc4feb5 | 30 | unsigned int ce_mode; |
7a51ed66 | 31 | unsigned int ce_flags; |
8e72d675 | 32 | unsigned int mem_pool_allocated; |
b60e188c | 33 | unsigned int ce_namelen; |
5fc2fc8f | 34 | unsigned int index; /* for link extension */ |
99d1a986 | 35 | struct object_id oid; |
8f1d2e6f | 36 | char name[FLEX_ARRAY]; /* more */ |
e83c5163 LT |
37 | }; |
38 | ||
95fd5bf8 | 39 | #define CE_STAGEMASK (0x3000) |
16ce2e4c | 40 | #define CE_EXTENDED (0x4000) |
5f73076c | 41 | #define CE_VALID (0x8000) |
aee46198 | 42 | #define CE_STAGESHIFT 12 |
95fd5bf8 | 43 | |
06aaaa0b | 44 | /* |
ce51bf09 | 45 | * Range 0xFFFF0FFF in ce_flags is divided into |
06aaaa0b NTND |
46 | * two parts: in-memory flags and on-disk ones. |
47 | * Flags in CE_EXTENDED_FLAGS will get saved on-disk | |
48 | * if you want to save a new flag, add it in | |
49 | * CE_EXTENDED_FLAGS | |
50 | * | |
51 | * In-memory only flags | |
52 | */ | |
2977ffbb NTND |
53 | #define CE_UPDATE (1 << 16) |
54 | #define CE_REMOVE (1 << 17) | |
55 | #define CE_UPTODATE (1 << 18) | |
56 | #define CE_ADDED (1 << 19) | |
a22c6371 | 57 | |
2977ffbb | 58 | #define CE_HASHED (1 << 20) |
883e248b | 59 | #define CE_FSMONITOR_VALID (1 << 21) |
2977ffbb NTND |
60 | #define CE_WT_REMOVE (1 << 22) /* remove in work directory */ |
61 | #define CE_CONFLICTED (1 << 23) | |
7a51ed66 | 62 | |
2977ffbb | 63 | #define CE_UNPACKED (1 << 24) |
2431afbf | 64 | #define CE_NEW_SKIP_WORKTREE (1 << 25) |
da165f47 | 65 | |
e721c154 NTND |
66 | /* used to temporarily mark paths matched by pathspecs */ |
67 | #define CE_MATCHED (1 << 26) | |
68 | ||
078a58e8 | 69 | #define CE_UPDATE_IN_BASE (1 << 27) |
b3c96fb1 | 70 | #define CE_STRIP_NAME (1 << 28) |
078a58e8 | 71 | |
06aaaa0b NTND |
72 | /* |
73 | * Extended on-disk flags | |
74 | */ | |
2977ffbb NTND |
75 | #define CE_INTENT_TO_ADD (1 << 29) |
76 | #define CE_SKIP_WORKTREE (1 << 30) | |
06aaaa0b | 77 | /* CE_EXTENDED2 is for future extension */ |
9a93c668 | 78 | #define CE_EXTENDED2 (1U << 31) |
06aaaa0b | 79 | |
44a36913 | 80 | #define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE) |
06aaaa0b NTND |
81 | |
82 | /* | |
83 | * Safeguard to avoid saving wrong flags: | |
84 | * - CE_EXTENDED2 won't get saved until its semantic is known | |
85 | * - Bits in 0x0000FFFF have been saved in ce_flags already | |
86 | * - Bits in 0x003F0000 are currently in-memory flags | |
87 | */ | |
88 | #if CE_EXTENDED_FLAGS & 0x803FFFFF | |
89 | #error "CE_EXTENDED_FLAGS out of range" | |
90 | #endif | |
91 | ||
3e3a4a41 | 92 | /* Forward structure decls */ |
64acde94 | 93 | struct pathspec; |
e1f8694f | 94 | struct tree; |
64acde94 | 95 | |
eb7a2f1d LT |
96 | /* |
97 | * Copy the sha1 and stat state of a cache entry from one to | |
98 | * another. But we never change the name, or the hash state! | |
99 | */ | |
20d142b4 RS |
100 | static inline void copy_cache_entry(struct cache_entry *dst, |
101 | const struct cache_entry *src) | |
eb7a2f1d | 102 | { |
419a597f | 103 | unsigned int state = dst->ce_flags & CE_HASHED; |
8e72d675 | 104 | int mem_pool_allocated = dst->mem_pool_allocated; |
eb7a2f1d LT |
105 | |
106 | /* Don't copy hash chain and name */ | |
8b013788 KB |
107 | memcpy(&dst->ce_stat_data, &src->ce_stat_data, |
108 | offsetof(struct cache_entry, name) - | |
109 | offsetof(struct cache_entry, ce_stat_data)); | |
eb7a2f1d LT |
110 | |
111 | /* Restore the hash state */ | |
419a597f | 112 | dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state; |
8e72d675 JM |
113 | |
114 | /* Restore the mem_pool_allocated flag */ | |
115 | dst->mem_pool_allocated = mem_pool_allocated; | |
eb7a2f1d LT |
116 | } |
117 | ||
b60e188c | 118 | static inline unsigned create_ce_flags(unsigned stage) |
7fec10b7 | 119 | { |
b60e188c | 120 | return (stage << CE_STAGESHIFT); |
7fec10b7 JH |
121 | } |
122 | ||
b60e188c | 123 | #define ce_namelen(ce) ((ce)->ce_namelen) |
aee46198 | 124 | #define ce_size(ce) cache_entry_size(ce_namelen(ce)) |
7a51ed66 | 125 | #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT) |
eadb5831 | 126 | #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE) |
44a36913 | 127 | #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE) |
eadb5831 | 128 | #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE) |
895ff3b2 | 129 | #define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD) |
aee46198 | 130 | |
20d142b4 RS |
131 | static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce, |
132 | unsigned int mode) | |
185c975f | 133 | { |
78a8d641 JS |
134 | extern int trust_executable_bit, has_symlinks; |
135 | if (!has_symlinks && S_ISREG(mode) && | |
7a51ed66 | 136 | ce && S_ISLNK(ce->ce_mode)) |
78a8d641 | 137 | return ce->ce_mode; |
185c975f | 138 | if (!trust_executable_bit && S_ISREG(mode)) { |
7a51ed66 | 139 | if (ce && S_ISREG(ce->ce_mode)) |
185c975f JH |
140 | return ce->ce_mode; |
141 | return create_ce_mode(0666); | |
142 | } | |
143 | return create_ce_mode(mode); | |
144 | } | |
d6b8fc30 JH |
145 | static inline int ce_to_dtype(const struct cache_entry *ce) |
146 | { | |
147 | unsigned ce_mode = ntohl(ce->ce_mode); | |
148 | if (S_ISREG(ce_mode)) | |
149 | return DT_REG; | |
150 | else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode)) | |
151 | return DT_DIR; | |
152 | else if (S_ISLNK(ce_mode)) | |
153 | return DT_LNK; | |
154 | else | |
155 | return DT_UNKNOWN; | |
156 | } | |
e4479470 | 157 | |
ac48adf4 EN |
158 | static inline int ce_path_match(struct index_state *istate, |
159 | const struct cache_entry *ce, | |
160 | const struct pathspec *pathspec, | |
161 | char *seen) | |
162 | { | |
163 | return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen, | |
164 | S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)); | |
165 | } | |
166 | ||
ee7825b5 | 167 | #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) |
f5cabd13 | 168 | |
e636a7b4 NTND |
169 | #define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */ |
170 | #define CE_ENTRY_CHANGED (1 << 1) | |
171 | #define CE_ENTRY_REMOVED (1 << 2) | |
172 | #define CE_ENTRY_ADDED (1 << 3) | |
6c306a34 | 173 | #define RESOLVE_UNDO_CHANGED (1 << 4) |
a5400efe | 174 | #define CACHE_TREE_CHANGED (1 << 5) |
c18b80a0 | 175 | #define SPLIT_INDEX_ORDERED (1 << 6) |
1bbb3dba | 176 | #define UNTRACKED_CHANGED (1 << 7) |
883e248b | 177 | #define FSMONITOR_CHANGED (1 << 8) |
e636a7b4 | 178 | |
5fc2fc8f | 179 | struct split_index; |
83c094ad | 180 | struct untracked_cache; |
4dcd4def | 181 | struct progress; |
836e25c5 | 182 | struct pattern_list; |
83c094ad | 183 | |
9fadb373 DS |
184 | enum sparse_index_mode { |
185 | /* | |
186 | * There are no sparse directories in the index at all. | |
187 | * | |
188 | * Repositories that don't use cone-mode sparse-checkout will | |
189 | * always have their indexes in this mode. | |
190 | */ | |
191 | INDEX_EXPANDED = 0, | |
192 | ||
193 | /* | |
194 | * The index has already been collapsed to sparse directories | |
195 | * whereever possible. | |
196 | */ | |
197 | INDEX_COLLAPSED, | |
198 | ||
199 | /* | |
200 | * The sparse directories that exist are outside the | |
201 | * sparse-checkout boundary, but it is possible that some file | |
202 | * entries could collapse to sparse directory entries. | |
203 | */ | |
204 | INDEX_PARTIALLY_SPARSE, | |
205 | }; | |
206 | ||
228e94f9 JH |
207 | struct index_state { |
208 | struct cache_entry **cache; | |
9d227781 | 209 | unsigned int version; |
228e94f9 | 210 | unsigned int cache_nr, cache_alloc, cache_changed; |
cfc5789a | 211 | struct string_list *resolve_undo; |
228e94f9 | 212 | struct cache_tree *cache_tree; |
5fc2fc8f | 213 | struct split_index *split_index; |
fba2f38a | 214 | struct cache_time timestamp; |
913e0e99 | 215 | unsigned name_hash_initialized : 1, |
4bddd983 | 216 | initialized : 1, |
1956ecd0 BP |
217 | drop_cache_tree : 1, |
218 | updated_workdir : 1, | |
cfd635c7 | 219 | updated_skipworktree : 1, |
9fadb373 DS |
220 | fsmonitor_has_run_once : 1; |
221 | enum sparse_index_mode sparse_index; | |
8b013788 | 222 | struct hashmap name_hash; |
e05881a4 | 223 | struct hashmap dir_hash; |
75691ea3 | 224 | struct object_id oid; |
83c094ad | 225 | struct untracked_cache *untracked; |
56c69100 | 226 | char *fsmonitor_last_update; |
ba1b9cac | 227 | struct ewah_bitmap *fsmonitor_dirty; |
8e72d675 | 228 | struct mem_pool *ce_mem_pool; |
4dcd4def | 229 | struct progress *progress; |
1fd9ae51 | 230 | struct repository *repo; |
836e25c5 | 231 | struct pattern_list *sparse_checkout_patterns; |
228e94f9 JH |
232 | }; |
233 | ||
2f6b1eb7 ÆAB |
234 | /** |
235 | * A "struct index_state istate" must be initialized with | |
236 | * INDEX_STATE_INIT or the corresponding index_state_init(). | |
237 | * | |
238 | * If the variable won't be used again, use release_index() to free() | |
239 | * its resources. If it needs to be used again use discard_index(), | |
240 | * which does the same thing, but will use use index_state_init() at | |
6269f8ea ÆAB |
241 | * the end. The discard_index() will use its own "istate->repo" as the |
242 | * "r" argument to index_state_init() in that case. | |
2f6b1eb7 | 243 | */ |
6269f8ea ÆAB |
244 | #define INDEX_STATE_INIT(r) { \ |
245 | .repo = (r), \ | |
246 | } | |
247 | void index_state_init(struct index_state *istate, struct repository *r); | |
2f6b1eb7 ÆAB |
248 | void release_index(struct index_state *istate); |
249 | ||
96872bc2 | 250 | /* Name hashing */ |
55454427 DL |
251 | int test_lazy_init_name_hash(struct index_state *istate, int try_threaded); |
252 | void add_name_hash(struct index_state *istate, struct cache_entry *ce); | |
253 | void remove_name_hash(struct index_state *istate, struct cache_entry *ce); | |
254 | void free_name_hash(struct index_state *istate); | |
96872bc2 | 255 | |
a849735b JM |
256 | /* Cache entry creation and cleanup */ |
257 | ||
258 | /* | |
259 | * Create cache_entry intended for use in the specified index. Caller | |
260 | * is responsible for discarding the cache_entry with | |
261 | * `discard_cache_entry`. | |
262 | */ | |
263 | struct cache_entry *make_cache_entry(struct index_state *istate, | |
264 | unsigned int mode, | |
265 | const struct object_id *oid, | |
266 | const char *path, | |
267 | int stage, | |
268 | unsigned int refresh_options); | |
269 | ||
270 | struct cache_entry *make_empty_cache_entry(struct index_state *istate, | |
271 | size_t name_len); | |
272 | ||
273 | /* | |
96168827 MT |
274 | * Create a cache_entry that is not intended to be added to an index. If |
275 | * `ce_mem_pool` is not NULL, the entry is allocated within the given memory | |
276 | * pool. Caller is responsible for discarding "loose" entries with | |
277 | * `discard_cache_entry()` and the memory pool with | |
278 | * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`. | |
a849735b JM |
279 | */ |
280 | struct cache_entry *make_transient_cache_entry(unsigned int mode, | |
281 | const struct object_id *oid, | |
282 | const char *path, | |
96168827 MT |
283 | int stage, |
284 | struct mem_pool *ce_mem_pool); | |
a849735b | 285 | |
96168827 MT |
286 | struct cache_entry *make_empty_transient_cache_entry(size_t len, |
287 | struct mem_pool *ce_mem_pool); | |
a849735b JM |
288 | |
289 | /* | |
290 | * Discard cache entry. | |
291 | */ | |
292 | void discard_cache_entry(struct cache_entry *ce); | |
293 | ||
8616a2d0 JM |
294 | /* |
295 | * Check configuration if we should perform extra validation on cache | |
296 | * entries. | |
297 | */ | |
298 | int should_validate_cache_entries(void); | |
299 | ||
8e72d675 JM |
300 | /* |
301 | * Duplicate a cache_entry. Allocate memory for the new entry from a | |
302 | * memory_pool. Takes into account cache_entry fields that are meant | |
303 | * for managing the underlying memory allocation of the cache_entry. | |
304 | */ | |
305 | struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate); | |
306 | ||
307 | /* | |
308 | * Validate the cache entries in the index. This is an internal | |
309 | * consistency check that the cache_entry structs are allocated from | |
310 | * the expected memory pool. | |
311 | */ | |
312 | void validate_cache_entries(const struct index_state *istate); | |
313 | ||
b2896d27 JT |
314 | /* |
315 | * Bulk prefetch all missing cache entries that are not GITLINKs and that match | |
316 | * the given predicate. This function should only be called if | |
c7c33f50 | 317 | * repo_has_promisor_remote() returns true. |
b2896d27 JT |
318 | */ |
319 | typedef int (*must_prefetch_predicate)(const struct cache_entry *); | |
320 | void prefetch_cache_entries(const struct index_state *istate, | |
321 | must_prefetch_predicate must_prefetch); | |
322 | ||
dfd0a893 | 323 | #ifdef USE_THE_INDEX_VARIABLE |
f8adbec9 | 324 | extern struct index_state the_index; |
666f53eb | 325 | #endif |
e83c5163 | 326 | |
f225aeb2 | 327 | #define INIT_DB_QUIET 0x0001 |
33158701 | 328 | #define INIT_DB_EXIST_OK 0x0002 |
f225aeb2 | 329 | |
55454427 | 330 | int init_db(const char *git_dir, const char *real_git_dir, |
8b8f7189 | 331 | const char *template_dir, int hash_algo, |
32ba12da | 332 | const char *initial_branch, unsigned int flags); |
47ac9703 | 333 | void initialize_repository_version(int hash_algo, int reinit); |
f225aeb2 | 334 | |
734aab75 | 335 | /* Initialize and use the cache information */ |
03b86647 | 336 | struct lock_file; |
55454427 | 337 | void preload_index(struct index_state *index, |
ad6dad09 DL |
338 | const struct pathspec *pathspec, |
339 | unsigned int refresh_flags); | |
55454427 | 340 | int do_read_index(struct index_state *istate, const char *path, |
ad6dad09 | 341 | int must_exist); /* for testting only! */ |
55454427 | 342 | int read_index_from(struct index_state *, const char *path, |
ad6dad09 | 343 | const char *gitdir); |
55454427 | 344 | int is_index_unborn(struct index_state *); |
8dc38346 | 345 | |
4300f844 DS |
346 | void ensure_full_index(struct index_state *istate); |
347 | ||
8dc38346 | 348 | /* For use with `write_locked_index()`. */ |
03b86647 | 349 | #define COMMIT_LOCK (1 << 0) |
61000814 | 350 | #define SKIP_IF_UNCHANGED (1 << 1) |
8dc38346 MÅ |
351 | |
352 | /* | |
812d6b00 MÅ |
353 | * Write the index while holding an already-taken lock. Close the lock, |
354 | * and if `COMMIT_LOCK` is given, commit it. | |
8dc38346 MÅ |
355 | * |
356 | * Unless a split index is in use, write the index into the lockfile. | |
357 | * | |
358 | * With a split index, write the shared index to a temporary file, | |
359 | * adjust its permissions and rename it into place, then write the | |
360 | * split index to the lockfile. If the temporary file for the shared | |
361 | * index cannot be created, fall back to the behavior described in | |
362 | * the previous paragraph. | |
df60cf57 MÅ |
363 | * |
364 | * With `COMMIT_LOCK`, the lock is always committed or rolled back. | |
365 | * Without it, the lock is closed, but neither committed nor rolled | |
366 | * back. | |
61000814 MÅ |
367 | * |
368 | * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing | |
369 | * is written (and the lock is rolled back if `COMMIT_LOCK` is given). | |
8dc38346 | 370 | */ |
55454427 | 371 | int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags); |
8dc38346 | 372 | |
9c5f3ee3 | 373 | void discard_index(struct index_state *); |
55454427 DL |
374 | void move_index_extensions(struct index_state *dst, struct index_state *src); |
375 | int unmerged_index(const struct index_state *); | |
b101793c EN |
376 | |
377 | /** | |
e1f8694f EN |
378 | * Returns 1 if istate differs from tree, 0 otherwise. If tree is NULL, |
379 | * compares istate to HEAD. If tree is NULL and on an unborn branch, | |
380 | * returns 1 if there are entries in istate, 0 otherwise. If an strbuf is | |
381 | * provided, the space-separated list of files that differ will be appended | |
382 | * to it. | |
b101793c | 383 | */ |
55454427 | 384 | int repo_index_has_changes(struct repository *repo, |
ad6dad09 DL |
385 | struct tree *tree, |
386 | struct strbuf *sb); | |
b101793c | 387 | |
55454427 DL |
388 | int verify_path(const char *path, unsigned mode); |
389 | int strcmp_offset(const char *s1, const char *s2, size_t *first_change); | |
390 | int index_dir_exists(struct index_state *istate, const char *name, int namelen); | |
391 | void adjust_dirname_case(struct index_state *istate, char *name); | |
392 | struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase); | |
12733e9d SB |
393 | |
394 | /* | |
395 | * Searches for an entry defined by name and namelen in the given index. | |
396 | * If the return value is positive (including 0) it is the position of an | |
397 | * exact match. If the return value is negative, the negated value minus 1 | |
398 | * is the position where the entry would be inserted. | |
399 | * Example: The current index consists of these files and its stages: | |
400 | * | |
401 | * b#0, d#0, f#1, f#3 | |
402 | * | |
403 | * index_name_pos(&index, "a", 1) -> -1 | |
404 | * index_name_pos(&index, "b", 1) -> 0 | |
405 | * index_name_pos(&index, "c", 1) -> -2 | |
406 | * index_name_pos(&index, "d", 1) -> 1 | |
407 | * index_name_pos(&index, "e", 1) -> -3 | |
408 | * index_name_pos(&index, "f", 1) -> -3 | |
409 | * index_name_pos(&index, "g", 1) -> -5 | |
410 | */ | |
847a9e5d | 411 | int index_name_pos(struct index_state *, const char *name, int namelen); |
12733e9d | 412 | |
9553aa0f VD |
413 | /* |
414 | * Like index_name_pos, returns the position of an entry of the given name in | |
415 | * the index if one exists, otherwise returns a negative value where the negated | |
416 | * value minus 1 is the position where the index entry would be inserted. Unlike | |
417 | * index_name_pos, however, a sparse index is not expanded to find an entry | |
418 | * inside a sparse directory. | |
419 | */ | |
420 | int index_name_pos_sparse(struct index_state *, const char *name, int namelen); | |
421 | ||
20ec2d03 VD |
422 | /* |
423 | * Determines whether an entry with the given name exists within the | |
424 | * given index. The return value is 1 if an exact match is found, otherwise | |
425 | * it is 0. Note that, unlike index_name_pos, this function does not expand | |
426 | * the index if it is sparse. If an item exists within the full index but it | |
427 | * is contained within a sparse directory (and not in the sparse index), 0 is | |
428 | * returned. | |
429 | */ | |
430 | int index_entry_exists(struct index_state *, const char *name, int namelen); | |
431 | ||
c097b95a JS |
432 | /* |
433 | * Some functions return the negative complement of an insert position when a | |
434 | * precise match was not found but a position was found where the entry would | |
435 | * need to be inserted. This helper protects that logic from any integer | |
436 | * underflow. | |
437 | */ | |
438 | static inline int index_pos_to_insert_pos(uintmax_t pos) | |
439 | { | |
440 | if (pos > INT_MAX) | |
441 | die("overflow: -1 - %"PRIuMAX, pos); | |
442 | return -1 - (int)pos; | |
443 | } | |
444 | ||
192268c1 JH |
445 | #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ |
446 | #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ | |
b155725d | 447 | #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ |
eefadd18 | 448 | #define ADD_CACHE_JUST_APPEND 8 /* Append only */ |
39425819 | 449 | #define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */ |
ce7c614b | 450 | #define ADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */ |
9e5da3d0 | 451 | #define ADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */ |
55454427 DL |
452 | int add_index_entry(struct index_state *, struct cache_entry *ce, int option); |
453 | void rename_index_entry_at(struct index_state *, int pos, const char *new_name); | |
3bd72adf SB |
454 | |
455 | /* Remove entry, return true if there are more entries to go. */ | |
55454427 | 456 | int remove_index_entry_at(struct index_state *, int pos); |
3bd72adf | 457 | |
55454427 DL |
458 | void remove_marked_cache_entries(struct index_state *istate, int invalidate); |
459 | int remove_file_from_index(struct index_state *, const char *path); | |
38ed1d89 JH |
460 | #define ADD_CACHE_VERBOSE 1 |
461 | #define ADD_CACHE_PRETEND 2 | |
01665924 | 462 | #define ADD_CACHE_IGNORE_ERRORS 4 |
041aee31 | 463 | #define ADD_CACHE_IGNORE_REMOVAL 8 |
39425819 | 464 | #define ADD_CACHE_INTENT 16 |
20cf41d0 SB |
465 | /* |
466 | * These two are used to add the contents of the file at path | |
467 | * to the index, marking the working tree up-to-date by storing | |
468 | * the cached stat info in the resulting cache entry. A caller | |
469 | * that has already run lstat(2) on the path can call | |
470 | * add_to_index(), and all others can call add_file_to_index(); | |
471 | * the latter will do necessary lstat(2) internally before | |
472 | * calling the former. | |
473 | */ | |
55454427 DL |
474 | int add_to_index(struct index_state *, const char *path, struct stat *, int flags); |
475 | int add_file_to_index(struct index_state *, const char *path, int flags); | |
20cf41d0 | 476 | |
55454427 DL |
477 | int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip); |
478 | int ce_same_name(const struct cache_entry *a, const struct cache_entry *b); | |
479 | void set_object_name_for_intent_to_add_entry(struct cache_entry *ce); | |
847a9e5d DS |
480 | int index_name_is_other(struct index_state *, const char *, int); |
481 | void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *); | |
4bd5b7da JH |
482 | |
483 | /* do stat comparison even if CE_VALID is true */ | |
484 | #define CE_MATCH_IGNORE_VALID 01 | |
485 | /* do not check the contents but report dirty on racily-clean entries */ | |
56cac48c NTND |
486 | #define CE_MATCH_RACY_IS_DIRTY 02 |
487 | /* do stat comparison even if CE_SKIP_WORKTREE is true */ | |
488 | #define CE_MATCH_IGNORE_SKIP_WORKTREE 04 | |
2e2e7ec1 BK |
489 | /* ignore non-existent files during stat update */ |
490 | #define CE_MATCH_IGNORE_MISSING 0x08 | |
25762726 BK |
491 | /* enable stat refresh */ |
492 | #define CE_MATCH_REFRESH 0x10 | |
883e248b BP |
493 | /* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */ |
494 | #define CE_MATCH_IGNORE_FSMONITOR 0X20 | |
55454427 | 495 | int is_racy_timestamp(const struct index_state *istate, |
ad6dad09 | 496 | const struct cache_entry *ce); |
2ede073f | 497 | int has_racy_timestamp(struct index_state *istate); |
55454427 DL |
498 | int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int); |
499 | int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int); | |
4bd5b7da | 500 | |
c21d39d7 MH |
501 | /* |
502 | * Record to sd the data from st that we use to check whether a file | |
503 | * might have changed. | |
504 | */ | |
55454427 | 505 | void fill_stat_data(struct stat_data *sd, struct stat *st); |
c21d39d7 MH |
506 | |
507 | /* | |
508 | * Return 0 if st is consistent with a file not having been changed | |
509 | * since sd was filled. If there are differences, return a | |
510 | * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED, | |
511 | * INODE_CHANGED, and DATA_CHANGED. | |
512 | */ | |
55454427 DL |
513 | int match_stat_data(const struct stat_data *sd, struct stat *st); |
514 | int match_stat_data_racy(const struct index_state *istate, | |
ad6dad09 | 515 | const struct stat_data *sd, struct stat *st); |
c21d39d7 | 516 | |
d4c0a3ac | 517 | void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st); |
415e96c8 | 518 | |
b243012c MT |
519 | #define REFRESH_REALLY (1 << 0) /* ignore_valid */ |
520 | #define REFRESH_UNMERGED (1 << 1) /* allow unmerged */ | |
521 | #define REFRESH_QUIET (1 << 2) /* be quiet about it */ | |
522 | #define REFRESH_IGNORE_MISSING (1 << 3) /* ignore non-existent */ | |
523 | #define REFRESH_IGNORE_SUBMODULES (1 << 4) /* ignore submodules */ | |
524 | #define REFRESH_IN_PORCELAIN (1 << 5) /* user friendly output, not "needs update" */ | |
525 | #define REFRESH_PROGRESS (1 << 6) /* show progress bar if stderr is tty */ | |
526 | #define REFRESH_IGNORE_SKIP_WORKTREE (1 << 7) /* ignore skip_worktree entries */ | |
55454427 | 527 | int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg); |
22184497 TG |
528 | /* |
529 | * Refresh the index and write it to disk. | |
530 | * | |
531 | * 'refresh_flags' is passed directly to 'refresh_index()', while | |
532 | * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so | |
533 | * the lockfile is always either committed or rolled back. | |
534 | * | |
535 | * If 'gentle' is passed, errors locking the index are ignored. | |
536 | * | |
537 | * Return 1 if refreshing the index returns an error, -1 if writing | |
538 | * the index to disk fails, 0 on success. | |
539 | * | |
540 | * Note that if refreshing the index returns an error, we still write | |
541 | * out the index (unless locking fails). | |
542 | */ | |
543 | int repo_refresh_and_write_index(struct repository*, unsigned int refresh_flags, unsigned int write_flags, int gentle, const struct pathspec *, char *seen, const char *header_msg); | |
544 | ||
55454427 | 545 | struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int); |
405e5b2f | 546 | |
55454427 | 547 | void set_alternate_index_output(const char *); |
697cc8ef | 548 | |
a33fc72f | 549 | extern int verify_index_checksum; |
00ec50e5 | 550 | extern int verify_ce_order; |
a33fc72f | 551 | |
734aab75 LT |
552 | #define MTIME_CHANGED 0x0001 |
553 | #define CTIME_CHANGED 0x0002 | |
554 | #define OWNER_CHANGED 0x0004 | |
555 | #define MODE_CHANGED 0x0008 | |
556 | #define INODE_CHANGED 0x0010 | |
557 | #define DATA_CHANGED 0x0020 | |
8ae0a8c5 | 558 | #define TYPE_CHANGED 0x0040 |
e83c5163 | 559 | |
1b4a38d7 RS |
560 | int base_name_compare(const char *name1, size_t len1, int mode1, |
561 | const char *name2, size_t len2, int mode2); | |
562 | int df_name_compare(const char *name1, size_t len1, int mode1, | |
563 | const char *name2, size_t len2, int mode2); | |
55454427 DL |
564 | int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); |
565 | int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); | |
e83c5163 | 566 | |
b6ec1d61 | 567 | /* add */ |
7ae02a30 AR |
568 | /* |
569 | * return 0 if success, 1 - if addition of a file failed and | |
570 | * ADD_FILES_IGNORE_ERRORS was specified in flags | |
571 | */ | |
610d55af | 572 | int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags); |
b6ec1d61 | 573 | |
aecbf914 JH |
574 | /* diff.c */ |
575 | extern int diff_auto_refresh_index; | |
576 | ||
ee425e46 | 577 | /* ls-files */ |
312c984a BW |
578 | void overlay_tree_on_index(struct index_state *istate, |
579 | const char *tree_name, const char *prefix); | |
ee425e46 | 580 | |
db699a8a NTND |
581 | /* merge.c */ |
582 | struct commit_list; | |
7e196c3a NTND |
583 | int try_merge_command(struct repository *r, |
584 | const char *strategy, size_t xopts_nr, | |
db699a8a NTND |
585 | const char **xopts, struct commit_list *common, |
586 | const char *head_arg, struct commit_list *remotes); | |
7e196c3a NTND |
587 | int checkout_fast_forward(struct repository *r, |
588 | const struct object_id *from, | |
f06e90da | 589 | const struct object_id *to, |
db699a8a NTND |
590 | int overwrite_ignore); |
591 | ||
cac42b26 | 592 | |
38f865c2 JK |
593 | int sane_execvp(const char *file, char *const argv[]); |
594 | ||
38612532 MH |
595 | /* |
596 | * A struct to encapsulate the concept of whether a file has changed | |
597 | * since we last checked it. This uses criteria similar to those used | |
598 | * for the index. | |
599 | */ | |
600 | struct stat_validity { | |
601 | struct stat_data *sd; | |
602 | }; | |
603 | ||
604 | void stat_validity_clear(struct stat_validity *sv); | |
605 | ||
606 | /* | |
607 | * Returns 1 if the path is a regular file (or a symlink to a regular | |
608 | * file) and matches the saved stat_validity, 0 otherwise. A missing | |
609 | * or inaccessible file is considered a match if the struct was just | |
610 | * initialized, or if the previous update found an inaccessible file. | |
611 | */ | |
612 | int stat_validity_check(struct stat_validity *sv, const char *path); | |
613 | ||
614 | /* | |
615 | * Update the stat_validity from a file opened at descriptor fd. If | |
616 | * the file is missing, inaccessible, or not a regular file, then | |
617 | * future calls to stat_validity_check will match iff one of those | |
618 | * conditions continues to be true. | |
619 | */ | |
620 | void stat_validity_update(struct stat_validity *sv, int fd); | |
621 | ||
e83c5163 | 622 | #endif /* CACHE_H */ |