]> git.proxmox.com Git - libgit2.git/blob - src/index.h
Merge pull request #2213 from ethomson/safecrlf
[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
39 git_vector names;
40 git_vector reuc;
41
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;
46 };
47
48 struct git_index_conflict_iterator {
49 git_index *index;
50 size_t cur;
51 };
52
53 extern void git_index_entry__init_from_stat(
54 git_index_entry *entry, struct stat *st, bool trust_mode);
55
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);
59
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);
63
64 /* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
65 * (but not setting an error message).
66 *
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.
69 */
70 extern int git_index__find_pos(
71 size_t *at_pos, git_index *index, const char *path, size_t path_len, int stage);
72
73 extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
74
75 extern unsigned int git_index__create_mode(unsigned int mode);
76
77 GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index)
78 {
79 return &index->stamp;
80 }
81
82 extern int git_index__changed_relative_to(git_index *index, const git_futils_filestamp *fs);
83
84 /* Copy the current entries vector *and* increment the index refcount.
85 * Call `git_index__release_snapshot` when done.
86 */
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);
89
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);
94
95
96 #endif