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;
43 git_vector_cmp entries_cmp_path
;
44 git_vector_cmp entries_search
;
45 git_vector_cmp entries_search_path
;
46 git_vector_cmp reuc_search
;
49 struct git_index_conflict_iterator
{
54 extern void git_index_entry__init_from_stat(
55 git_index_entry
*entry
, struct stat
*st
, bool trust_mode
);
57 /* Index entry comparison functions for array sorting */
58 extern int git_index_entry_cmp(const void *a
, const void *b
);
59 extern int git_index_entry_icmp(const void *a
, const void *b
);
61 /* Index entry search functions for search using a search spec */
62 extern int git_index_entry_srch(const void *a
, const void *b
);
63 extern int git_index_entry_isrch(const void *a
, const void *b
);
65 /* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
66 * (but not setting an error message).
68 * `at_pos` is set to the position where it is or would be inserted.
69 * Pass `path_len` as strlen of path or 0 to call strlen internally.
71 extern int git_index__find_pos(
72 size_t *at_pos
, git_index
*index
, const char *path
, size_t path_len
, int stage
);
74 extern void git_index__set_ignore_case(git_index
*index
, bool ignore_case
);
76 extern unsigned int git_index__create_mode(unsigned int mode
);
78 GIT_INLINE(const git_futils_filestamp
*) git_index__filestamp(git_index
*index
)
83 extern int git_index__changed_relative_to(git_index
*index
, const git_futils_filestamp
*fs
);
85 /* Copy the current entries vector *and* increment the index refcount.
86 * Call `git_index__release_snapshot` when done.
88 extern int git_index_snapshot_new(git_vector
*snap
, git_index
*index
);
89 extern void git_index_snapshot_release(git_vector
*snap
, git_index
*index
);
91 /* Allow searching in a snapshot; entries must already be sorted! */
92 extern int git_index_snapshot_find(
93 size_t *at_pos
, git_vector
*snap
, git_vector_cmp entry_srch
,
94 const char *path
, size_t path_len
, int stage
);
96 /* Replace an index with a new index */
97 int git_index_read_index(git_index
*index
, const git_index
*new_index
);
102 unsigned int should_write
:1;
105 #define GIT_INDEXWRITER_INIT { NULL, GIT_FILEBUF_INIT }
107 /* Lock the index for eventual writing. */
108 extern int git_indexwriter_init(git_indexwriter
*writer
, git_index
*index
);
110 /* Lock the index for eventual writing by a repository operation: a merge,
111 * revert, cherry-pick or a rebase. Note that the given checkout strategy
112 * will be updated for the operation's use so that checkout will not write
115 extern int git_indexwriter_init_for_operation(
116 git_indexwriter
*writer
,
117 git_repository
*repo
,
118 unsigned int *checkout_strategy
);
120 /* Write the index and unlock it. */
121 extern int git_indexwriter_commit(git_indexwriter
*writer
);
123 /* Cleanup an index writing session, unlocking the file (if it is still
124 * locked and freeing any data structures.
126 extern void git_indexwriter_cleanup(git_indexwriter
*writer
);