]>
Commit | Line | Data |
---|---|---|
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 |
36 | extern bool git_repository__fsync_gitdir; |
37 | ||
f2c25d18 VM |
38 | /** Cvar cache identifiers */ |
39 | typedef 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 */ | |
c25aa7cd | 54 | GIT_CONFIGMAP_LONGPATHS, /* core.longpaths */ |
22a2d3d5 UG |
55 | GIT_CONFIGMAP_CACHE_MAX |
56 | } git_configmap_item; | |
f2c25d18 VM |
57 | |
58 | /** | |
22a2d3d5 | 59 | * Configuration map value enumerations |
f2c25d18 | 60 | * |
22a2d3d5 UG |
61 | * These are the values that are actually stored in the configmap cache, |
62 | * instead of their string equivalents. These values are internal and | |
63 | * symbolic; make sure that none of them is set to `-1`, since that is | |
64 | * the unique identifier for "not cached" | |
f2c25d18 VM |
65 | */ |
66 | typedef enum { | |
67 | /* The value hasn't been loaded from the cache yet */ | |
22a2d3d5 | 68 | GIT_CONFIGMAP_NOT_CACHED = -1, |
f2c25d18 VM |
69 | |
70 | /* core.safecrlf: false, 'fail', 'warn' */ | |
71 | GIT_SAFE_CRLF_FALSE = 0, | |
72 | GIT_SAFE_CRLF_FAIL = 1, | |
73 | GIT_SAFE_CRLF_WARN = 2, | |
74 | ||
75 | /* core.autocrlf: false, true, 'input; */ | |
76 | GIT_AUTO_CRLF_FALSE = 0, | |
77 | GIT_AUTO_CRLF_TRUE = 1, | |
78 | GIT_AUTO_CRLF_INPUT = 2, | |
79 | GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE, | |
80 | ||
81 | /* core.eol: unset, 'crlf', 'lf', 'native' */ | |
82 | GIT_EOL_UNSET = 0, | |
83 | GIT_EOL_CRLF = 1, | |
84 | GIT_EOL_LF = 2, | |
85 | #ifdef GIT_WIN32 | |
86 | GIT_EOL_NATIVE = GIT_EOL_CRLF, | |
87 | #else | |
88 | GIT_EOL_NATIVE = GIT_EOL_LF, | |
89 | #endif | |
ab01cbd4 RB |
90 | GIT_EOL_DEFAULT = GIT_EOL_NATIVE, |
91 | ||
92 | /* core.symlinks: bool */ | |
22a2d3d5 | 93 | GIT_SYMLINKS_DEFAULT = GIT_CONFIGMAP_TRUE, |
ab01cbd4 | 94 | /* core.ignorecase */ |
22a2d3d5 | 95 | GIT_IGNORECASE_DEFAULT = GIT_CONFIGMAP_FALSE, |
ab01cbd4 | 96 | /* core.filemode */ |
22a2d3d5 | 97 | GIT_FILEMODE_DEFAULT = GIT_CONFIGMAP_TRUE, |
ab01cbd4 | 98 | /* core.ignorestat */ |
22a2d3d5 | 99 | GIT_IGNORESTAT_DEFAULT = GIT_CONFIGMAP_FALSE, |
ab01cbd4 | 100 | /* core.trustctime */ |
22a2d3d5 | 101 | GIT_TRUSTCTIME_DEFAULT = GIT_CONFIGMAP_TRUE, |
ab01cbd4 RB |
102 | /* core.abbrev */ |
103 | GIT_ABBREV_DEFAULT = 7, | |
2fe54afa | 104 | /* core.precomposeunicode */ |
22a2d3d5 | 105 | GIT_PRECOMPOSE_DEFAULT = GIT_CONFIGMAP_FALSE, |
855c66de | 106 | /* core.safecrlf */ |
22a2d3d5 | 107 | GIT_SAFE_CRLF_DEFAULT = GIT_CONFIGMAP_FALSE, |
2b52a0bf | 108 | /* core.logallrefupdates */ |
22a2d3d5 UG |
109 | GIT_LOGALLREFUPDATES_FALSE = GIT_CONFIGMAP_FALSE, |
110 | GIT_LOGALLREFUPDATES_TRUE = GIT_CONFIGMAP_TRUE, | |
2b52a0bf | 111 | GIT_LOGALLREFUPDATES_UNSET = 2, |
ac3d33df | 112 | GIT_LOGALLREFUPDATES_ALWAYS = 3, |
2b52a0bf | 113 | GIT_LOGALLREFUPDATES_DEFAULT = GIT_LOGALLREFUPDATES_UNSET, |
ec74b40c | 114 | /* core.protectHFS */ |
22a2d3d5 | 115 | GIT_PROTECTHFS_DEFAULT = GIT_CONFIGMAP_FALSE, |
ec74b40c | 116 | /* core.protectNTFS */ |
22a2d3d5 | 117 | GIT_PROTECTNTFS_DEFAULT = GIT_CONFIGMAP_TRUE, |
1c04a96b | 118 | /* core.fsyncObjectFiles */ |
22a2d3d5 | 119 | GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CONFIGMAP_FALSE, |
c25aa7cd PP |
120 | /* core.longpaths */ |
121 | GIT_LONGPATHS_DEFAULT = GIT_CONFIGMAP_FALSE, | |
22a2d3d5 | 122 | } git_configmap_value; |
f2c25d18 | 123 | |
662880ca RB |
124 | /* internal repository init flags */ |
125 | enum { | |
126 | GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16), | |
127 | GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17), | |
128 | GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18), | |
129 | }; | |
130 | ||
662880ca | 131 | /** Internal structure for repository object */ |
3315782c | 132 | struct git_repository { |
9462c471 | 133 | git_odb *_odb; |
d00d5464 | 134 | git_refdb *_refdb; |
9462c471 VM |
135 | git_config *_config; |
136 | git_index *_index; | |
48c27f86 | 137 | |
72a3fe42 | 138 | git_cache objects; |
40ed4990 | 139 | git_attr_cache *attrcache; |
114f5a6c | 140 | git_diff_driver_registry *diff_drivers; |
6fd195d7 | 141 | |
84f56cb0 PS |
142 | char *gitlink; |
143 | char *gitdir; | |
c09fd54e | 144 | char *commondir; |
9462c471 | 145 | char *workdir; |
bade5194 | 146 | char *namespace; |
6fd195d7 | 147 | |
659cf202 CMN |
148 | char *ident_name; |
149 | char *ident_email; | |
150 | ||
4196dd8e ET |
151 | git_array_t(git_buf) reserved_names; |
152 | ||
153 | unsigned is_bare:1; | |
79ab3ef6 | 154 | unsigned is_worktree:1; |
83ad46f7 | 155 | |
6b2a1941 | 156 | unsigned int lru_counter; |
450b40ca | 157 | |
c25aa7cd | 158 | git_atomic32 attr_session_key; |
9f779aac | 159 | |
c25aa7cd | 160 | intptr_t configmap_cache[GIT_CONFIGMAP_CACHE_MAX]; |
4d99c4cf | 161 | git_strmap *submodule_cache; |
3315782c VM |
162 | }; |
163 | ||
95dfb031 RB |
164 | GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo) |
165 | { | |
40ed4990 | 166 | return repo->attrcache; |
95dfb031 RB |
167 | } |
168 | ||
f917481e | 169 | int git_repository_head_tree(git_tree **tree, git_repository *repo); |
854b5c70 | 170 | int git_repository_create_head(const char *git_dir, const char *ref_name); |
f917481e | 171 | |
22a2d3d5 | 172 | typedef int (*git_repository_foreach_worktree_cb)(git_repository *, void *); |
74511aa2 | 173 | |
22a2d3d5 UG |
174 | int git_repository_foreach_worktree(git_repository *repo, |
175 | git_repository_foreach_worktree_cb cb, | |
176 | void *payload); | |
74511aa2 | 177 | |
f2c25d18 VM |
178 | /* |
179 | * Weak pointers to repository internals. | |
180 | * | |
181 | * The returned pointers do not need to be freed. Do not keep | |
182 | * permanent references to these (i.e. between API calls), since they may | |
183 | * become invalidated if the user replaces a repository internal. | |
184 | */ | |
9462c471 VM |
185 | int git_repository_config__weakptr(git_config **out, git_repository *repo); |
186 | int git_repository_odb__weakptr(git_odb **out, git_repository *repo); | |
d00d5464 | 187 | int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo); |
9462c471 VM |
188 | int git_repository_index__weakptr(git_index **out, git_repository *repo); |
189 | ||
f2c25d18 | 190 | /* |
22a2d3d5 | 191 | * Configuration map cache |
f2c25d18 VM |
192 | * |
193 | * Efficient access to the most used config variables of a repository. | |
b874629b | 194 | * The cache is cleared every time the config backend is replaced. |
f2c25d18 | 195 | */ |
22a2d3d5 UG |
196 | int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item); |
197 | void git_repository__configmap_lookup_cache_clear(git_repository *repo); | |
f2c25d18 | 198 | |
ced8d142 | 199 | GIT_INLINE(int) git_repository__ensure_not_bare( |
200 | git_repository *repo, | |
201 | const char *operation_name) | |
202 | { | |
203 | if (!git_repository_is_bare(repo)) | |
204 | return 0; | |
205 | ||
ac3d33df JK |
206 | git_error_set( |
207 | GIT_ERROR_REPOSITORY, | |
909d5494 | 208 | "cannot %s. This operation is not allowed against bare repositories.", |
ced8d142 | 209 | operation_name); |
210 | ||
211 | return GIT_EBAREREPO; | |
212 | } | |
213 | ||
867a36f3 ET |
214 | int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head); |
215 | ||
bab0b9f2 ET |
216 | int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len); |
217 | ||
4196dd8e ET |
218 | /* The default "reserved names" for a repository */ |
219 | extern git_buf git_repository__reserved_names_win32[]; | |
220 | extern size_t git_repository__reserved_names_win32_len; | |
221 | ||
222 | extern git_buf git_repository__reserved_names_posix[]; | |
223 | extern size_t git_repository__reserved_names_posix_len; | |
a64119e3 | 224 | |
4196dd8e ET |
225 | /* |
226 | * Gets any "reserved names" in the repository. This will return paths | |
227 | * that should not be allowed in the repository (like ".git") to avoid | |
228 | * conflicting with the repository path, or with alternate mechanisms to | |
229 | * the repository path (eg, "GIT~1"). Every attempt will be made to look | |
230 | * up all possible reserved names - if there was a conflict for the shortname | |
231 | * GIT~1, for example, this function will try to look up the alternate | |
232 | * shortname. If that fails, this function returns false, but out and outlen | |
233 | * will still be populated with good defaults. | |
a64119e3 | 234 | */ |
4196dd8e ET |
235 | bool git_repository__reserved_names( |
236 | git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs); | |
a64119e3 | 237 | |
22a2d3d5 UG |
238 | /* |
239 | * The default branch for the repository; the `init.defaultBranch` | |
240 | * configuration option, if set, or `master` if it is not. | |
241 | */ | |
242 | int git_repository_initialbranch(git_buf *out, git_repository *repo); | |
243 | ||
c25aa7cd PP |
244 | /* |
245 | * Given a relative `path`, this makes it absolute based on the | |
246 | * repository's working directory. This will perform validation | |
247 | * to ensure that the path is not longer than MAX_PATH on Windows | |
248 | * (unless `core.longpaths` is set in the repo config). | |
249 | */ | |
250 | int git_repository_workdir_path(git_buf *out, git_repository *repo, const char *path); | |
251 | ||
252 | int git_repository__extensions(char ***out, size_t *out_len); | |
253 | int git_repository__set_extensions(const char **extensions, size_t len); | |
254 | void git_repository__free_extensions(void); | |
255 | ||
3315782c | 256 | #endif |