index.h 2.8 KB
Newer Older
Vicent Marti committed
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
Vicent Marti committed
3 4 5 6
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
7 8 9 10
#ifndef INCLUDE_index_h__
#define INCLUDE_index_h__

#include "fileops.h"
11
#include "filebuf.h"
12
#include "vector.h"
13
#include "tree-cache.h"
14 15
#include "git2/odb.h"
#include "git2/index.h"
16

17 18 19
#define GIT_INDEX_FILE "index"
#define GIT_INDEX_FILE_MODE 0666

20
struct git_index {
21 22
	git_refcount rc;

23
	char *index_file_path;
24
	git_futils_filestamp stamp;
25

26
	git_vector entries;
27

28 29 30
	git_mutex  lock;    /* lock held while entries is being changed */
	git_vector deleted; /* deleted entries if readers > 0 */
	git_atomic readers; /* number of active iterators */
31

32
	unsigned int on_disk:1;
33 34 35 36
	unsigned int ignore_case:1;
	unsigned int distrust_filemode:1;
	unsigned int no_symlinks:1;

37
	git_tree_cache *tree;
38
	git_pool tree_pool;
39

Edward Thomson committed
40
	git_vector names;
Edward Thomson committed
41
	git_vector reuc;
42

Edward Thomson committed
43
	git_vector_cmp entries_cmp_path;
44
	git_vector_cmp entries_search;
Edward Thomson committed
45 46
	git_vector_cmp entries_search_path;
	git_vector_cmp reuc_search;
47 48
};

49 50 51 52 53
struct git_index_conflict_iterator {
	git_index *index;
	size_t cur;
};

54
extern void git_index_entry__init_from_stat(
55
	git_index_entry *entry, struct stat *st, bool trust_mode);
56

57 58 59 60 61 62 63
/* Index entry comparison functions for array sorting */
extern int git_index_entry_cmp(const void *a, const void *b);
extern int git_index_entry_icmp(const void *a, const void *b);

/* Index entry search functions for search using a search spec */
extern int git_index_entry_srch(const void *a, const void *b);
extern int git_index_entry_isrch(const void *a, const void *b);
64

65 66 67
/* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
 * (but not setting an error message).
 *
68 69 70
 * `at_pos` is set to the position where it is or would be inserted.
 * 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);
73

74
extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
75

76 77
extern unsigned int git_index__create_mode(unsigned int mode);

78 79 80 81 82 83 84
GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index)
{
   return &index->stamp;
}

extern int git_index__changed_relative_to(git_index *index, const git_futils_filestamp *fs);

85 86 87
/* Copy the current entries vector *and* increment the index refcount.
 * Call `git_index__release_snapshot` when done.
 */
88 89
extern int git_index_snapshot_new(git_vector *snap, git_index *index);
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 93
extern int git_index_snapshot_find(
	size_t *at_pos, git_vector *snap, git_vector_cmp entry_srch,
94 95
	const char *path, size_t path_len, int stage);

96

97
#endif