object: add object_array initializer helper function
[git/gitster.git] / cache.h
blob71e2fe74c4fd6b45c49e987207777ab6020d6f83
1 #ifndef CACHE_H
2 #define CACHE_H
4 #include "git-compat-util.h"
5 #include "strbuf.h"
6 #include "hashmap.h"
7 #include "gettext.h"
8 #include "string-list.h"
9 #include "pathspec.h"
10 #include "object.h"
11 #include "statinfo.h"
13 #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
14 #define DTYPE(de) ((de)->d_type)
15 #else
16 #undef DT_UNKNOWN
17 #undef DT_DIR
18 #undef DT_REG
19 #undef DT_LNK
20 #define DT_UNKNOWN 0
21 #define DT_DIR 1
22 #define DT_REG 2
23 #define DT_LNK 3
24 #define DTYPE(de) DT_UNKNOWN
25 #endif
28 * Some mode bits are also used internally for computations.
30 * They *must* not overlap with any valid modes, and they *must* not be emitted
31 * to outside world - i.e. appear on disk or network. In other words, it's just
32 * temporary fields, which we internally use, but they have to stay in-house.
34 * ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git
35 * codebase mode is `unsigned int` which is assumed to be at least 32 bits )
38 /* used internally in tree-diff */
39 #define S_DIFFTREE_IFXMIN_NEQ 0x80000000
43 * Basic data structures for the directory cache
46 #define CACHE_SIGNATURE 0x44495243 /* "DIRC" */
47 struct cache_header {
48 uint32_t hdr_signature;
49 uint32_t hdr_version;
50 uint32_t hdr_entries;
53 #define INDEX_FORMAT_LB 2
54 #define INDEX_FORMAT_UB 4
56 struct cache_entry {
57 struct hashmap_entry ent;
58 struct stat_data ce_stat_data;
59 unsigned int ce_mode;
60 unsigned int ce_flags;
61 unsigned int mem_pool_allocated;
62 unsigned int ce_namelen;
63 unsigned int index; /* for link extension */
64 struct object_id oid;
65 char name[FLEX_ARRAY]; /* more */
68 #define CE_STAGEMASK (0x3000)
69 #define CE_EXTENDED (0x4000)
70 #define CE_VALID (0x8000)
71 #define CE_STAGESHIFT 12
74 * Range 0xFFFF0FFF in ce_flags is divided into
75 * two parts: in-memory flags and on-disk ones.
76 * Flags in CE_EXTENDED_FLAGS will get saved on-disk
77 * if you want to save a new flag, add it in
78 * CE_EXTENDED_FLAGS
80 * In-memory only flags
82 #define CE_UPDATE (1 << 16)
83 #define CE_REMOVE (1 << 17)
84 #define CE_UPTODATE (1 << 18)
85 #define CE_ADDED (1 << 19)
87 #define CE_HASHED (1 << 20)
88 #define CE_FSMONITOR_VALID (1 << 21)
89 #define CE_WT_REMOVE (1 << 22) /* remove in work directory */
90 #define CE_CONFLICTED (1 << 23)
92 #define CE_UNPACKED (1 << 24)
93 #define CE_NEW_SKIP_WORKTREE (1 << 25)
95 /* used to temporarily mark paths matched by pathspecs */
96 #define CE_MATCHED (1 << 26)
98 #define CE_UPDATE_IN_BASE (1 << 27)
99 #define CE_STRIP_NAME (1 << 28)
102 * Extended on-disk flags
104 #define CE_INTENT_TO_ADD (1 << 29)
105 #define CE_SKIP_WORKTREE (1 << 30)
106 /* CE_EXTENDED2 is for future extension */
107 #define CE_EXTENDED2 (1U << 31)
109 #define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
112 * Safeguard to avoid saving wrong flags:
113 * - CE_EXTENDED2 won't get saved until its semantic is known
114 * - Bits in 0x0000FFFF have been saved in ce_flags already
115 * - Bits in 0x003F0000 are currently in-memory flags
117 #if CE_EXTENDED_FLAGS & 0x803FFFFF
118 #error "CE_EXTENDED_FLAGS out of range"
119 #endif
121 /* Forward structure decls */
122 struct pathspec;
123 struct tree;
126 * Copy the sha1 and stat state of a cache entry from one to
127 * another. But we never change the name, or the hash state!
129 static inline void copy_cache_entry(struct cache_entry *dst,
130 const struct cache_entry *src)
132 unsigned int state = dst->ce_flags & CE_HASHED;
133 int mem_pool_allocated = dst->mem_pool_allocated;
135 /* Don't copy hash chain and name */
136 memcpy(&dst->ce_stat_data, &src->ce_stat_data,
137 offsetof(struct cache_entry, name) -
138 offsetof(struct cache_entry, ce_stat_data));
140 /* Restore the hash state */
141 dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
143 /* Restore the mem_pool_allocated flag */
144 dst->mem_pool_allocated = mem_pool_allocated;
147 static inline unsigned create_ce_flags(unsigned stage)
149 return (stage << CE_STAGESHIFT);
152 #define ce_namelen(ce) ((ce)->ce_namelen)
153 #define ce_size(ce) cache_entry_size(ce_namelen(ce))
154 #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
155 #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
156 #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
157 #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
158 #define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
160 static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
161 unsigned int mode)
163 extern int trust_executable_bit, has_symlinks;
164 if (!has_symlinks && S_ISREG(mode) &&
165 ce && S_ISLNK(ce->ce_mode))
166 return ce->ce_mode;
167 if (!trust_executable_bit && S_ISREG(mode)) {
168 if (ce && S_ISREG(ce->ce_mode))
169 return ce->ce_mode;
170 return create_ce_mode(0666);
172 return create_ce_mode(mode);
174 static inline int ce_to_dtype(const struct cache_entry *ce)
176 unsigned ce_mode = ntohl(ce->ce_mode);
177 if (S_ISREG(ce_mode))
178 return DT_REG;
179 else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
180 return DT_DIR;
181 else if (S_ISLNK(ce_mode))
182 return DT_LNK;
183 else
184 return DT_UNKNOWN;
187 static inline int ce_path_match(struct index_state *istate,
188 const struct cache_entry *ce,
189 const struct pathspec *pathspec,
190 char *seen)
192 return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
193 S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
196 #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
198 #define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */
199 #define CE_ENTRY_CHANGED (1 << 1)
200 #define CE_ENTRY_REMOVED (1 << 2)
201 #define CE_ENTRY_ADDED (1 << 3)
202 #define RESOLVE_UNDO_CHANGED (1 << 4)
203 #define CACHE_TREE_CHANGED (1 << 5)
204 #define SPLIT_INDEX_ORDERED (1 << 6)
205 #define UNTRACKED_CHANGED (1 << 7)
206 #define FSMONITOR_CHANGED (1 << 8)
208 struct split_index;
209 struct untracked_cache;
210 struct progress;
211 struct pattern_list;
213 enum sparse_index_mode {
215 * There are no sparse directories in the index at all.
217 * Repositories that don't use cone-mode sparse-checkout will
218 * always have their indexes in this mode.
220 INDEX_EXPANDED = 0,
223 * The index has already been collapsed to sparse directories
224 * whereever possible.
226 INDEX_COLLAPSED,
229 * The sparse directories that exist are outside the
230 * sparse-checkout boundary, but it is possible that some file
231 * entries could collapse to sparse directory entries.
233 INDEX_PARTIALLY_SPARSE,
236 struct index_state {
237 struct cache_entry **cache;
238 unsigned int version;
239 unsigned int cache_nr, cache_alloc, cache_changed;
240 struct string_list *resolve_undo;
241 struct cache_tree *cache_tree;
242 struct split_index *split_index;
243 struct cache_time timestamp;
244 unsigned name_hash_initialized : 1,
245 initialized : 1,
246 drop_cache_tree : 1,
247 updated_workdir : 1,
248 updated_skipworktree : 1,
249 fsmonitor_has_run_once : 1;
250 enum sparse_index_mode sparse_index;
251 struct hashmap name_hash;
252 struct hashmap dir_hash;
253 struct object_id oid;
254 struct untracked_cache *untracked;
255 char *fsmonitor_last_update;
256 struct ewah_bitmap *fsmonitor_dirty;
257 struct mem_pool *ce_mem_pool;
258 struct progress *progress;
259 struct repository *repo;
260 struct pattern_list *sparse_checkout_patterns;
264 * A "struct index_state istate" must be initialized with
265 * INDEX_STATE_INIT or the corresponding index_state_init().
267 * If the variable won't be used again, use release_index() to free()
268 * its resources. If it needs to be used again use discard_index(),
269 * which does the same thing, but will use use index_state_init() at
270 * the end. The discard_index() will use its own "istate->repo" as the
271 * "r" argument to index_state_init() in that case.
273 #define INDEX_STATE_INIT(r) { \
274 .repo = (r), \
276 void index_state_init(struct index_state *istate, struct repository *r);
277 void release_index(struct index_state *istate);
279 /* Name hashing */
280 int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
281 void add_name_hash(struct index_state *istate, struct cache_entry *ce);
282 void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
283 void free_name_hash(struct index_state *istate);
285 /* Cache entry creation and cleanup */
288 * Create cache_entry intended for use in the specified index. Caller
289 * is responsible for discarding the cache_entry with
290 * `discard_cache_entry`.
292 struct cache_entry *make_cache_entry(struct index_state *istate,
293 unsigned int mode,
294 const struct object_id *oid,
295 const char *path,
296 int stage,
297 unsigned int refresh_options);
299 struct cache_entry *make_empty_cache_entry(struct index_state *istate,
300 size_t name_len);
303 * Create a cache_entry that is not intended to be added to an index. If
304 * `ce_mem_pool` is not NULL, the entry is allocated within the given memory
305 * pool. Caller is responsible for discarding "loose" entries with
306 * `discard_cache_entry()` and the memory pool with
307 * `mem_pool_discard(ce_mem_pool, should_validate_cache_entries())`.
309 struct cache_entry *make_transient_cache_entry(unsigned int mode,
310 const struct object_id *oid,
311 const char *path,
312 int stage,
313 struct mem_pool *ce_mem_pool);
315 struct cache_entry *make_empty_transient_cache_entry(size_t len,
316 struct mem_pool *ce_mem_pool);
319 * Discard cache entry.
321 void discard_cache_entry(struct cache_entry *ce);
324 * Check configuration if we should perform extra validation on cache
325 * entries.
327 int should_validate_cache_entries(void);
330 * Duplicate a cache_entry. Allocate memory for the new entry from a
331 * memory_pool. Takes into account cache_entry fields that are meant
332 * for managing the underlying memory allocation of the cache_entry.
334 struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_state *istate);
337 * Validate the cache entries in the index. This is an internal
338 * consistency check that the cache_entry structs are allocated from
339 * the expected memory pool.
341 void validate_cache_entries(const struct index_state *istate);
344 * Bulk prefetch all missing cache entries that are not GITLINKs and that match
345 * the given predicate. This function should only be called if
346 * repo_has_promisor_remote() returns true.
348 typedef int (*must_prefetch_predicate)(const struct cache_entry *);
349 void prefetch_cache_entries(const struct index_state *istate,
350 must_prefetch_predicate must_prefetch);
352 #ifdef USE_THE_INDEX_VARIABLE
353 extern struct index_state the_index;
354 #endif
356 #define INIT_DB_QUIET 0x0001
357 #define INIT_DB_EXIST_OK 0x0002
359 int init_db(const char *git_dir, const char *real_git_dir,
360 const char *template_dir, int hash_algo,
361 const char *initial_branch, unsigned int flags);
362 void initialize_repository_version(int hash_algo, int reinit);
364 /* Initialize and use the cache information */
365 struct lock_file;
366 void preload_index(struct index_state *index,
367 const struct pathspec *pathspec,
368 unsigned int refresh_flags);
369 int do_read_index(struct index_state *istate, const char *path,
370 int must_exist); /* for testting only! */
371 int read_index_from(struct index_state *, const char *path,
372 const char *gitdir);
373 int is_index_unborn(struct index_state *);
375 void ensure_full_index(struct index_state *istate);
377 /* For use with `write_locked_index()`. */
378 #define COMMIT_LOCK (1 << 0)
379 #define SKIP_IF_UNCHANGED (1 << 1)
382 * Write the index while holding an already-taken lock. Close the lock,
383 * and if `COMMIT_LOCK` is given, commit it.
385 * Unless a split index is in use, write the index into the lockfile.
387 * With a split index, write the shared index to a temporary file,
388 * adjust its permissions and rename it into place, then write the
389 * split index to the lockfile. If the temporary file for the shared
390 * index cannot be created, fall back to the behavior described in
391 * the previous paragraph.
393 * With `COMMIT_LOCK`, the lock is always committed or rolled back.
394 * Without it, the lock is closed, but neither committed nor rolled
395 * back.
397 * If `SKIP_IF_UNCHANGED` is given and the index is unchanged, nothing
398 * is written (and the lock is rolled back if `COMMIT_LOCK` is given).
400 int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
402 void discard_index(struct index_state *);
403 void move_index_extensions(struct index_state *dst, struct index_state *src);
404 int unmerged_index(const struct index_state *);
407 * Returns 1 if istate differs from tree, 0 otherwise. If tree is NULL,
408 * compares istate to HEAD. If tree is NULL and on an unborn branch,
409 * returns 1 if there are entries in istate, 0 otherwise. If an strbuf is
410 * provided, the space-separated list of files that differ will be appended
411 * to it.
413 int repo_index_has_changes(struct repository *repo,
414 struct tree *tree,
415 struct strbuf *sb);
417 int verify_path(const char *path, unsigned mode);
418 int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
419 int index_dir_exists(struct index_state *istate, const char *name, int namelen);
420 void adjust_dirname_case(struct index_state *istate, char *name);
421 struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
424 * Searches for an entry defined by name and namelen in the given index.
425 * If the return value is positive (including 0) it is the position of an
426 * exact match. If the return value is negative, the negated value minus 1
427 * is the position where the entry would be inserted.
428 * Example: The current index consists of these files and its stages:
430 * b#0, d#0, f#1, f#3
432 * index_name_pos(&index, "a", 1) -> -1
433 * index_name_pos(&index, "b", 1) -> 0
434 * index_name_pos(&index, "c", 1) -> -2
435 * index_name_pos(&index, "d", 1) -> 1
436 * index_name_pos(&index, "e", 1) -> -3
437 * index_name_pos(&index, "f", 1) -> -3
438 * index_name_pos(&index, "g", 1) -> -5
440 int index_name_pos(struct index_state *, const char *name, int namelen);
443 * Like index_name_pos, returns the position of an entry of the given name in
444 * the index if one exists, otherwise returns a negative value where the negated
445 * value minus 1 is the position where the index entry would be inserted. Unlike
446 * index_name_pos, however, a sparse index is not expanded to find an entry
447 * inside a sparse directory.
449 int index_name_pos_sparse(struct index_state *, const char *name, int namelen);
452 * Determines whether an entry with the given name exists within the
453 * given index. The return value is 1 if an exact match is found, otherwise
454 * it is 0. Note that, unlike index_name_pos, this function does not expand
455 * the index if it is sparse. If an item exists within the full index but it
456 * is contained within a sparse directory (and not in the sparse index), 0 is
457 * returned.
459 int index_entry_exists(struct index_state *, const char *name, int namelen);
462 * Some functions return the negative complement of an insert position when a
463 * precise match was not found but a position was found where the entry would
464 * need to be inserted. This helper protects that logic from any integer
465 * underflow.
467 static inline int index_pos_to_insert_pos(uintmax_t pos)
469 if (pos > INT_MAX)
470 die("overflow: -1 - %"PRIuMAX, pos);
471 return -1 - (int)pos;
474 #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
475 #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
476 #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */
477 #define ADD_CACHE_JUST_APPEND 8 /* Append only */
478 #define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */
479 #define ADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */
480 #define ADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */
481 int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
482 void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
484 /* Remove entry, return true if there are more entries to go. */
485 int remove_index_entry_at(struct index_state *, int pos);
487 void remove_marked_cache_entries(struct index_state *istate, int invalidate);
488 int remove_file_from_index(struct index_state *, const char *path);
489 #define ADD_CACHE_VERBOSE 1
490 #define ADD_CACHE_PRETEND 2
491 #define ADD_CACHE_IGNORE_ERRORS 4
492 #define ADD_CACHE_IGNORE_REMOVAL 8
493 #define ADD_CACHE_INTENT 16
495 * These two are used to add the contents of the file at path
496 * to the index, marking the working tree up-to-date by storing
497 * the cached stat info in the resulting cache entry. A caller
498 * that has already run lstat(2) on the path can call
499 * add_to_index(), and all others can call add_file_to_index();
500 * the latter will do necessary lstat(2) internally before
501 * calling the former.
503 int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
504 int add_file_to_index(struct index_state *, const char *path, int flags);
506 int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
507 int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
508 void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
509 int index_name_is_other(struct index_state *, const char *, int);
510 void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
512 /* do stat comparison even if CE_VALID is true */
513 #define CE_MATCH_IGNORE_VALID 01
514 /* do not check the contents but report dirty on racily-clean entries */
515 #define CE_MATCH_RACY_IS_DIRTY 02
516 /* do stat comparison even if CE_SKIP_WORKTREE is true */
517 #define CE_MATCH_IGNORE_SKIP_WORKTREE 04
518 /* ignore non-existent files during stat update */
519 #define CE_MATCH_IGNORE_MISSING 0x08
520 /* enable stat refresh */
521 #define CE_MATCH_REFRESH 0x10
522 /* don't refresh_fsmonitor state or do stat comparison even if CE_FSMONITOR_VALID is true */
523 #define CE_MATCH_IGNORE_FSMONITOR 0X20
524 int is_racy_timestamp(const struct index_state *istate,
525 const struct cache_entry *ce);
526 int has_racy_timestamp(struct index_state *istate);
527 int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
528 int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
531 * Record to sd the data from st that we use to check whether a file
532 * might have changed.
534 void fill_stat_data(struct stat_data *sd, struct stat *st);
537 * Return 0 if st is consistent with a file not having been changed
538 * since sd was filled. If there are differences, return a
539 * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
540 * INODE_CHANGED, and DATA_CHANGED.
542 int match_stat_data(const struct stat_data *sd, struct stat *st);
543 int match_stat_data_racy(const struct index_state *istate,
544 const struct stat_data *sd, struct stat *st);
546 void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st);
548 #define REFRESH_REALLY (1 << 0) /* ignore_valid */
549 #define REFRESH_UNMERGED (1 << 1) /* allow unmerged */
550 #define REFRESH_QUIET (1 << 2) /* be quiet about it */
551 #define REFRESH_IGNORE_MISSING (1 << 3) /* ignore non-existent */
552 #define REFRESH_IGNORE_SUBMODULES (1 << 4) /* ignore submodules */
553 #define REFRESH_IN_PORCELAIN (1 << 5) /* user friendly output, not "needs update" */
554 #define REFRESH_PROGRESS (1 << 6) /* show progress bar if stderr is tty */
555 #define REFRESH_IGNORE_SKIP_WORKTREE (1 << 7) /* ignore skip_worktree entries */
556 int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
558 * Refresh the index and write it to disk.
560 * 'refresh_flags' is passed directly to 'refresh_index()', while
561 * 'COMMIT_LOCK | write_flags' is passed to 'write_locked_index()', so
562 * the lockfile is always either committed or rolled back.
564 * If 'gentle' is passed, errors locking the index are ignored.
566 * Return 1 if refreshing the index returns an error, -1 if writing
567 * the index to disk fails, 0 on success.
569 * Note that if refreshing the index returns an error, we still write
570 * out the index (unless locking fails).
572 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);
574 struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
576 void set_alternate_index_output(const char *);
578 extern int verify_index_checksum;
579 extern int verify_ce_order;
581 #define MTIME_CHANGED 0x0001
582 #define CTIME_CHANGED 0x0002
583 #define OWNER_CHANGED 0x0004
584 #define MODE_CHANGED 0x0008
585 #define INODE_CHANGED 0x0010
586 #define DATA_CHANGED 0x0020
587 #define TYPE_CHANGED 0x0040
589 int base_name_compare(const char *name1, size_t len1, int mode1,
590 const char *name2, size_t len2, int mode2);
591 int df_name_compare(const char *name1, size_t len1, int mode1,
592 const char *name2, size_t len2, int mode2);
593 int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
594 int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
596 struct cache_def {
597 struct strbuf path;
598 int flags;
599 int track_flags;
600 int prefix_len_stat_func;
602 #define CACHE_DEF_INIT { \
603 .path = STRBUF_INIT, \
605 static inline void cache_def_clear(struct cache_def *cache)
607 strbuf_release(&cache->path);
610 int has_symlink_leading_path(const char *name, int len);
611 int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
612 int check_leading_path(const char *name, int len, int warn_on_lstat_err);
613 int has_dirs_only_path(const char *name, int len, int prefix_len);
614 void invalidate_lstat_cache(void);
615 void schedule_dir_for_removal(const char *name, int len);
616 void remove_scheduled_dirs(void);
618 struct pack_window {
619 struct pack_window *next;
620 unsigned char *base;
621 off_t offset;
622 size_t len;
623 unsigned int last_used;
624 unsigned int inuse_cnt;
627 struct pack_entry {
628 off_t offset;
629 struct packed_git *p;
632 /* Dumb servers support */
633 int update_server_info(int);
635 #define COPY_READ_ERROR (-2)
636 #define COPY_WRITE_ERROR (-3)
637 int copy_fd(int ifd, int ofd);
638 int copy_file(const char *dst, const char *src, int mode);
639 int copy_file_with_time(const char *dst, const char *src, int mode);
641 /* base85 */
642 int decode_85(char *dst, const char *line, int linelen);
643 void encode_85(char *buf, const unsigned char *data, int bytes);
645 /* pkt-line.c */
646 void packet_trace_identity(const char *prog);
648 /* add */
650 * return 0 if success, 1 - if addition of a file failed and
651 * ADD_FILES_IGNORE_ERRORS was specified in flags
653 int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags);
655 /* diff.c */
656 extern int diff_auto_refresh_index;
658 /* match-trees.c */
659 void shift_tree(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, int);
660 void shift_tree_by(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, const char *);
663 * whitespace rules.
664 * used by both diff and apply
665 * last two digits are tab width
667 #define WS_BLANK_AT_EOL 0100
668 #define WS_SPACE_BEFORE_TAB 0200
669 #define WS_INDENT_WITH_NON_TAB 0400
670 #define WS_CR_AT_EOL 01000
671 #define WS_BLANK_AT_EOF 02000
672 #define WS_TAB_IN_INDENT 04000
673 #define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)
674 #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8)
675 #define WS_TAB_WIDTH_MASK 077
676 /* All WS_* -- when extended, adapt diff.c emit_symbol */
677 #define WS_RULE_MASK 07777
678 extern unsigned whitespace_rule_cfg;
679 unsigned whitespace_rule(struct index_state *, const char *);
680 unsigned parse_whitespace_rule(const char *);
681 unsigned ws_check(const char *line, int len, unsigned ws_rule);
682 void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws);
683 char *whitespace_error_string(unsigned ws);
684 void ws_fix_copy(struct strbuf *, const char *, int, unsigned, int *);
685 int ws_blank_line(const char *line, int len);
686 #define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK)
688 /* ls-files */
689 void overlay_tree_on_index(struct index_state *istate,
690 const char *tree_name, const char *prefix);
692 /* merge.c */
693 struct commit_list;
694 int try_merge_command(struct repository *r,
695 const char *strategy, size_t xopts_nr,
696 const char **xopts, struct commit_list *common,
697 const char *head_arg, struct commit_list *remotes);
698 int checkout_fast_forward(struct repository *r,
699 const struct object_id *from,
700 const struct object_id *to,
701 int overwrite_ignore);
704 int sane_execvp(const char *file, char *const argv[]);
707 * A struct to encapsulate the concept of whether a file has changed
708 * since we last checked it. This uses criteria similar to those used
709 * for the index.
711 struct stat_validity {
712 struct stat_data *sd;
715 void stat_validity_clear(struct stat_validity *sv);
718 * Returns 1 if the path is a regular file (or a symlink to a regular
719 * file) and matches the saved stat_validity, 0 otherwise. A missing
720 * or inaccessible file is considered a match if the struct was just
721 * initialized, or if the previous update found an inaccessible file.
723 int stat_validity_check(struct stat_validity *sv, const char *path);
726 * Update the stat_validity from a file opened at descriptor fd. If
727 * the file is missing, inaccessible, or not a regular file, then
728 * future calls to stat_validity_check will match iff one of those
729 * conditions continues to be true.
731 void stat_validity_update(struct stat_validity *sv, int fd);
733 int versioncmp(const char *s1, const char *s2);
735 #endif /* CACHE_H */