2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #ifndef INCLUDE_index_h__
8 #define INCLUDE_index_h__
13 #include "tree-cache.h"
15 #include "git2/index.h"
17 #define GIT_INDEX_FILE "index"
18 #define GIT_INDEX_FILE_MODE 0666
23 char *index_file_path
;
24 git_futils_filestamp stamp
;
28 git_mutex lock
; /* lock held while entries is being changed */
29 git_vector deleted
; /* deleted entries if readers > 0 */
30 git_atomic readers
; /* number of active iterators */
32 unsigned int on_disk
:1;
33 unsigned int ignore_case
:1;
34 unsigned int distrust_filemode
:1;
35 unsigned int no_symlinks
:1;
42 git_vector_cmp entries_cmp_path
;
43 git_vector_cmp entries_search
;
44 git_vector_cmp entries_search_path
;
45 git_vector_cmp reuc_search
;
48 struct git_index_conflict_iterator
{
53 extern void git_index_entry__init_from_stat(
54 git_index_entry
*entry
, struct stat
*st
, bool trust_mode
);
56 /* Index entry comparison functions for array sorting */
57 extern int git_index_entry_cmp(const void *a
, const void *b
);
58 extern int git_index_entry_icmp(const void *a
, const void *b
);
60 /* Index entry search functions for search using a search spec */
61 extern int git_index_entry_srch(const void *a
, const void *b
);
62 extern int git_index_entry_isrch(const void *a
, const void *b
);
64 /* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
65 * (but not setting an error message).
67 * `at_pos` is set to the position where it is or would be inserted.
68 * Pass `path_len` as strlen of path or 0 to call strlen internally.
70 extern int git_index__find_pos(
71 size_t *at_pos
, git_index
*index
, const char *path
, size_t path_len
, int stage
);
73 extern void git_index__set_ignore_case(git_index
*index
, bool ignore_case
);
75 extern unsigned int git_index__create_mode(unsigned int mode
);
77 GIT_INLINE(const git_futils_filestamp
*) git_index__filestamp(git_index
*index
)
82 extern int git_index__changed_relative_to(git_index
*index
, const git_futils_filestamp
*fs
);
84 /* Copy the current entries vector *and* increment the index refcount.
85 * Call `git_index__release_snapshot` when done.
87 extern int git_index_snapshot_new(git_vector
*snap
, git_index
*index
);
88 extern void git_index_snapshot_release(git_vector
*snap
, git_index
*index
);
90 /* Allow searching in a snapshot; entries must already be sorted! */
91 extern int git_index_snapshot_find(
92 size_t *at_pos
, git_vector
*snap
, git_vector_cmp entry_srch
,
93 const char *path
, size_t path_len
, int stage
);