]> git.proxmox.com Git - libgit2.git/blame - src/index.h
merge-like operations: lock index while working
[libgit2.git] / src / index.h
CommitLineData
bb742ede 1/*
359fc2d2 2 * Copyright (C) the libgit2 contributors. All rights reserved.
bb742ede
VM
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 */
68535125
VM
7#ifndef INCLUDE_index_h__
8#define INCLUDE_index_h__
9
10#include "fileops.h"
817c2820 11#include "filebuf.h"
c4034e63 12#include "vector.h"
b4171320 13#include "tree-cache.h"
44908fe7
VM
14#include "git2/odb.h"
15#include "git2/index.h"
68535125 16
01ad7b3a
BR
17#define GIT_INDEX_FILE "index"
18#define GIT_INDEX_FILE_MODE 0666
19
68535125 20struct git_index {
9462c471
VM
21 git_refcount rc;
22
68535125 23 char *index_file_path;
8ff0f325 24 git_futils_filestamp stamp;
dac16048 25
c4034e63 26 git_vector entries;
68535125 27
dac16048
RB
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 */
da825c92 31
dac16048 32 unsigned int on_disk:1;
da825c92
RB
33 unsigned int ignore_case:1;
34 unsigned int distrust_filemode:1;
35 unsigned int no_symlinks:1;
36
b4171320 37 git_tree_cache *tree;
19c88310 38 git_pool tree_pool;
4c0b6a6d 39
0462fba5 40 git_vector names;
f45ec1a0 41 git_vector reuc;
ec40b7f9 42
f45ec1a0 43 git_vector_cmp entries_cmp_path;
ec40b7f9 44 git_vector_cmp entries_search;
f45ec1a0
ET
45 git_vector_cmp entries_search_path;
46 git_vector_cmp reuc_search;
68535125
VM
47};
48
0e0108f7
ET
49struct git_index_conflict_iterator {
50 git_index *index;
51 size_t cur;
52};
53
d2ce27dd 54extern void git_index_entry__init_from_stat(
14997dc5 55 git_index_entry *entry, struct stat *st, bool trust_mode);
7c7ff7d1 56
3b4c401a
RB
57/* Index entry comparison functions for array sorting */
58extern int git_index_entry_cmp(const void *a, const void *b);
59extern int git_index_entry_icmp(const void *a, const void *b);
60
61/* Index entry search functions for search using a search spec */
62extern int git_index_entry_srch(const void *a, const void *b);
63extern int git_index_entry_isrch(const void *a, const void *b);
55cbd05b 64
52bb0476
RB
65/* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
66 * (but not setting an error message).
67 *
3dbee456
RB
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 */
52bb0476 71extern int git_index__find_pos(
3158e2fe 72 size_t *at_pos, git_index *index, const char *path, size_t path_len, int stage);
d2ce27dd 73
cb53669e 74extern void git_index__set_ignore_case(git_index *index, bool ignore_case);
3f0d0c85 75
05d47768
ET
76extern unsigned int git_index__create_mode(unsigned int mode);
77
db0e7878
RB
78GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index)
79{
80 return &index->stamp;
81}
82
83extern int git_index__changed_relative_to(git_index *index, const git_futils_filestamp *fs);
84
54edbb98
RB
85/* Copy the current entries vector *and* increment the index refcount.
86 * Call `git_index__release_snapshot` when done.
87 */
52bb0476
RB
88extern int git_index_snapshot_new(git_vector *snap, git_index *index);
89extern void git_index_snapshot_release(git_vector *snap, git_index *index);
54edbb98
RB
90
91/* Allow searching in a snapshot; entries must already be sorted! */
52bb0476
RB
92extern int git_index_snapshot_find(
93 size_t *at_pos, git_vector *snap, git_vector_cmp entry_srch,
54edbb98
RB
94 const char *path, size_t path_len, int stage);
95
52bb0476 96
55798fd1
ET
97typedef struct {
98 git_index *index;
99 git_filebuf file;
100} git_indexwriter;
101
102#define GIT_INDEXWRITER_INIT { NULL, GIT_FILEBUF_INIT }
103
104/* Lock the index for eventual writing. */
105extern int git_indexwriter_init(git_indexwriter *writer, git_index *index);
106
107/* Write the index and unlock it. */
108extern int git_indexwriter_commit(git_indexwriter *writer);
109
110/* Cleanup an index writing session, unlocking the file (if it is still
111 * locked and freeing any data structures.
112 */
113extern void git_indexwriter_cleanup(git_indexwriter *writer);
114
68535125 115#endif