]>
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" |
ec2dd32c | 7 | #include "list.h" |
75194438 | 8 | #include "advice.h" |
65784830 | 9 | #include "gettext.h" |
d1bf0e08 | 10 | #include "convert.h" |
5991a55c | 11 | #include "trace.h" |
ee4512ed | 12 | #include "trace2.h" |
155ef25f | 13 | #include "string-list.h" |
f4015337 | 14 | #include "pack-revindex.h" |
f18f816c | 15 | #include "hash.h" |
e7d72d07 | 16 | #include "path.h" |
ac48adf4 | 17 | #include "pathspec.h" |
a64215b6 | 18 | #include "object.h" |
fe299ec5 | 19 | #include "oid-array.h" |
78a67668 | 20 | #include "repository.h" |
ac48adf4 | 21 | #include "statinfo.h" |
8e72d675 | 22 | #include "mem-pool.h" |
e83c5163 | 23 | |
ef49a7a0 JH |
24 | typedef struct git_zstream { |
25 | z_stream z; | |
26 | unsigned long avail_in; | |
27 | unsigned long avail_out; | |
28 | unsigned long total_in; | |
29 | unsigned long total_out; | |
30 | unsigned char *next_in; | |
31 | unsigned char *next_out; | |
32 | } git_zstream; | |
33 | ||
34 | void git_inflate_init(git_zstream *); | |
35 | void git_inflate_init_gzip_only(git_zstream *); | |
36 | void git_inflate_end(git_zstream *); | |
37 | int git_inflate(git_zstream *, int flush); | |
38 | ||
39 | void git_deflate_init(git_zstream *, int level); | |
40 | void git_deflate_init_gzip(git_zstream *, int level); | |
c3c2e1a0 | 41 | void git_deflate_init_raw(git_zstream *, int level); |
ef49a7a0 | 42 | void git_deflate_end(git_zstream *); |
568508e7 | 43 | int git_deflate_abort(git_zstream *); |
ef49a7a0 JH |
44 | int git_deflate_end_gently(git_zstream *); |
45 | int git_deflate(git_zstream *, int flush); | |
46 | unsigned long git_deflate_bound(git_zstream *, unsigned long); | |
39c68542 | 47 | |
962554c6 | 48 | #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT) |
b6829693 ET |
49 | #define DTYPE(de) ((de)->d_type) |
50 | #else | |
0bdd79af JH |
51 | #undef DT_UNKNOWN |
52 | #undef DT_DIR | |
53 | #undef DT_REG | |
54 | #undef DT_LNK | |
b6829693 ET |
55 | #define DT_UNKNOWN 0 |
56 | #define DT_DIR 1 | |
57 | #define DT_REG 2 | |
a15c1c60 | 58 | #define DT_LNK 3 |
b6829693 ET |
59 | #define DTYPE(de) DT_UNKNOWN |
60 | #endif | |
61 | ||
40689ae1 MK |
62 | /* unknown mode (impossible combination S_IFIFO|S_IFCHR) */ |
63 | #define S_IFINVALID 0030000 | |
64 | ||
9eec4795 LT |
65 | /* |
66 | * A "directory link" is a link to another git directory. | |
67 | * | |
68 | * The value 0160000 is not normally a valid mode, and | |
69 | * also just happens to be S_IFDIR + S_IFLNK | |
9eec4795 | 70 | */ |
302b9282 MW |
71 | #define S_IFGITLINK 0160000 |
72 | #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) | |
9eec4795 | 73 | |
72441af7 KS |
74 | /* |
75 | * Some mode bits are also used internally for computations. | |
76 | * | |
77 | * They *must* not overlap with any valid modes, and they *must* not be emitted | |
78 | * to outside world - i.e. appear on disk or network. In other words, it's just | |
79 | * temporary fields, which we internally use, but they have to stay in-house. | |
80 | * | |
81 | * ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git | |
82 | * codebase mode is `unsigned int` which is assumed to be at least 32 bits ) | |
83 | */ | |
84 | ||
85 | /* used internally in tree-diff */ | |
86 | #define S_DIFFTREE_IFXMIN_NEQ 0x80000000 | |
87 | ||
88 | ||
2386d658 LT |
89 | /* |
90 | * Intensive research over the course of many years has shown that | |
91 | * port 9418 is totally unused by anything else. Or | |
92 | * | |
93 | * Your search - "port 9418" - did not match any documents. | |
94 | * | |
95 | * as www.google.com puts it. | |
ba8a4970 LT |
96 | * |
97 | * This port has been properly assigned for git use by IANA: | |
98 | * git (Assigned-9418) [I06-050728-0001]. | |
99 | * | |
100 | * git 9418/tcp git pack transfer service | |
101 | * git 9418/udp git pack transfer service | |
102 | * | |
103 | * with Linus Torvalds <torvalds@osdl.org> as the point of | |
104 | * contact. September 2005. | |
105 | * | |
106 | * See http://www.iana.org/assignments/port-numbers | |
2386d658 LT |
107 | */ |
108 | #define DEFAULT_GIT_PORT 9418 | |
109 | ||
e83c5163 LT |
110 | /* |
111 | * Basic data structures for the directory cache | |
e83c5163 LT |
112 | */ |
113 | ||
114 | #define CACHE_SIGNATURE 0x44495243 /* "DIRC" */ | |
115 | struct cache_header { | |
7800c1eb TG |
116 | uint32_t hdr_signature; |
117 | uint32_t hdr_version; | |
118 | uint32_t hdr_entries; | |
e83c5163 LT |
119 | }; |
120 | ||
9d227781 JH |
121 | #define INDEX_FORMAT_LB 2 |
122 | #define INDEX_FORMAT_UB 4 | |
123 | ||
e83c5163 | 124 | struct cache_entry { |
8b013788 | 125 | struct hashmap_entry ent; |
c21d39d7 | 126 | struct stat_data ce_stat_data; |
ccc4feb5 | 127 | unsigned int ce_mode; |
7a51ed66 | 128 | unsigned int ce_flags; |
8e72d675 | 129 | unsigned int mem_pool_allocated; |
b60e188c | 130 | unsigned int ce_namelen; |
5fc2fc8f | 131 | unsigned int index; /* for link extension */ |
99d1a986 | 132 | struct object_id oid; |
8f1d2e6f | 133 | char name[FLEX_ARRAY]; /* more */ |
e83c5163 LT |
134 | }; |
135 | ||
95fd5bf8 | 136 | #define CE_STAGEMASK (0x3000) |
16ce2e4c | 137 | #define CE_EXTENDED (0x4000) |
5f73076c | 138 | #define CE_VALID (0x8000) |
aee46198 | 139 | #define CE_STAGESHIFT 12 |
95fd5bf8 | 140 | |
06aaaa0b | 141 | /* |
ce51bf09 | 142 | * Range 0xFFFF0FFF in ce_flags is divided into |
06aaaa0b NTND |
143 | * two parts: in-memory flags and on-disk ones. |
144 | * Flags in CE_EXTENDED_FLAGS will get saved on-disk | |
145 | * if you want to save a new flag, add it in | |
146 | * CE_EXTENDED_FLAGS | |
147 | * | |
148 | * In-memory only flags | |
149 | */ | |
2977ffbb NTND |
150 | #define CE_UPDATE (1 << 16) |
151 | #define CE_REMOVE (1 << 17) | |
152 | #define CE_UPTODATE (1 << 18) | |
153 | #define CE_ADDED (1 << 19) | |
a22c6371 | 154 | |
2977ffbb | 155 | #define CE_HASHED (1 << 20) |
883e248b | 156 | #define CE_FSMONITOR_VALID (1 << 21) |
2977ffbb NTND |
157 | #define CE_WT_REMOVE (1 << 22) /* remove in work directory */ |
158 | #define CE_CONFLICTED (1 << 23) | |
7a51ed66 | 159 | |
2977ffbb | 160 | #define CE_UNPACKED (1 << 24) |
2431afbf | 161 | #define CE_NEW_SKIP_WORKTREE (1 << 25) |
da165f47 | 162 | |
e721c154 NTND |
163 | /* used to temporarily mark paths matched by pathspecs */ |
164 | #define CE_MATCHED (1 << 26) | |
165 | ||
078a58e8 | 166 | #define CE_UPDATE_IN_BASE (1 << 27) |
b3c96fb1 | 167 | #define CE_STRIP_NAME (1 << 28) |
078a58e8 | 168 | |
06aaaa0b NTND |
169 | /* |
170 | * Extended on-disk flags | |
171 | */ | |
2977ffbb NTND |
172 | #define CE_INTENT_TO_ADD (1 << 29) |
173 | #define CE_SKIP_WORKTREE (1 << 30) | |
06aaaa0b | 174 | /* CE_EXTENDED2 is for future extension */ |
9a93c668 | 175 | #define CE_EXTENDED2 (1U << 31) |
06aaaa0b | 176 | |
44a36913 | 177 | #define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE) |
06aaaa0b NTND |
178 | |
179 | /* | |
180 | * Safeguard to avoid saving wrong flags: | |
181 | * - CE_EXTENDED2 won't get saved until its semantic is known | |
182 | * - Bits in 0x0000FFFF have been saved in ce_flags already | |
183 | * - Bits in 0x003F0000 are currently in-memory flags | |
184 | */ | |
185 | #if CE_EXTENDED_FLAGS & 0x803FFFFF | |
186 | #error "CE_EXTENDED_FLAGS out of range" | |
187 | #endif | |
188 | ||
4300f844 DS |
189 | #define S_ISSPARSEDIR(m) ((m) == S_IFDIR) |
190 | ||
3e3a4a41 | 191 | /* Forward structure decls */ |
64acde94 | 192 | struct pathspec; |
3e3a4a41 | 193 | struct child_process; |
e1f8694f | 194 | struct tree; |
64acde94 | 195 | |
eb7a2f1d LT |
196 | /* |
197 | * Copy the sha1 and stat state of a cache entry from one to | |
198 | * another. But we never change the name, or the hash state! | |
199 | */ | |
20d142b4 RS |
200 | static inline void copy_cache_entry(struct cache_entry *dst, |
201 | const struct cache_entry *src) | |
eb7a2f1d | 202 | { |
419a597f | 203 | unsigned int state = dst->ce_flags & CE_HASHED; |
8e72d675 | 204 | int mem_pool_allocated = dst->mem_pool_allocated; |
eb7a2f1d LT |
205 | |
206 | /* Don't copy hash chain and name */ | |
8b013788 KB |
207 | memcpy(&dst->ce_stat_data, &src->ce_stat_data, |
208 | offsetof(struct cache_entry, name) - | |
209 | offsetof(struct cache_entry, ce_stat_data)); | |
eb7a2f1d LT |
210 | |
211 | /* Restore the hash state */ | |
419a597f | 212 | dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state; |
8e72d675 JM |
213 | |
214 | /* Restore the mem_pool_allocated flag */ | |
215 | dst->mem_pool_allocated = mem_pool_allocated; | |
eb7a2f1d LT |
216 | } |
217 | ||
b60e188c | 218 | static inline unsigned create_ce_flags(unsigned stage) |
7fec10b7 | 219 | { |
b60e188c | 220 | return (stage << CE_STAGESHIFT); |
7fec10b7 JH |
221 | } |
222 | ||
b60e188c | 223 | #define ce_namelen(ce) ((ce)->ce_namelen) |
aee46198 | 224 | #define ce_size(ce) cache_entry_size(ce_namelen(ce)) |
7a51ed66 | 225 | #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT) |
eadb5831 | 226 | #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE) |
44a36913 | 227 | #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE) |
eadb5831 | 228 | #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE) |
895ff3b2 | 229 | #define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD) |
aee46198 | 230 | |
e4479470 | 231 | #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644) |
8ae0a8c5 KS |
232 | static inline unsigned int create_ce_mode(unsigned int mode) |
233 | { | |
8ae0a8c5 | 234 | if (S_ISLNK(mode)) |
7a51ed66 | 235 | return S_IFLNK; |
6e773527 DS |
236 | if (S_ISSPARSEDIR(mode)) |
237 | return S_IFDIR; | |
302b9282 | 238 | if (S_ISDIR(mode) || S_ISGITLINK(mode)) |
7a51ed66 LT |
239 | return S_IFGITLINK; |
240 | return S_IFREG | ce_permissions(mode); | |
8ae0a8c5 | 241 | } |
20d142b4 RS |
242 | static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce, |
243 | unsigned int mode) | |
185c975f | 244 | { |
78a8d641 JS |
245 | extern int trust_executable_bit, has_symlinks; |
246 | if (!has_symlinks && S_ISREG(mode) && | |
7a51ed66 | 247 | ce && S_ISLNK(ce->ce_mode)) |
78a8d641 | 248 | return ce->ce_mode; |
185c975f | 249 | if (!trust_executable_bit && S_ISREG(mode)) { |
7a51ed66 | 250 | if (ce && S_ISREG(ce->ce_mode)) |
185c975f JH |
251 | return ce->ce_mode; |
252 | return create_ce_mode(0666); | |
253 | } | |
254 | return create_ce_mode(mode); | |
255 | } | |
d6b8fc30 JH |
256 | static inline int ce_to_dtype(const struct cache_entry *ce) |
257 | { | |
258 | unsigned ce_mode = ntohl(ce->ce_mode); | |
259 | if (S_ISREG(ce_mode)) | |
260 | return DT_REG; | |
261 | else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode)) | |
262 | return DT_DIR; | |
263 | else if (S_ISLNK(ce_mode)) | |
264 | return DT_LNK; | |
265 | else | |
266 | return DT_UNKNOWN; | |
267 | } | |
b90d9b88 RS |
268 | static inline unsigned int canon_mode(unsigned int mode) |
269 | { | |
270 | if (S_ISREG(mode)) | |
271 | return S_IFREG | ce_permissions(mode); | |
272 | if (S_ISLNK(mode)) | |
273 | return S_IFLNK; | |
274 | if (S_ISDIR(mode)) | |
275 | return S_IFDIR; | |
276 | return S_IFGITLINK; | |
277 | } | |
e4479470 | 278 | |
ac48adf4 EN |
279 | static inline int ce_path_match(struct index_state *istate, |
280 | const struct cache_entry *ce, | |
281 | const struct pathspec *pathspec, | |
282 | char *seen) | |
283 | { | |
284 | return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen, | |
285 | S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)); | |
286 | } | |
287 | ||
ee7825b5 | 288 | #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) |
f5cabd13 | 289 | |
e636a7b4 NTND |
290 | #define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */ |
291 | #define CE_ENTRY_CHANGED (1 << 1) | |
292 | #define CE_ENTRY_REMOVED (1 << 2) | |
293 | #define CE_ENTRY_ADDED (1 << 3) | |
6c306a34 | 294 | #define RESOLVE_UNDO_CHANGED (1 << 4) |
a5400efe | 295 | #define CACHE_TREE_CHANGED (1 << 5) |
c18b80a0 | 296 | #define SPLIT_INDEX_ORDERED (1 << 6) |
1bbb3dba | 297 | #define UNTRACKED_CHANGED (1 << 7) |
883e248b | 298 | #define FSMONITOR_CHANGED (1 << 8) |
e636a7b4 | 299 | |
5fc2fc8f | 300 | struct split_index; |
83c094ad | 301 | struct untracked_cache; |
4dcd4def | 302 | struct progress; |
836e25c5 | 303 | struct pattern_list; |
83c094ad | 304 | |
9fadb373 DS |
305 | enum sparse_index_mode { |
306 | /* | |
307 | * There are no sparse directories in the index at all. | |
308 | * | |
309 | * Repositories that don't use cone-mode sparse-checkout will | |
310 | * always have their indexes in this mode. | |
311 | */ | |
312 | INDEX_EXPANDED = 0, | |
313 | ||
314 | /* | |
315 | * The index has already been collapsed to sparse directories | |
316 | * whereever possible. | |
317 | */ | |
318 | INDEX_COLLAPSED, | |
319 | ||
320 | /* | |
321 | * The sparse directories that exist are outside the | |
322 | * sparse-checkout boundary, but it is possible that some file | |
323 | * entries could collapse to sparse directory entries. | |
324 | */ | |
325 | INDEX_PARTIALLY_SPARSE, | |
326 | }; | |
327 | ||
228e94f9 JH |
328 | struct index_state { |
329 | struct cache_entry **cache; | |
9d227781 | 330 | unsigned int version; |
228e94f9 | 331 | unsigned int cache_nr, cache_alloc, cache_changed; |
cfc5789a | 332 | struct string_list *resolve_undo; |
228e94f9 | 333 | struct cache_tree *cache_tree; |
5fc2fc8f | 334 | struct split_index *split_index; |
fba2f38a | 335 | struct cache_time timestamp; |
913e0e99 | 336 | unsigned name_hash_initialized : 1, |
4bddd983 | 337 | initialized : 1, |
1956ecd0 BP |
338 | drop_cache_tree : 1, |
339 | updated_workdir : 1, | |
cfd635c7 | 340 | updated_skipworktree : 1, |
9fadb373 DS |
341 | fsmonitor_has_run_once : 1; |
342 | enum sparse_index_mode sparse_index; | |
8b013788 | 343 | struct hashmap name_hash; |
e05881a4 | 344 | struct hashmap dir_hash; |
75691ea3 | 345 | struct object_id oid; |
83c094ad | 346 | struct untracked_cache *untracked; |
56c69100 | 347 | char *fsmonitor_last_update; |
ba1b9cac | 348 | struct ewah_bitmap *fsmonitor_dirty; |
8e72d675 | 349 | struct mem_pool *ce_mem_pool; |
4dcd4def | 350 | struct progress *progress; |
1fd9ae51 | 351 | struct repository *repo; |
836e25c5 | 352 | struct pattern_list *sparse_checkout_patterns; |
228e94f9 JH |
353 | }; |
354 | ||
2f6b1eb7 ÆAB |
355 | /** |
356 | * A "struct index_state istate" must be initialized with | |
357 | * INDEX_STATE_INIT or the corresponding index_state_init(). | |
358 | * | |
359 | * If the variable won't be used again, use release_index() to free() | |
360 | * its resources. If it needs to be used again use discard_index(), | |
361 | * which does the same thing, but will use use index_state_init() at | |
6269f8ea ÆAB |
362 | * the end. The discard_index() will use its own "istate->repo" as the |
363 | * "r" argument to index_state_init() in that case. | |
2f6b1eb7 | 364 | */ |
6269f8ea ÆAB |
365 | #define INDEX_STATE_INIT(r) { \ |
366 | .repo = (r), \ | |
367 | } | |
368 | void index_state_init(struct index_state *istate, struct repository *r); | |
2f6b1eb7 ÆAB |
369 | void release_index(struct index_state *istate); |
370 | ||
96872bc2 | 371 | /* Name hashing */ |
55454427 DL |
372 | int test_lazy_init_name_hash(struct index_state *istate, int try_threaded); |
373 | void add_name_hash(struct index_state *istate, struct cache_entry *ce); | |
374 | void remove_name_hash(struct index_state *istate, struct cache_entry *ce); | |
375 | void free_name_hash(struct index_state *istate); | |
96872bc2 | 376 | |
a849735b JM |
377 | /* Cache entry creation and cleanup */ |
378 | ||
379 | /* | |
380 | * Create cache_entry intended for use in the specified index. Caller | |
381 | * is responsible for discarding the cache_entry with | |
382 | * `discard_cache_entry`. | |
383 | */ | |
384 | struct cache_entry *make_cache_entry(struct index_state *istate, | |
385 | unsigned int mode, | |
386 | const struct object_id *oid, | |
387 | const char *path, | |
388 | int stage, | |
389 | unsigned int refresh_options); | |
390 | ||
391 | struct cache_entry *make_empty_cache_entry(struct index_state *istate, | |
392 | size_t name_len); | |
393 | ||
394 | /* | |
96168827 MT |
395 | * Create a cache_entry that is not intended to be added to an index. If |
396 | * `ce_mem_pool` is not NULL, the entry is allocated within the given memory | |
397 | * pool. Caller is responsible for discarding "loose" entries with | |
398 | * `discard_cache_entry()` and the memory pool with | |
399 | * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`. | |
a849735b JM |
400 | */ |
401 | struct cache_entry *make_transient_cache_entry(unsigned int mode, | |
402 | const struct object_id *oid, | |
403 | const char *path, | |
96168827 MT |
404 | int stage, |
405 | struct mem_pool *ce_mem_pool); | |
a849735b | 406 | |
96168827 MT |
407 | struct cache_entry *make_empty_transient_cache_entry(size_t len, |
408 | struct mem_pool *ce_mem_pool); | |
a849735b JM |
409 | |
410 | /* | |
411 | * Discard cache entry. | |
412 | */ | |
413 | void discard_cache_entry(struct cache_entry *ce); | |
414 | ||
8616a2d0 JM |
415 | /* |
416 | * Check configuration if we should perform extra validation on cache | |
417 | * entries. | |
418 | */ | |
419 | int should_validate_cache_entries(void); | |
420 | ||
8e72d675 JM |
421 | /* |
422 | * Duplicate a cache_entry. Allocate memory for the new entry from a | |
423 | * memory_pool. Takes into account cache_entry fields that are meant | |
424 | * for managing the underlying memory allocation of the cache_entry. | |
425 | */ | |
426 | struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate); | |
427 | ||
428 | /* | |
429 | * Validate the cache entries in the index. This is an internal | |
430 | * consistency check that the cache_entry structs are allocated from | |
431 | * the expected memory pool. | |
432 | */ | |
433 | void validate_cache_entries(const struct index_state *istate); | |
434 | ||
b2896d27 JT |
435 | /* |
436 | * Bulk prefetch all missing cache entries that are not GITLINKs and that match | |
437 | * the given predicate. This function should only be called if | |
438 | * has_promisor_remote() returns true. | |
439 | */ | |
440 | typedef int (*must_prefetch_predicate)(const struct cache_entry *); | |
441 | void prefetch_cache_entries(const struct index_state *istate, | |
442 | must_prefetch_predicate must_prefetch); | |
443 | ||
dfd0a893 | 444 | #ifdef USE_THE_INDEX_VARIABLE |
f8adbec9 | 445 | extern struct index_state the_index; |
666f53eb | 446 | #endif |
e83c5163 | 447 | |
b45563a2 JH |
448 | static inline enum object_type object_type(unsigned int mode) |
449 | { | |
450 | return S_ISDIR(mode) ? OBJ_TREE : | |
451 | S_ISGITLINK(mode) ? OBJ_COMMIT : | |
452 | OBJ_BLOB; | |
453 | } | |
454 | ||
55454427 | 455 | int is_inside_git_dir(void); |
55454427 | 456 | int is_inside_work_tree(void); |
55454427 DL |
457 | int get_common_dir_noenv(struct strbuf *sb, const char *gitdir); |
458 | int get_common_dir(struct strbuf *sb, const char *gitdir); | |
a93bedad | 459 | |
ffd036b1 JK |
460 | /* |
461 | * Return true if the given path is a git directory; note that this _just_ | |
462 | * looks at the directory itself. If you want to know whether "foo/.git" | |
463 | * is a repository, you must feed that path, not just "foo". | |
464 | */ | |
55454427 | 465 | int is_git_directory(const char *path); |
ffd036b1 JK |
466 | |
467 | /* | |
468 | * Return 1 if the given path is the root of a git repository or | |
469 | * submodule, else 0. Will not return 1 for bare repositories with the | |
470 | * exception of creating a bare repository in "foo/.git" and calling | |
471 | * is_git_repository("foo"). | |
472 | * | |
473 | * If we run into read errors, we err on the side of saying "yes, it is", | |
474 | * as we usually consider sub-repos precious, and would prefer to err on the | |
475 | * side of not disrupting or deleting them. | |
476 | */ | |
55454427 | 477 | int is_nonbare_repository_dir(struct strbuf *path); |
ffd036b1 | 478 | |
a93bedad EE |
479 | #define READ_GITFILE_ERR_STAT_FAILED 1 |
480 | #define READ_GITFILE_ERR_NOT_A_FILE 2 | |
481 | #define READ_GITFILE_ERR_OPEN_FAILED 3 | |
482 | #define READ_GITFILE_ERR_READ_FAILED 4 | |
483 | #define READ_GITFILE_ERR_INVALID_FORMAT 5 | |
484 | #define READ_GITFILE_ERR_NO_PATH 6 | |
485 | #define READ_GITFILE_ERR_NOT_A_REPO 7 | |
921bdd96 | 486 | #define READ_GITFILE_ERR_TOO_LARGE 8 |
55454427 DL |
487 | void read_gitfile_error_die(int error_code, const char *path, const char *dir); |
488 | const char *read_gitfile_gently(const char *path, int *return_error_code); | |
a93bedad | 489 | #define read_gitfile(path) read_gitfile_gently((path), NULL) |
55454427 | 490 | const char *resolve_gitdir_gently(const char *suspect, int *return_error_code); |
40d96325 SB |
491 | #define resolve_gitdir(path) resolve_gitdir_gently((path), NULL) |
492 | ||
55454427 | 493 | void setup_work_tree(void); |
16ac8b8d | 494 | /* |
d3fb71b3 BW |
495 | * Find the commondir and gitdir of the repository that contains the current |
496 | * working directory, without changing the working directory or other global | |
497 | * state. The result is appended to commondir and gitdir. If the discovered | |
498 | * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will | |
499 | * both have the same result appended to the buffer. The return value is | |
500 | * either 0 upon success and non-zero if no repository was found. | |
16ac8b8d | 501 | */ |
55454427 | 502 | int discover_git_directory(struct strbuf *commondir, |
ad6dad09 | 503 | struct strbuf *gitdir); |
55454427 DL |
504 | const char *setup_git_directory_gently(int *); |
505 | const char *setup_git_directory(void); | |
506 | char *prefix_path(const char *prefix, int len, const char *path); | |
507 | char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path); | |
59801976 | 508 | |
55454427 DL |
509 | int check_filename(const char *prefix, const char *name); |
510 | void verify_filename(const char *prefix, | |
ad6dad09 DL |
511 | const char *name, |
512 | int diagnose_misspelt_rev); | |
55454427 DL |
513 | void verify_non_filename(const char *prefix, const char *name); |
514 | int path_inside_repo(const char *prefix, const char *path); | |
d288a700 | 515 | |
f225aeb2 | 516 | #define INIT_DB_QUIET 0x0001 |
33158701 | 517 | #define INIT_DB_EXIST_OK 0x0002 |
f225aeb2 | 518 | |
55454427 | 519 | int init_db(const char *git_dir, const char *real_git_dir, |
8b8f7189 | 520 | const char *template_dir, int hash_algo, |
32ba12da | 521 | const char *initial_branch, unsigned int flags); |
47ac9703 | 522 | void initialize_repository_version(int hash_algo, int reinit); |
f225aeb2 | 523 | |
55454427 DL |
524 | void sanitize_stdfds(void); |
525 | int daemonize(void); | |
1d999ddd | 526 | |
734aab75 | 527 | /* Initialize and use the cache information */ |
03b86647 | 528 | struct lock_file; |
55454427 | 529 | void preload_index(struct index_state *index, |
ad6dad09 DL |
530 | const struct pathspec *pathspec, |
531 | unsigned int refresh_flags); | |
55454427 | 532 | int do_read_index(struct index_state *istate, const char *path, |
ad6dad09 | 533 | int must_exist); /* for testting only! */ |
55454427 | 534 | int read_index_from(struct index_state *, const char *path, |
ad6dad09 | 535 | const char *gitdir); |
55454427 | 536 | int is_index_unborn(struct index_state *); |
8dc38346 | 537 | |
4300f844 DS |
538 | void ensure_full_index(struct index_state *istate); |
539 | ||
8dc38346 | 540 | /* For use with `write_locked_index()`. */ |
03b86647 | 541 | #define COMMIT_LOCK (1 << 0) |
61000814 | 542 | #define SKIP_IF_UNCHANGED (1 << 1) |
8dc38346 MÅ |
543 | |
544 | /* | |
812d6b00 MÅ |
545 | * Write the index while holding an already-taken lock. Close the lock, |
546 | * and if `COMMIT_LOCK` is given, commit it. | |
8dc38346 MÅ |
547 | * |
548 | * Unless a split index is in use, write the index into the lockfile. | |
549 | * | |
550 | * With a split index, write the shared index to a temporary file, | |
551 | * adjust its permissions and rename it into place, then write the | |
552 | * split index to the lockfile. If the temporary file for the shared | |
553 | * index cannot be created, fall back to the behavior described in | |
554 | * the previous paragraph. | |
df60cf57 MÅ |
555 | * |
556 | * With `COMMIT_LOCK`, the lock is always committed or rolled back. | |
557 | * Without it, the lock is closed, but neither committed nor rolled | |
558 | * back. | |
61000814 MÅ |
559 | * |
560 | * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing | |
561 | * is written (and the lock is rolled back if `COMMIT_LOCK` is given). | |
8dc38346 | 562 | */ |
55454427 | 563 | int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags); |
8dc38346 | 564 | |
9c5f3ee3 | 565 | void discard_index(struct index_state *); |
55454427 DL |
566 | void move_index_extensions(struct index_state *dst, struct index_state *src); |
567 | int unmerged_index(const struct index_state *); | |
b101793c EN |
568 | |
569 | /** | |
e1f8694f EN |
570 | * Returns 1 if istate differs from tree, 0 otherwise. If tree is NULL, |
571 | * compares istate to HEAD. If tree is NULL and on an unborn branch, | |
572 | * returns 1 if there are entries in istate, 0 otherwise. If an strbuf is | |
573 | * provided, the space-separated list of files that differ will be appended | |
574 | * to it. | |
b101793c | 575 | */ |
55454427 | 576 | int repo_index_has_changes(struct repository *repo, |
ad6dad09 DL |
577 | struct tree *tree, |
578 | struct strbuf *sb); | |
b101793c | 579 | |
55454427 DL |
580 | int verify_path(const char *path, unsigned mode); |
581 | int strcmp_offset(const char *s1, const char *s2, size_t *first_change); | |
582 | int index_dir_exists(struct index_state *istate, const char *name, int namelen); | |
583 | void adjust_dirname_case(struct index_state *istate, char *name); | |
584 | struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase); | |
12733e9d SB |
585 | |
586 | /* | |
587 | * Searches for an entry defined by name and namelen in the given index. | |
588 | * If the return value is positive (including 0) it is the position of an | |
589 | * exact match. If the return value is negative, the negated value minus 1 | |
590 | * is the position where the entry would be inserted. | |
591 | * Example: The current index consists of these files and its stages: | |
592 | * | |
593 | * b#0, d#0, f#1, f#3 | |
594 | * | |
595 | * index_name_pos(&index, "a", 1) -> -1 | |
596 | * index_name_pos(&index, "b", 1) -> 0 | |
597 | * index_name_pos(&index, "c", 1) -> -2 | |
598 | * index_name_pos(&index, "d", 1) -> 1 | |
599 | * index_name_pos(&index, "e", 1) -> -3 | |
600 | * index_name_pos(&index, "f", 1) -> -3 | |
601 | * index_name_pos(&index, "g", 1) -> -5 | |
602 | */ | |
847a9e5d | 603 | int index_name_pos(struct index_state *, const char *name, int namelen); |
12733e9d | 604 | |
9553aa0f VD |
605 | /* |
606 | * Like index_name_pos, returns the position of an entry of the given name in | |
607 | * the index if one exists, otherwise returns a negative value where the negated | |
608 | * value minus 1 is the position where the index entry would be inserted. Unlike | |
609 | * index_name_pos, however, a sparse index is not expanded to find an entry | |
610 | * inside a sparse directory. | |
611 | */ | |
612 | int index_name_pos_sparse(struct index_state *, const char *name, int namelen); | |
613 | ||
20ec2d03 VD |
614 | /* |
615 | * Determines whether an entry with the given name exists within the | |
616 | * given index. The return value is 1 if an exact match is found, otherwise | |
617 | * it is 0. Note that, unlike index_name_pos, this function does not expand | |
618 | * the index if it is sparse. If an item exists within the full index but it | |
619 | * is contained within a sparse directory (and not in the sparse index), 0 is | |
620 | * returned. | |
621 | */ | |
622 | int index_entry_exists(struct index_state *, const char *name, int namelen); | |
623 | ||
c097b95a JS |
624 | /* |
625 | * Some functions return the negative complement of an insert position when a | |
626 | * precise match was not found but a position was found where the entry would | |
627 | * need to be inserted. This helper protects that logic from any integer | |
628 | * underflow. | |
629 | */ | |
630 | static inline int index_pos_to_insert_pos(uintmax_t pos) | |
631 | { | |
632 | if (pos > INT_MAX) | |
633 | die("overflow: -1 - %"PRIuMAX, pos); | |
634 | return -1 - (int)pos; | |
635 | } | |
636 | ||
192268c1 JH |
637 | #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ |
638 | #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ | |
b155725d | 639 | #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ |
eefadd18 | 640 | #define ADD_CACHE_JUST_APPEND 8 /* Append only */ |
39425819 | 641 | #define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */ |
ce7c614b | 642 | #define ADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */ |
9e5da3d0 | 643 | #define ADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */ |
55454427 DL |
644 | int add_index_entry(struct index_state *, struct cache_entry *ce, int option); |
645 | void rename_index_entry_at(struct index_state *, int pos, const char *new_name); | |
3bd72adf SB |
646 | |
647 | /* Remove entry, return true if there are more entries to go. */ | |
55454427 | 648 | int remove_index_entry_at(struct index_state *, int pos); |
3bd72adf | 649 | |
55454427 DL |
650 | void remove_marked_cache_entries(struct index_state *istate, int invalidate); |
651 | int remove_file_from_index(struct index_state *, const char *path); | |
38ed1d89 JH |
652 | #define ADD_CACHE_VERBOSE 1 |
653 | #define ADD_CACHE_PRETEND 2 | |
01665924 | 654 | #define ADD_CACHE_IGNORE_ERRORS 4 |
041aee31 | 655 | #define ADD_CACHE_IGNORE_REMOVAL 8 |
39425819 | 656 | #define ADD_CACHE_INTENT 16 |
20cf41d0 SB |
657 | /* |
658 | * These two are used to add the contents of the file at path | |
659 | * to the index, marking the working tree up-to-date by storing | |
660 | * the cached stat info in the resulting cache entry. A caller | |
661 | * that has already run lstat(2) on the path can call | |
662 | * add_to_index(), and all others can call add_file_to_index(); | |
663 | * the latter will do necessary lstat(2) internally before | |
664 | * calling the former. | |
665 | */ | |
55454427 DL |
666 | int add_to_index(struct index_state *, const char *path, struct stat *, int flags); |
667 | int add_file_to_index(struct index_state *, const char *path, int flags); | |
20cf41d0 | 668 | |
55454427 DL |
669 | int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip); |
670 | int ce_same_name(const struct cache_entry *a, const struct cache_entry *b); | |
671 | void set_object_name_for_intent_to_add_entry(struct cache_entry *ce); | |
847a9e5d DS |
672 | int index_name_is_other(struct index_state *, const char *, int); |
673 | void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *); | |
4bd5b7da JH |
674 | |
675 | /* do stat comparison even if CE_VALID is true */ | |
676 | #define CE_MATCH_IGNORE_VALID 01 | |
677 | /* do not check the contents but report dirty on racily-clean entries */ | |
56cac48c NTND |
678 | #define CE_MATCH_RACY_IS_DIRTY 02 |
679 | /* do stat comparison even if CE_SKIP_WORKTREE is true */ | |
680 | #define CE_MATCH_IGNORE_SKIP_WORKTREE 04 | |
2e2e7ec1 BK |
681 | /* ignore non-existent files during stat update */ |
682 | #define CE_MATCH_IGNORE_MISSING 0x08 | |
25762726 BK |
683 | /* enable stat refresh */ |
684 | #define CE_MATCH_REFRESH 0x10 | |
883e248b BP |
685 | /* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */ |
686 | #define CE_MATCH_IGNORE_FSMONITOR 0X20 | |
55454427 | 687 | int is_racy_timestamp(const struct index_state *istate, |
ad6dad09 | 688 | const struct cache_entry *ce); |
2ede073f | 689 | int has_racy_timestamp(struct index_state *istate); |
55454427 DL |
690 | int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int); |
691 | int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int); | |
4bd5b7da | 692 | |
c4ce46fc JH |
693 | #define HASH_WRITE_OBJECT 1 |
694 | #define HASH_FORMAT_CHECK 2 | |
9472935d | 695 | #define HASH_RENORMALIZE 4 |
4ef91a2d | 696 | #define HASH_SILENT 8 |
55454427 DL |
697 | int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags); |
698 | int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags); | |
c21d39d7 MH |
699 | |
700 | /* | |
701 | * Record to sd the data from st that we use to check whether a file | |
702 | * might have changed. | |
703 | */ | |
55454427 | 704 | void fill_stat_data(struct stat_data *sd, struct stat *st); |
c21d39d7 MH |
705 | |
706 | /* | |
707 | * Return 0 if st is consistent with a file not having been changed | |
708 | * since sd was filled. If there are differences, return a | |
709 | * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED, | |
710 | * INODE_CHANGED, and DATA_CHANGED. | |
711 | */ | |
55454427 DL |
712 | int match_stat_data(const struct stat_data *sd, struct stat *st); |
713 | int match_stat_data_racy(const struct index_state *istate, | |
ad6dad09 | 714 | const struct stat_data *sd, struct stat *st); |
c21d39d7 | 715 | |
d4c0a3ac | 716 | void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st); |
415e96c8 | 717 | |
b243012c MT |
718 | #define REFRESH_REALLY (1 << 0) /* ignore_valid */ |
719 | #define REFRESH_UNMERGED (1 << 1) /* allow unmerged */ | |
720 | #define REFRESH_QUIET (1 << 2) /* be quiet about it */ | |
721 | #define REFRESH_IGNORE_MISSING (1 << 3) /* ignore non-existent */ | |
722 | #define REFRESH_IGNORE_SUBMODULES (1 << 4) /* ignore submodules */ | |
723 | #define REFRESH_IN_PORCELAIN (1 << 5) /* user friendly output, not "needs update" */ | |
724 | #define REFRESH_PROGRESS (1 << 6) /* show progress bar if stderr is tty */ | |
725 | #define REFRESH_IGNORE_SKIP_WORKTREE (1 << 7) /* ignore skip_worktree entries */ | |
55454427 | 726 | int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg); |
22184497 TG |
727 | /* |
728 | * Refresh the index and write it to disk. | |
729 | * | |
730 | * 'refresh_flags' is passed directly to 'refresh_index()', while | |
731 | * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so | |
732 | * the lockfile is always either committed or rolled back. | |
733 | * | |
734 | * If 'gentle' is passed, errors locking the index are ignored. | |
735 | * | |
736 | * Return 1 if refreshing the index returns an error, -1 if writing | |
737 | * the index to disk fails, 0 on success. | |
738 | * | |
739 | * Note that if refreshing the index returns an error, we still write | |
740 | * out the index (unless locking fails). | |
741 | */ | |
742 | 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); | |
743 | ||
55454427 | 744 | struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int); |
405e5b2f | 745 | |
55454427 | 746 | void set_alternate_index_output(const char *); |
697cc8ef | 747 | |
a33fc72f | 748 | extern int verify_index_checksum; |
00ec50e5 | 749 | extern int verify_ce_order; |
a33fc72f | 750 | |
9378c161 | 751 | extern int quote_path_fully; |
7875acb6 | 752 | |
020406ea NS |
753 | /* |
754 | * These values are used to help identify parts of a repository to fsync. | |
755 | * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the | |
756 | * repository and so shouldn't be fsynced. | |
757 | */ | |
758 | enum fsync_component { | |
759 | FSYNC_COMPONENT_NONE, | |
760 | FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0, | |
761 | FSYNC_COMPONENT_PACK = 1 << 1, | |
762 | FSYNC_COMPONENT_PACK_METADATA = 1 << 2, | |
763 | FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3, | |
ba95e96d | 764 | FSYNC_COMPONENT_INDEX = 1 << 4, |
bc22d845 | 765 | FSYNC_COMPONENT_REFERENCE = 1 << 5, |
020406ea NS |
766 | }; |
767 | ||
b9f5d035 NS |
768 | #define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \ |
769 | FSYNC_COMPONENT_PACK) | |
770 | ||
771 | #define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \ | |
772 | FSYNC_COMPONENT_COMMIT_GRAPH) | |
773 | ||
e5ec440c NS |
774 | #define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \ |
775 | FSYNC_COMPONENTS_DERIVED_METADATA) & \ | |
b9f5d035 NS |
776 | ~FSYNC_COMPONENT_LOOSE_OBJECT) |
777 | ||
bc22d845 PS |
778 | #define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \ |
779 | FSYNC_COMPONENT_REFERENCE) | |
b9f5d035 NS |
780 | |
781 | #define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \ | |
782 | FSYNC_COMPONENT_INDEX) | |
783 | ||
784 | #define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \ | |
785 | FSYNC_COMPONENT_PACK | \ | |
786 | FSYNC_COMPONENT_PACK_METADATA | \ | |
787 | FSYNC_COMPONENT_COMMIT_GRAPH | \ | |
bc22d845 PS |
788 | FSYNC_COMPONENT_INDEX | \ |
789 | FSYNC_COMPONENT_REFERENCE) | |
020406ea | 790 | |
8a94d833 NS |
791 | #ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT |
792 | #define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT | |
793 | #endif | |
794 | ||
020406ea NS |
795 | /* |
796 | * A bitmask indicating which components of the repo should be fsynced. | |
797 | */ | |
798 | extern enum fsync_component fsync_components; | |
aafe9fba | 799 | extern int fsync_object_files; |
412e4cae | 800 | extern int use_fsync; |
abf38abe NS |
801 | |
802 | enum fsync_method { | |
803 | FSYNC_METHOD_FSYNC, | |
c0f4752e NS |
804 | FSYNC_METHOD_WRITEOUT_ONLY, |
805 | FSYNC_METHOD_BATCH, | |
abf38abe NS |
806 | }; |
807 | ||
808 | extern enum fsync_method fsync_method; | |
7f3140cd | 809 | |
00a09d57 JK |
810 | /* |
811 | * GIT_REPO_VERSION is the version we write by default. The | |
812 | * _READ variant is the highest number we know how to | |
813 | * handle. | |
814 | */ | |
ab9cb76f | 815 | #define GIT_REPO_VERSION 0 |
00a09d57 | 816 | #define GIT_REPO_VERSION_READ 1 |
4b0d1eeb | 817 | |
e8805af1 MÅ |
818 | /* |
819 | * You _have_ to initialize a `struct repository_format` using | |
820 | * `= REPOSITORY_FORMAT_INIT` before calling `read_repository_format()`. | |
821 | */ | |
2cc7c2c7 JK |
822 | struct repository_format { |
823 | int version; | |
824 | int precious_objects; | |
75b97fec | 825 | char *partial_clone; /* value of extensions.partialclone */ |
58b284a2 | 826 | int worktree_config; |
2cc7c2c7 | 827 | int is_bare; |
78a67668 | 828 | int hash_algo; |
58300f47 | 829 | int sparse_index; |
2cc7c2c7 JK |
830 | char *work_tree; |
831 | struct string_list unknown_extensions; | |
ec91ffca | 832 | struct string_list v1_only_extensions; |
2cc7c2c7 JK |
833 | }; |
834 | ||
e8805af1 MÅ |
835 | /* |
836 | * Always use this to initialize a `struct repository_format` | |
837 | * to a well-defined, default state before calling | |
838 | * `read_repository()`. | |
839 | */ | |
840 | #define REPOSITORY_FORMAT_INIT \ | |
841 | { \ | |
842 | .version = -1, \ | |
843 | .is_bare = -1, \ | |
844 | .hash_algo = GIT_HASH_SHA1, \ | |
845 | .unknown_extensions = STRING_LIST_INIT_DUP, \ | |
ec91ffca | 846 | .v1_only_extensions = STRING_LIST_INIT_DUP, \ |
e8805af1 MÅ |
847 | } |
848 | ||
2cc7c2c7 JK |
849 | /* |
850 | * Read the repository format characteristics from the config file "path" into | |
e8805af1 MÅ |
851 | * "format" struct. Returns the numeric version. On error, or if no version is |
852 | * found in the configuration, -1 is returned, format->version is set to -1, | |
853 | * and all other fields in the struct are set to the default configuration | |
854 | * (REPOSITORY_FORMAT_INIT). Always initialize the struct using | |
855 | * REPOSITORY_FORMAT_INIT before calling this function. | |
2cc7c2c7 JK |
856 | */ |
857 | int read_repository_format(struct repository_format *format, const char *path); | |
858 | ||
e8805af1 MÅ |
859 | /* |
860 | * Free the memory held onto by `format`, but not the struct itself. | |
861 | * (No need to use this after `read_repository_format()` fails.) | |
862 | */ | |
863 | void clear_repository_format(struct repository_format *format); | |
864 | ||
2cc7c2c7 JK |
865 | /* |
866 | * Verify that the repository described by repository_format is something we | |
867 | * can read. If it is, return 0. Otherwise, return -1, and "err" will describe | |
868 | * any errors encountered. | |
869 | */ | |
870 | int verify_repository_format(const struct repository_format *format, | |
871 | struct strbuf *err); | |
872 | ||
4b0d1eeb JK |
873 | /* |
874 | * Check the repository format version in the path found in get_git_dir(), | |
875 | * and die if it is a version we don't understand. Generally one would | |
876 | * set_git_dir() before calling this, and use it only for "are we in a valid | |
877 | * repo?". | |
cfe3917c | 878 | * |
879 | * If successful and fmt is not NULL, fill fmt with data. | |
4b0d1eeb | 880 | */ |
cfe3917c | 881 | void check_repository_format(struct repository_format *fmt); |
ab9cb76f | 882 | |
734aab75 LT |
883 | #define MTIME_CHANGED 0x0001 |
884 | #define CTIME_CHANGED 0x0002 | |
885 | #define OWNER_CHANGED 0x0004 | |
886 | #define MODE_CHANGED 0x0008 | |
887 | #define INODE_CHANGED 0x0010 | |
888 | #define DATA_CHANGED 0x0020 | |
8ae0a8c5 | 889 | #define TYPE_CHANGED 0x0040 |
e83c5163 | 890 | |
af49c6d0 JK |
891 | /* |
892 | * Return an abbreviated sha1 unique within this repository's object database. | |
893 | * The result will be at least `len` characters long, and will be NUL | |
894 | * terminated. | |
895 | * | |
ef2ed501 JK |
896 | * The non-`_r` version returns a static buffer which remains valid until 4 |
897 | * more calls to find_unique_abbrev are made. | |
af49c6d0 JK |
898 | * |
899 | * The `_r` variant writes to a buffer supplied by the caller, which must be at | |
aab9583f | 900 | * least `GIT_MAX_HEXSZ + 1` bytes. The return value is the number of bytes |
af49c6d0 JK |
901 | * written (excluding the NUL terminator). |
902 | * | |
903 | * Note that while this version avoids the static buffer, it is not fully | |
904 | * reentrant, as it calls into other non-reentrant git code. | |
905 | */ | |
8bb95572 NTND |
906 | const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len); |
907 | #define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len) | |
908 | int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); | |
909 | #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len) | |
af49c6d0 | 910 | |
06cbe855 HO |
911 | /* |
912 | * NOTE NOTE NOTE!! | |
913 | * | |
914 | * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must | |
915 | * not be changed. Old repositories have core.sharedrepository written in | |
916 | * numeric format, and therefore these values are preserved for compatibility | |
917 | * reasons. | |
918 | */ | |
94df2506 | 919 | enum sharedrepo { |
06cbe855 HO |
920 | PERM_UMASK = 0, |
921 | OLD_PERM_GROUP = 1, | |
922 | OLD_PERM_EVERYBODY = 2, | |
923 | PERM_GROUP = 0660, | |
4b05548f | 924 | PERM_EVERYBODY = 0664 |
94df2506 JH |
925 | }; |
926 | int git_config_perm(const char *var, const char *value); | |
0be0521b MH |
927 | |
928 | /* | |
929 | * Create the directory containing the named path, using care to be | |
204a047f MH |
930 | * somewhat safe against races. Return one of the scld_error values to |
931 | * indicate success/failure. On error, set errno to describe the | |
932 | * problem. | |
18d37e86 MH |
933 | * |
934 | * SCLD_VANISHED indicates that one of the ancestor directories of the | |
935 | * path existed at one point during the function call and then | |
936 | * suddenly vanished, probably because another process pruned the | |
937 | * directory while we were working. To be robust against this kind of | |
938 | * race, callers might want to try invoking the function again when it | |
939 | * returns SCLD_VANISHED. | |
e95792e5 MH |
940 | * |
941 | * safe_create_leading_directories() temporarily changes path while it | |
942 | * is working but restores it before returning. | |
943 | * safe_create_leading_directories_const() doesn't modify path, even | |
eb3c027e MT |
944 | * temporarily. Both these variants adjust the permissions of the |
945 | * created directories to honor core.sharedRepository, so they are best | |
946 | * suited for files inside the git dir. For working tree files, use | |
947 | * safe_create_leading_directories_no_share() instead, as it ignores | |
948 | * the core.sharedRepository setting. | |
0be0521b MH |
949 | */ |
950 | enum scld_error { | |
951 | SCLD_OK = 0, | |
952 | SCLD_FAILED = -1, | |
953 | SCLD_PERMS = -2, | |
18d37e86 MH |
954 | SCLD_EXISTS = -3, |
955 | SCLD_VANISHED = -4 | |
0be0521b MH |
956 | }; |
957 | enum scld_error safe_create_leading_directories(char *path); | |
958 | enum scld_error safe_create_leading_directories_const(const char *path); | |
eb3c027e | 959 | enum scld_error safe_create_leading_directories_no_share(char *path); |
0be0521b | 960 | |
90a6464b | 961 | int mkdir_in_gitdir(const char *path); |
e7f136bf | 962 | |
55454427 | 963 | int git_open_cloexec(const char *name, int flags); |
b4d065df | 964 | #define git_open(name) git_open_cloexec(name, O_RDONLY) |
01cab976 ÆAB |
965 | |
966 | /** | |
967 | * unpack_loose_header() initializes the data stream needed to unpack | |
968 | * a loose object header. | |
969 | * | |
3b6a8db3 ÆAB |
970 | * Returns: |
971 | * | |
972 | * - ULHR_OK on success | |
973 | * - ULHR_BAD on error | |
5848fb11 | 974 | * - ULHR_TOO_LONG if the header was too long |
01cab976 ÆAB |
975 | * |
976 | * It will only parse up to MAX_HEADER_LEN bytes unless an optional | |
977 | * "hdrbuf" argument is non-NULL. This is intended for use with | |
978 | * OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error) | |
979 | * reporting. The full header will be extracted to "hdrbuf" for use | |
5848fb11 ÆAB |
980 | * with parse_loose_header(), ULHR_TOO_LONG will still be returned |
981 | * from this function to indicate that the header was too long. | |
01cab976 | 982 | */ |
3b6a8db3 ÆAB |
983 | enum unpack_loose_header_result { |
984 | ULHR_OK, | |
985 | ULHR_BAD, | |
5848fb11 | 986 | ULHR_TOO_LONG, |
3b6a8db3 ÆAB |
987 | }; |
988 | enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, | |
989 | unsigned char *map, | |
990 | unsigned long mapsize, | |
991 | void *buffer, | |
992 | unsigned long bufsiz, | |
993 | struct strbuf *hdrbuf); | |
994 | ||
dccb32bf ÆAB |
995 | /** |
996 | * parse_loose_header() parses the starting "<type> <len>\0" of an | |
997 | * object. If it doesn't follow that format -1 is returned. To check | |
998 | * the validity of the <type> populate the "typep" in the "struct | |
999 | * object_info". It will be OBJ_BAD if the object type is unknown. The | |
1000 | * parsed <len> can be retrieved via "oi->sizep", and from there | |
1001 | * passed to unpack_loose_rest(). | |
1002 | */ | |
ddb3474b | 1003 | struct object_info; |
dccb32bf | 1004 | int parse_loose_header(const char *hdr, struct object_info *oi); |
8237b185 | 1005 | |
cdcaaec9 ÆAB |
1006 | /** |
1007 | * With in-core object data in "buf", rehash it to make sure the | |
1008 | * object name actually matches "oid" to detect object corruption. | |
ee213de2 ÆAB |
1009 | * |
1010 | * A negative value indicates an error, usually that the OID is not | |
1011 | * what we expected, but it might also indicate another error. | |
cdcaaec9 | 1012 | */ |
b98d1885 | 1013 | int check_object_signature(struct repository *r, const struct object_id *oid, |
44439c1c ÆAB |
1014 | void *map, unsigned long size, |
1015 | enum object_type type); | |
0f156dbb ÆAB |
1016 | |
1017 | /** | |
1018 | * A streaming version of check_object_signature(). | |
1019 | * Try reading the object named with "oid" using | |
1020 | * the streaming interface and rehash it to do the same. | |
1021 | */ | |
1022 | int stream_object_signature(struct repository *r, const struct object_id *oid); | |
e83c5163 | 1023 | |
55454427 | 1024 | int finalize_object_file(const char *tmpfile, const char *filename); |
8237b185 | 1025 | |
6a5e6f5e | 1026 | /* Helper to check and "touch" a file */ |
55454427 | 1027 | int check_and_freshen_file(const char *fn, int freshen); |
6a5e6f5e | 1028 | |
e83c5163 | 1029 | /* Convert to/from hex/sha1 representation */ |
dce96489 LT |
1030 | #define MINIMUM_ABBREV minimum_abbrev |
1031 | #define DEFAULT_ABBREV default_abbrev | |
46a6c262 | 1032 | |
65acfeac JH |
1033 | /* used when the code does not know or care what the default abbrev is */ |
1034 | #define FALLBACK_DEFAULT_ABBREV 7 | |
1035 | ||
573285e5 | 1036 | struct object_context { |
5ec1e728 | 1037 | unsigned short mode; |
c4ec9677 DT |
1038 | /* |
1039 | * symlink_path is only used by get_tree_entry_follow_symlinks, | |
1040 | * and only for symlinks that point outside the repository. | |
1041 | */ | |
1042 | struct strbuf symlink_path; | |
dc944b65 | 1043 | /* |
321c89bf | 1044 | * If GET_OID_RECORD_PATH is set, this will record path (if any) |
dc944b65 JK |
1045 | * found when resolving the name. The caller is responsible for |
1046 | * releasing the memory. | |
1047 | */ | |
1048 | char *path; | |
573285e5 CP |
1049 | }; |
1050 | ||
ec580eaa | 1051 | int repo_get_oid(struct repository *r, const char *str, struct object_id *oid); |
75d31cee | 1052 | __attribute__((format (printf, 2, 3))) |
0b179f31 | 1053 | int get_oidf(struct object_id *oid, const char *fmt, ...); |
65e50464 NTND |
1054 | int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid); |
1055 | int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid); | |
1056 | int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid); | |
1057 | int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid); | |
1058 | int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid); | |
0daf7ff6 | 1059 | int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid); |
e270f42c NTND |
1060 | void maybe_die_on_misspelt_object_name(struct repository *repo, |
1061 | const char *name, | |
1062 | const char *prefix); | |
55454427 | 1063 | enum get_oid_result get_oid_with_context(struct repository *repo, const char *str, |
ad6dad09 DL |
1064 | unsigned flags, struct object_id *oid, |
1065 | struct object_context *oc); | |
2764fd93 | 1066 | |
65e50464 NTND |
1067 | #define get_oid(str, oid) repo_get_oid(the_repository, str, oid) |
1068 | #define get_oid_commit(str, oid) repo_get_oid_commit(the_repository, str, oid) | |
1069 | #define get_oid_committish(str, oid) repo_get_oid_committish(the_repository, str, oid) | |
1070 | #define get_oid_tree(str, oid) repo_get_oid_tree(the_repository, str, oid) | |
1071 | #define get_oid_treeish(str, oid) repo_get_oid_treeish(the_repository, str, oid) | |
1072 | #define get_oid_blob(str, oid) repo_get_oid_blob(the_repository, str, oid) | |
0daf7ff6 | 1073 | #define get_oid_mb(str, oid) repo_get_oid_mb(the_repository, str, oid) |
65e50464 | 1074 | |
1b7ba794 | 1075 | typedef int each_abbrev_fn(const struct object_id *oid, void *); |
4e99f2db NTND |
1076 | int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *); |
1077 | #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data) | |
d4e85a1a | 1078 | |
55454427 | 1079 | int set_disambiguate_hint_config(const char *var, const char *value); |
5b33cb1f | 1080 | |
e322b60d JK |
1081 | /* |
1082 | * This reads short-hand syntax that not only evaluates to a commit | |
1083 | * object name, but also can act as if the end user spelled the name | |
1084 | * of the branch from the command line. | |
1085 | * | |
1086 | * - "@{-N}" finds the name of the Nth previous branch we were on, and | |
1087 | * places the name of the branch in the given buf and returns the | |
1088 | * number of characters parsed if successful. | |
1089 | * | |
1090 | * - "<branch>@{upstream}" finds the name of the other ref that | |
1091 | * <branch> is configured to merge with (missing <branch> defaults | |
1092 | * to the current branch), and places the name of the branch in the | |
1093 | * given buf and returns the number of characters parsed if | |
1094 | * successful. | |
1095 | * | |
1096 | * If the input is not of the accepted format, it returns a negative | |
1097 | * number to signal an error. | |
1098 | * | |
1099 | * If the input was ok but there are not N branch switches in the | |
1100 | * reflog, it returns 0. | |
1101 | */ | |
0e9f62da JK |
1102 | #define INTERPRET_BRANCH_LOCAL (1<<0) |
1103 | #define INTERPRET_BRANCH_REMOTE (1<<1) | |
1104 | #define INTERPRET_BRANCH_HEAD (1<<2) | |
a4f66a78 JT |
1105 | struct interpret_branch_name_options { |
1106 | /* | |
1107 | * If "allowed" is non-zero, it is a treated as a bitfield of allowable | |
1108 | * expansions: local branches ("refs/heads/"), remote branches | |
1109 | * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is | |
1110 | * allowed, even ones to refs outside of those namespaces. | |
1111 | */ | |
1112 | unsigned allowed; | |
f24c30e0 JT |
1113 | |
1114 | /* | |
1115 | * If ^{upstream} or ^{push} (or equivalent) is requested, and the | |
1116 | * branch in question does not have such a reference, return -1 instead | |
1117 | * of die()-ing. | |
1118 | */ | |
1119 | unsigned nonfatal_dangling_mark : 1; | |
a4f66a78 | 1120 | }; |
8f56e9d4 NTND |
1121 | int repo_interpret_branch_name(struct repository *r, |
1122 | const char *str, int len, | |
1123 | struct strbuf *buf, | |
a4f66a78 JT |
1124 | const struct interpret_branch_name_options *options); |
1125 | #define interpret_branch_name(str, len, buf, options) \ | |
1126 | repo_interpret_branch_name(the_repository, str, len, buf, options) | |
e86eb666 | 1127 | |
1b4a38d7 RS |
1128 | int base_name_compare(const char *name1, size_t len1, int mode1, |
1129 | const char *name2, size_t len2, int mode2); | |
1130 | int df_name_compare(const char *name1, size_t len1, int mode1, | |
1131 | const char *name2, size_t len2, int mode2); | |
55454427 DL |
1132 | int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); |
1133 | int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); | |
e83c5163 | 1134 | |
d3b4705a NTND |
1135 | void *read_object_with_reference(struct repository *r, |
1136 | const struct object_id *oid, | |
6aea6bae | 1137 | enum object_type required_type, |
ad6dad09 DL |
1138 | unsigned long *size, |
1139 | struct object_id *oid_ret); | |
f4913f91 | 1140 | |
2b1790f5 NTND |
1141 | struct object *repo_peel_to_type(struct repository *r, |
1142 | const char *name, int namelen, | |
1143 | struct object *o, enum object_type); | |
1144 | #define peel_to_type(name, namelen, obj, type) \ | |
1145 | repo_peel_to_type(the_repository, name, namelen, obj, type) | |
81776315 | 1146 | |
55454427 DL |
1147 | const char *git_editor(void); |
1148 | const char *git_sequence_editor(void); | |
1149 | const char *git_pager(int stdout_is_tty); | |
1150 | int is_terminal_dumb(void); | |
662cc30c | 1151 | |
b9fd2846 | 1152 | struct cache_def { |
e7c73053 | 1153 | struct strbuf path; |
b9fd2846 LT |
1154 | int flags; |
1155 | int track_flags; | |
1156 | int prefix_len_stat_func; | |
1157 | }; | |
f69a6e4f ÆAB |
1158 | #define CACHE_DEF_INIT { \ |
1159 | .path = STRBUF_INIT, \ | |
1160 | } | |
2a608391 | 1161 | static inline void cache_def_clear(struct cache_def *cache) |
e7c73053 KB |
1162 | { |
1163 | strbuf_release(&cache->path); | |
1164 | } | |
b9fd2846 | 1165 | |
55454427 DL |
1166 | int has_symlink_leading_path(const char *name, int len); |
1167 | int threaded_has_symlink_leading_path(struct cache_def *, const char *, int); | |
fab78a0c | 1168 | int check_leading_path(const char *name, int len, int warn_on_lstat_err); |
55454427 | 1169 | int has_dirs_only_path(const char *name, int len, int prefix_len); |
bcf08f33 | 1170 | void invalidate_lstat_cache(void); |
55454427 DL |
1171 | void schedule_dir_for_removal(const char *name, int len); |
1172 | void remove_scheduled_dirs(void); | |
12dccc16 | 1173 | |
c41ee586 SP |
1174 | struct pack_window { |
1175 | struct pack_window *next; | |
1176 | unsigned char *base; | |
1177 | off_t offset; | |
1178 | size_t len; | |
1179 | unsigned int last_used; | |
1180 | unsigned int inuse_cnt; | |
1181 | }; | |
1182 | ||
f3bf9224 | 1183 | struct pack_entry { |
c4001d92 | 1184 | off_t offset; |
f3bf9224 JH |
1185 | struct packed_git *p; |
1186 | }; | |
1187 | ||
8b4c0103 | 1188 | /* |
c93206b4 | 1189 | * Set this to 0 to prevent oid_object_info_extended() from fetching missing |
8b4c0103 JT |
1190 | * blobs. This has a difference only if extensions.partialClone is set. |
1191 | * | |
1192 | * Its default value is 1. | |
1193 | */ | |
1194 | extern int fetch_if_missing; | |
1195 | ||
8f3f9b09 | 1196 | /* Dumb servers support */ |
55454427 | 1197 | int update_server_info(int); |
8f3f9b09 | 1198 | |
d551a488 | 1199 | extern const char *git_mailmap_file; |
08610900 | 1200 | extern const char *git_mailmap_blob; |
4e72dcec | 1201 | |
06f59e9f | 1202 | /* IO helper functions */ |
55454427 | 1203 | void maybe_flush_or_die(FILE *, const char *); |
9540ce50 | 1204 | __attribute__((format (printf, 2, 3))) |
b199d714 | 1205 | void fprintf_or_die(FILE *, const char *fmt, ...); |
96328398 JV |
1206 | void fwrite_or_die(FILE *f, const void *buf, size_t count); |
1207 | void fflush_or_die(FILE *f); | |
00b7cbfc JH |
1208 | |
1209 | #define COPY_READ_ERROR (-2) | |
1210 | #define COPY_WRITE_ERROR (-3) | |
55454427 DL |
1211 | int copy_fd(int ifd, int ofd); |
1212 | int copy_file(const char *dst, const char *src, int mode); | |
1213 | int copy_file_with_time(const char *dst, const char *src, int mode); | |
00b7cbfc | 1214 | |
55454427 DL |
1215 | void write_or_die(int fd, const void *buf, size_t count); |
1216 | void fsync_or_die(int fd, const char *); | |
020406ea NS |
1217 | int fsync_component(enum fsync_component component, int fd); |
1218 | void fsync_component_or_die(enum fsync_component component, int fd, const char *msg); | |
ad897215 | 1219 | |
c0f4752e NS |
1220 | static inline int batch_fsync_enabled(enum fsync_component component) |
1221 | { | |
1222 | return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH); | |
1223 | } | |
1224 | ||
f67b45f8 | 1225 | /* pager.c */ |
55454427 DL |
1226 | void setup_pager(void); |
1227 | int pager_in_use(void); | |
aa086eb8 | 1228 | extern int pager_use_color; |
55454427 | 1229 | int term_columns(void); |
cd1096b2 | 1230 | void term_clear_line(void); |
55454427 DL |
1231 | int decimal_width(uintmax_t); |
1232 | int check_pager_config(const char *cmd); | |
1233 | void prepare_pager_args(struct child_process *, const char *pager); | |
f67b45f8 | 1234 | |
051308f6 | 1235 | /* base85 */ |
f9815772 JM |
1236 | int decode_85(char *dst, const char *line, int linelen); |
1237 | void encode_85(char *buf, const unsigned char *data, int bytes); | |
051308f6 | 1238 | |
5991a55c | 1239 | /* pkt-line.c */ |
bbc30f99 | 1240 | void packet_trace_identity(const char *prog); |
6ce4e61f | 1241 | |
b6ec1d61 | 1242 | /* add */ |
7ae02a30 AR |
1243 | /* |
1244 | * return 0 if success, 1 - if addition of a file failed and | |
1245 | * ADD_FILES_IGNORE_ERRORS was specified in flags | |
1246 | */ | |
610d55af | 1247 | int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags); |
b6ec1d61 | 1248 | |
aecbf914 JH |
1249 | /* diff.c */ |
1250 | extern int diff_auto_refresh_index; | |
1251 | ||
68faf689 | 1252 | /* match-trees.c */ |
90d34051 NTND |
1253 | void shift_tree(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, int); |
1254 | void shift_tree_by(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, const char *); | |
68faf689 | 1255 | |
a9cc857a JH |
1256 | /* |
1257 | * whitespace rules. | |
1258 | * used by both diff and apply | |
f4b05a49 | 1259 | * last two digits are tab width |
a9cc857a | 1260 | */ |
f4b05a49 JS |
1261 | #define WS_BLANK_AT_EOL 0100 |
1262 | #define WS_SPACE_BEFORE_TAB 0200 | |
1263 | #define WS_INDENT_WITH_NON_TAB 0400 | |
1264 | #define WS_CR_AT_EOL 01000 | |
1265 | #define WS_BLANK_AT_EOF 02000 | |
1266 | #define WS_TAB_IN_INDENT 04000 | |
aeb84b05 | 1267 | #define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF) |
f4b05a49 JS |
1268 | #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8) |
1269 | #define WS_TAB_WIDTH_MASK 077 | |
091f8e28 SB |
1270 | /* All WS_* -- when extended, adapt diff.c emit_symbol */ |
1271 | #define WS_RULE_MASK 07777 | |
cf1b7869 | 1272 | extern unsigned whitespace_rule_cfg; |
55454427 DL |
1273 | unsigned whitespace_rule(struct index_state *, const char *); |
1274 | unsigned parse_whitespace_rule(const char *); | |
1275 | unsigned ws_check(const char *line, int len, unsigned ws_rule); | |
1276 | void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws); | |
1277 | char *whitespace_error_string(unsigned ws); | |
1278 | void ws_fix_copy(struct strbuf *, const char *, int, unsigned, int *); | |
c5224f0f | 1279 | int ws_blank_line(const char *line, int len); |
f4b05a49 | 1280 | #define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK) |
a9cc857a | 1281 | |
ee425e46 | 1282 | /* ls-files */ |
312c984a BW |
1283 | void overlay_tree_on_index(struct index_state *istate, |
1284 | const char *tree_name, const char *prefix); | |
ee425e46 | 1285 | |
46c3cd44 | 1286 | /* setup.c */ |
e37c1329 | 1287 | struct startup_info { |
a60645f9 | 1288 | int have_repository; |
f07d6a1a | 1289 | const char *prefix; |
e6f8861b | 1290 | const char *original_cwd; |
e37c1329 NTND |
1291 | }; |
1292 | extern struct startup_info *startup_info; | |
e6f8861b | 1293 | extern const char *tmp_original_cwd; |
e37c1329 | 1294 | |
db699a8a NTND |
1295 | /* merge.c */ |
1296 | struct commit_list; | |
7e196c3a NTND |
1297 | int try_merge_command(struct repository *r, |
1298 | const char *strategy, size_t xopts_nr, | |
db699a8a NTND |
1299 | const char **xopts, struct commit_list *common, |
1300 | const char *head_arg, struct commit_list *remotes); | |
7e196c3a NTND |
1301 | int checkout_fast_forward(struct repository *r, |
1302 | const struct object_id *from, | |
f06e90da | 1303 | const struct object_id *to, |
db699a8a NTND |
1304 | int overwrite_ignore); |
1305 | ||
cac42b26 | 1306 | |
38f865c2 JK |
1307 | int sane_execvp(const char *file, char *const argv[]); |
1308 | ||
38612532 MH |
1309 | /* |
1310 | * A struct to encapsulate the concept of whether a file has changed | |
1311 | * since we last checked it. This uses criteria similar to those used | |
1312 | * for the index. | |
1313 | */ | |
1314 | struct stat_validity { | |
1315 | struct stat_data *sd; | |
1316 | }; | |
1317 | ||
1318 | void stat_validity_clear(struct stat_validity *sv); | |
1319 | ||
1320 | /* | |
1321 | * Returns 1 if the path is a regular file (or a symlink to a regular | |
1322 | * file) and matches the saved stat_validity, 0 otherwise. A missing | |
1323 | * or inaccessible file is considered a match if the struct was just | |
1324 | * initialized, or if the previous update found an inaccessible file. | |
1325 | */ | |
1326 | int stat_validity_check(struct stat_validity *sv, const char *path); | |
1327 | ||
1328 | /* | |
1329 | * Update the stat_validity from a file opened at descriptor fd. If | |
1330 | * the file is missing, inaccessible, or not a regular file, then | |
1331 | * future calls to stat_validity_check will match iff one of those | |
1332 | * conditions continues to be true. | |
1333 | */ | |
1334 | void stat_validity_update(struct stat_validity *sv, int fd); | |
1335 | ||
9ef176b5 NTND |
1336 | int versioncmp(const char *s1, const char *s2); |
1337 | ||
e83c5163 | 1338 | #endif /* CACHE_H */ |