]> git.proxmox.com Git - libgit2.git/blob - src/index.h
Merge pull request #2885 from JIghtuse/master
[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 "tree-cache.h"
14 #include "git2/odb.h"
15 #include "git2/index.h"
16
17 #define GIT_INDEX_FILE "index"
18 #define GIT_INDEX_FILE_MODE 0666
19
20 struct git_index {
21 git_refcount rc;
22
23 char *index_file_path;
24 git_futils_filestamp stamp;
25
26 git_vector entries;
27
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 */
31
32 unsigned int on_disk:1;
33 unsigned int ignore_case:1;
34 unsigned int distrust_filemode:1;
35 unsigned int no_symlinks:1;
36
37 git_tree_cache *tree;
38 git_pool tree_pool;
39
40 git_vector names;
41 git_vector reuc;
42
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;
47 };
48
49 struct git_index_conflict_iterator {
50 git_index *index;
51 size_t cur;
52 };
53
54 extern void git_index_entry__init_from_stat(
55 git_index_entry *entry, struct stat *st, bool trust_mode);
56
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);
60
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);
64
65 /* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
66 * (but not setting an error message).
67 *
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.
70 */
71 extern int git_index__find_pos(
72 size_t *at_pos, git_index *index, const char *path, size_t path_len, int stage);
73
74 extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
75
76 extern unsigned int git_index__create_mode(unsigned int mode);
77
78 GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index)
79 {
80 return &index->stamp;
81 }
82
83 extern int git_index__changed_relative_to(git_index *index, const git_futils_filestamp *fs);
84
85 /* Copy the current entries vector *and* increment the index refcount.
86 * Call `git_index__release_snapshot` when done.
87 */
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);
90
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);
95
96
97 typedef struct {
98 git_index *index;
99 git_filebuf file;
100 unsigned int should_write:1;
101 } git_indexwriter;
102
103 #define GIT_INDEXWRITER_INIT { NULL, GIT_FILEBUF_INIT }
104
105 /* Lock the index for eventual writing. */
106 extern int git_indexwriter_init(git_indexwriter *writer, git_index *index);
107
108 /* Lock the index for eventual writing by a repository operation: a merge,
109 * revert, cherry-pick or a rebase. Note that the given checkout strategy
110 * will be updated for the operation's use so that checkout will not write
111 * the index.
112 */
113 extern int git_indexwriter_init_for_operation(
114 git_indexwriter *writer,
115 git_repository *repo,
116 unsigned int *checkout_strategy);
117
118 /* Write the index and unlock it. */
119 extern int git_indexwriter_commit(git_indexwriter *writer);
120
121 /* Cleanup an index writing session, unlocking the file (if it is still
122 * locked and freeing any data structures.
123 */
124 extern void git_indexwriter_cleanup(git_indexwriter *writer);
125
126 #endif