]> git.proxmox.com Git - libgit2.git/blob - src/index.h
Merge branch 'cmn/ignore-dir-check'
[libgit2.git] / src / index.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
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.
6 */
7 #ifndef INCLUDE_index_h__
8 #define INCLUDE_index_h__
9
10 #include "fileops.h"
11 #include "filebuf.h"
12 #include "vector.h"
13 #include "idxmap.h"
14 #include "tree-cache.h"
15 #include "git2/odb.h"
16 #include "git2/index.h"
17
18 #define GIT_INDEX_FILE "index"
19 #define GIT_INDEX_FILE_MODE 0666
20
21 struct git_index {
22 git_refcount rc;
23
24 char *index_file_path;
25 git_futils_filestamp stamp;
26 git_oid checksum; /* checksum at the end of the file */
27
28 git_vector entries;
29 git_idxmap *entries_map;
30
31 git_mutex lock; /* lock held while entries is being changed */
32 git_vector deleted; /* deleted entries if readers > 0 */
33 git_atomic readers; /* number of active iterators */
34
35 unsigned int on_disk:1;
36 unsigned int ignore_case:1;
37 unsigned int distrust_filemode:1;
38 unsigned int no_symlinks:1;
39
40 git_tree_cache *tree;
41 git_pool tree_pool;
42
43 git_vector names;
44 git_vector reuc;
45
46 git_vector_cmp entries_cmp_path;
47 git_vector_cmp entries_search;
48 git_vector_cmp entries_search_path;
49 git_vector_cmp reuc_search;
50 };
51
52 struct git_index_conflict_iterator {
53 git_index *index;
54 size_t cur;
55 };
56
57 extern void git_index_entry__init_from_stat(
58 git_index_entry *entry, struct stat *st, bool trust_mode);
59
60 /* Index entry comparison functions for array sorting */
61 extern int git_index_entry_cmp(const void *a, const void *b);
62 extern int git_index_entry_icmp(const void *a, const void *b);
63
64 /* Index entry search functions for search using a search spec */
65 extern int git_index_entry_srch(const void *a, const void *b);
66 extern int git_index_entry_isrch(const void *a, const void *b);
67
68 /* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
69 * (but not setting an error message).
70 *
71 * `at_pos` is set to the position where it is or would be inserted.
72 * Pass `path_len` as strlen of path or 0 to call strlen internally.
73 */
74 extern int git_index__find_pos(
75 size_t *at_pos, git_index *index, const char *path, size_t path_len, int stage);
76
77 extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
78
79 extern unsigned int git_index__create_mode(unsigned int mode);
80
81 GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index)
82 {
83 return &index->stamp;
84 }
85
86 extern int git_index__changed_relative_to(git_index *index, const git_oid *checksum);
87
88 /* Copy the current entries vector *and* increment the index refcount.
89 * Call `git_index__release_snapshot` when done.
90 */
91 extern int git_index_snapshot_new(git_vector *snap, git_index *index);
92 extern void git_index_snapshot_release(git_vector *snap, git_index *index);
93
94 /* Allow searching in a snapshot; entries must already be sorted! */
95 extern int git_index_snapshot_find(
96 size_t *at_pos, git_vector *snap, git_vector_cmp entry_srch,
97 const char *path, size_t path_len, int stage);
98
99 /* Replace an index with a new index */
100 int git_index_read_index(git_index *index, const git_index *new_index);
101
102 typedef struct {
103 git_index *index;
104 git_filebuf file;
105 unsigned int should_write:1;
106 } git_indexwriter;
107
108 #define GIT_INDEXWRITER_INIT { NULL, GIT_FILEBUF_INIT }
109
110 /* Lock the index for eventual writing. */
111 extern int git_indexwriter_init(git_indexwriter *writer, git_index *index);
112
113 /* Lock the index for eventual writing by a repository operation: a merge,
114 * revert, cherry-pick or a rebase. Note that the given checkout strategy
115 * will be updated for the operation's use so that checkout will not write
116 * the index.
117 */
118 extern int git_indexwriter_init_for_operation(
119 git_indexwriter *writer,
120 git_repository *repo,
121 unsigned int *checkout_strategy);
122
123 /* Write the index and unlock it. */
124 extern int git_indexwriter_commit(git_indexwriter *writer);
125
126 /* Cleanup an index writing session, unlocking the file (if it is still
127 * locked and freeing any data structures.
128 */
129 extern void git_indexwriter_cleanup(git_indexwriter *writer);
130
131 #endif