]> git.proxmox.com Git - libgit2.git/blame - src/repository.h
install as examples
[libgit2.git] / src / repository.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 */
3315782c
VM
7#ifndef INCLUDE_repository_h__
8#define INCLUDE_repository_h__
9
eae0bfdc
PP
10#include "common.h"
11
44908fe7
VM
12#include "git2/common.h"
13#include "git2/oid.h"
14#include "git2/odb.h"
15#include "git2/repository.h"
f335b42c 16#include "git2/object.h"
ab01cbd4 17#include "git2/config.h"
3315782c 18
4196dd8e 19#include "array.h"
72a3fe42 20#include "cache.h"
9282e921 21#include "refs.h"
afeecf4f 22#include "buffer.h"
c6ac28fd 23#include "object.h"
5540d947 24#include "attrcache.h"
69b6ffc4 25#include "submodule.h"
114f5a6c 26#include "diff_driver.h"
3315782c 27
d2d6912e 28#define DOT_GIT ".git"
29#define GIT_DIR DOT_GIT "/"
ce8cd006
BR
30#define GIT_DIR_MODE 0755
31#define GIT_BARE_DIR_MODE 0777
d2d6912e 32
4196dd8e
ET
33/* Default DOS-compatible 8.3 "short name" for a git repository, "GIT~1" */
34#define GIT_DIR_SHORTNAME "GIT~1"
35
6c23704d
PS
36extern bool git_repository__fsync_gitdir;
37
f2c25d18
VM
38/** Cvar cache identifiers */
39typedef enum {
22a2d3d5
UG
40 GIT_CONFIGMAP_AUTO_CRLF = 0, /* core.autocrlf */
41 GIT_CONFIGMAP_EOL, /* core.eol */
42 GIT_CONFIGMAP_SYMLINKS, /* core.symlinks */
43 GIT_CONFIGMAP_IGNORECASE, /* core.ignorecase */
44 GIT_CONFIGMAP_FILEMODE, /* core.filemode */
45 GIT_CONFIGMAP_IGNORESTAT, /* core.ignorestat */
46 GIT_CONFIGMAP_TRUSTCTIME, /* core.trustctime */
47 GIT_CONFIGMAP_ABBREV, /* core.abbrev */
48 GIT_CONFIGMAP_PRECOMPOSE, /* core.precomposeunicode */
49 GIT_CONFIGMAP_SAFE_CRLF, /* core.safecrlf */
50 GIT_CONFIGMAP_LOGALLREFUPDATES, /* core.logallrefupdates */
51 GIT_CONFIGMAP_PROTECTHFS, /* core.protectHFS */
52 GIT_CONFIGMAP_PROTECTNTFS, /* core.protectNTFS */
53 GIT_CONFIGMAP_FSYNCOBJECTFILES, /* core.fsyncObjectFiles */
54 GIT_CONFIGMAP_CACHE_MAX
55} git_configmap_item;
f2c25d18
VM
56
57/**
22a2d3d5 58 * Configuration map value enumerations
f2c25d18 59 *
22a2d3d5
UG
60 * These are the values that are actually stored in the configmap cache,
61 * instead of their string equivalents. These values are internal and
62 * symbolic; make sure that none of them is set to `-1`, since that is
63 * the unique identifier for "not cached"
f2c25d18
VM
64 */
65typedef enum {
66 /* The value hasn't been loaded from the cache yet */
22a2d3d5 67 GIT_CONFIGMAP_NOT_CACHED = -1,
f2c25d18
VM
68
69 /* core.safecrlf: false, 'fail', 'warn' */
70 GIT_SAFE_CRLF_FALSE = 0,
71 GIT_SAFE_CRLF_FAIL = 1,
72 GIT_SAFE_CRLF_WARN = 2,
73
74 /* core.autocrlf: false, true, 'input; */
75 GIT_AUTO_CRLF_FALSE = 0,
76 GIT_AUTO_CRLF_TRUE = 1,
77 GIT_AUTO_CRLF_INPUT = 2,
78 GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE,
79
80 /* core.eol: unset, 'crlf', 'lf', 'native' */
81 GIT_EOL_UNSET = 0,
82 GIT_EOL_CRLF = 1,
83 GIT_EOL_LF = 2,
84#ifdef GIT_WIN32
85 GIT_EOL_NATIVE = GIT_EOL_CRLF,
86#else
87 GIT_EOL_NATIVE = GIT_EOL_LF,
88#endif
ab01cbd4
RB
89 GIT_EOL_DEFAULT = GIT_EOL_NATIVE,
90
91 /* core.symlinks: bool */
22a2d3d5 92 GIT_SYMLINKS_DEFAULT = GIT_CONFIGMAP_TRUE,
ab01cbd4 93 /* core.ignorecase */
22a2d3d5 94 GIT_IGNORECASE_DEFAULT = GIT_CONFIGMAP_FALSE,
ab01cbd4 95 /* core.filemode */
22a2d3d5 96 GIT_FILEMODE_DEFAULT = GIT_CONFIGMAP_TRUE,
ab01cbd4 97 /* core.ignorestat */
22a2d3d5 98 GIT_IGNORESTAT_DEFAULT = GIT_CONFIGMAP_FALSE,
ab01cbd4 99 /* core.trustctime */
22a2d3d5 100 GIT_TRUSTCTIME_DEFAULT = GIT_CONFIGMAP_TRUE,
ab01cbd4
RB
101 /* core.abbrev */
102 GIT_ABBREV_DEFAULT = 7,
2fe54afa 103 /* core.precomposeunicode */
22a2d3d5 104 GIT_PRECOMPOSE_DEFAULT = GIT_CONFIGMAP_FALSE,
855c66de 105 /* core.safecrlf */
22a2d3d5 106 GIT_SAFE_CRLF_DEFAULT = GIT_CONFIGMAP_FALSE,
2b52a0bf 107 /* core.logallrefupdates */
22a2d3d5
UG
108 GIT_LOGALLREFUPDATES_FALSE = GIT_CONFIGMAP_FALSE,
109 GIT_LOGALLREFUPDATES_TRUE = GIT_CONFIGMAP_TRUE,
2b52a0bf 110 GIT_LOGALLREFUPDATES_UNSET = 2,
ac3d33df 111 GIT_LOGALLREFUPDATES_ALWAYS = 3,
2b52a0bf 112 GIT_LOGALLREFUPDATES_DEFAULT = GIT_LOGALLREFUPDATES_UNSET,
ec74b40c 113 /* core.protectHFS */
22a2d3d5 114 GIT_PROTECTHFS_DEFAULT = GIT_CONFIGMAP_FALSE,
ec74b40c 115 /* core.protectNTFS */
22a2d3d5 116 GIT_PROTECTNTFS_DEFAULT = GIT_CONFIGMAP_TRUE,
1c04a96b 117 /* core.fsyncObjectFiles */
22a2d3d5
UG
118 GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CONFIGMAP_FALSE,
119} git_configmap_value;
f2c25d18 120
662880ca
RB
121/* internal repository init flags */
122enum {
123 GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16),
124 GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17),
125 GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18),
126};
127
662880ca 128/** Internal structure for repository object */
3315782c 129struct git_repository {
9462c471 130 git_odb *_odb;
d00d5464 131 git_refdb *_refdb;
9462c471
VM
132 git_config *_config;
133 git_index *_index;
48c27f86 134
72a3fe42 135 git_cache objects;
40ed4990 136 git_attr_cache *attrcache;
114f5a6c 137 git_diff_driver_registry *diff_drivers;
6fd195d7 138
84f56cb0
PS
139 char *gitlink;
140 char *gitdir;
c09fd54e 141 char *commondir;
9462c471 142 char *workdir;
bade5194 143 char *namespace;
6fd195d7 144
659cf202
CMN
145 char *ident_name;
146 char *ident_email;
147
4196dd8e
ET
148 git_array_t(git_buf) reserved_names;
149
150 unsigned is_bare:1;
79ab3ef6 151 unsigned is_worktree:1;
83ad46f7 152
6b2a1941 153 unsigned int lru_counter;
450b40ca 154
9f779aac
ET
155 git_atomic attr_session_key;
156
22a2d3d5 157 git_configmap_value configmap_cache[GIT_CONFIGMAP_CACHE_MAX];
4d99c4cf 158 git_strmap *submodule_cache;
3315782c
VM
159};
160
95dfb031
RB
161GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
162{
40ed4990 163 return repo->attrcache;
95dfb031
RB
164}
165
f917481e 166int git_repository_head_tree(git_tree **tree, git_repository *repo);
854b5c70 167int git_repository_create_head(const char *git_dir, const char *ref_name);
f917481e 168
22a2d3d5 169typedef int (*git_repository_foreach_worktree_cb)(git_repository *, void *);
74511aa2 170
22a2d3d5
UG
171int git_repository_foreach_worktree(git_repository *repo,
172 git_repository_foreach_worktree_cb cb,
173 void *payload);
74511aa2 174
f2c25d18
VM
175/*
176 * Weak pointers to repository internals.
177 *
178 * The returned pointers do not need to be freed. Do not keep
179 * permanent references to these (i.e. between API calls), since they may
180 * become invalidated if the user replaces a repository internal.
181 */
9462c471
VM
182int git_repository_config__weakptr(git_config **out, git_repository *repo);
183int git_repository_odb__weakptr(git_odb **out, git_repository *repo);
d00d5464 184int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo);
9462c471
VM
185int git_repository_index__weakptr(git_index **out, git_repository *repo);
186
f2c25d18 187/*
22a2d3d5 188 * Configuration map cache
f2c25d18
VM
189 *
190 * Efficient access to the most used config variables of a repository.
b874629b 191 * The cache is cleared every time the config backend is replaced.
f2c25d18 192 */
22a2d3d5
UG
193int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item);
194void git_repository__configmap_lookup_cache_clear(git_repository *repo);
f2c25d18 195
ced8d142 196GIT_INLINE(int) git_repository__ensure_not_bare(
197 git_repository *repo,
198 const char *operation_name)
199{
200 if (!git_repository_is_bare(repo))
201 return 0;
202
ac3d33df
JK
203 git_error_set(
204 GIT_ERROR_REPOSITORY,
909d5494 205 "cannot %s. This operation is not allowed against bare repositories.",
ced8d142 206 operation_name);
207
208 return GIT_EBAREREPO;
209}
210
867a36f3
ET
211int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head);
212
bab0b9f2
ET
213int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len);
214
4196dd8e
ET
215/* The default "reserved names" for a repository */
216extern git_buf git_repository__reserved_names_win32[];
217extern size_t git_repository__reserved_names_win32_len;
218
219extern git_buf git_repository__reserved_names_posix[];
220extern size_t git_repository__reserved_names_posix_len;
a64119e3 221
4196dd8e
ET
222/*
223 * Gets any "reserved names" in the repository. This will return paths
224 * that should not be allowed in the repository (like ".git") to avoid
225 * conflicting with the repository path, or with alternate mechanisms to
226 * the repository path (eg, "GIT~1"). Every attempt will be made to look
227 * up all possible reserved names - if there was a conflict for the shortname
228 * GIT~1, for example, this function will try to look up the alternate
229 * shortname. If that fails, this function returns false, but out and outlen
230 * will still be populated with good defaults.
a64119e3 231 */
4196dd8e
ET
232bool git_repository__reserved_names(
233 git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs);
a64119e3 234
22a2d3d5
UG
235/*
236 * The default branch for the repository; the `init.defaultBranch`
237 * configuration option, if set, or `master` if it is not.
238 */
239int git_repository_initialbranch(git_buf *out, git_repository *repo);
240
3315782c 241#endif