]>
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 | ||
44908fe7 VM |
10 | #include "git2/common.h" |
11 | #include "git2/oid.h" | |
12 | #include "git2/odb.h" | |
13 | #include "git2/repository.h" | |
f335b42c | 14 | #include "git2/object.h" |
ab01cbd4 | 15 | #include "git2/config.h" |
3315782c | 16 | |
4196dd8e | 17 | #include "array.h" |
72a3fe42 | 18 | #include "cache.h" |
9282e921 | 19 | #include "refs.h" |
afeecf4f | 20 | #include "buffer.h" |
c6ac28fd | 21 | #include "object.h" |
5540d947 | 22 | #include "attrcache.h" |
69b6ffc4 | 23 | #include "submodule.h" |
114f5a6c | 24 | #include "diff_driver.h" |
3315782c | 25 | |
d2d6912e | 26 | #define DOT_GIT ".git" |
27 | #define GIT_DIR DOT_GIT "/" | |
ce8cd006 BR |
28 | #define GIT_DIR_MODE 0755 |
29 | #define GIT_BARE_DIR_MODE 0777 | |
d2d6912e | 30 | |
4196dd8e ET |
31 | /* Default DOS-compatible 8.3 "short name" for a git repository, "GIT~1" */ |
32 | #define GIT_DIR_SHORTNAME "GIT~1" | |
33 | ||
f2c25d18 VM |
34 | /** Cvar cache identifiers */ |
35 | typedef enum { | |
36 | GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */ | |
ab01cbd4 RB |
37 | GIT_CVAR_EOL, /* core.eol */ |
38 | GIT_CVAR_SYMLINKS, /* core.symlinks */ | |
39 | GIT_CVAR_IGNORECASE, /* core.ignorecase */ | |
40 | GIT_CVAR_FILEMODE, /* core.filemode */ | |
41 | GIT_CVAR_IGNORESTAT, /* core.ignorestat */ | |
42 | GIT_CVAR_TRUSTCTIME, /* core.trustctime */ | |
43 | GIT_CVAR_ABBREV, /* core.abbrev */ | |
2fe54afa | 44 | GIT_CVAR_PRECOMPOSE, /* core.precomposeunicode */ |
855c66de | 45 | GIT_CVAR_SAFE_CRLF, /* core.safecrlf */ |
2b52a0bf | 46 | GIT_CVAR_LOGALLREFUPDATES, /* core.logallrefupdates */ |
ec74b40c ET |
47 | GIT_CVAR_PROTECTHFS, /* core.protectHFS */ |
48 | GIT_CVAR_PROTECTNTFS, /* core.protectNTFS */ | |
f2c25d18 VM |
49 | GIT_CVAR_CACHE_MAX |
50 | } git_cvar_cached; | |
51 | ||
52 | /** | |
53 | * CVAR value enumerations | |
54 | * | |
55 | * These are the values that are actually stored in the cvar cache, instead | |
56 | * of their string equivalents. These values are internal and symbolic; | |
57 | * make sure that none of them is set to `-1`, since that is the unique | |
58 | * identifier for "not cached" | |
59 | */ | |
60 | typedef enum { | |
61 | /* The value hasn't been loaded from the cache yet */ | |
62 | GIT_CVAR_NOT_CACHED = -1, | |
63 | ||
64 | /* core.safecrlf: false, 'fail', 'warn' */ | |
65 | GIT_SAFE_CRLF_FALSE = 0, | |
66 | GIT_SAFE_CRLF_FAIL = 1, | |
67 | GIT_SAFE_CRLF_WARN = 2, | |
68 | ||
69 | /* core.autocrlf: false, true, 'input; */ | |
70 | GIT_AUTO_CRLF_FALSE = 0, | |
71 | GIT_AUTO_CRLF_TRUE = 1, | |
72 | GIT_AUTO_CRLF_INPUT = 2, | |
73 | GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE, | |
74 | ||
75 | /* core.eol: unset, 'crlf', 'lf', 'native' */ | |
76 | GIT_EOL_UNSET = 0, | |
77 | GIT_EOL_CRLF = 1, | |
78 | GIT_EOL_LF = 2, | |
79 | #ifdef GIT_WIN32 | |
80 | GIT_EOL_NATIVE = GIT_EOL_CRLF, | |
81 | #else | |
82 | GIT_EOL_NATIVE = GIT_EOL_LF, | |
83 | #endif | |
ab01cbd4 RB |
84 | GIT_EOL_DEFAULT = GIT_EOL_NATIVE, |
85 | ||
86 | /* core.symlinks: bool */ | |
87 | GIT_SYMLINKS_DEFAULT = GIT_CVAR_TRUE, | |
88 | /* core.ignorecase */ | |
89 | GIT_IGNORECASE_DEFAULT = GIT_CVAR_FALSE, | |
90 | /* core.filemode */ | |
91 | GIT_FILEMODE_DEFAULT = GIT_CVAR_TRUE, | |
92 | /* core.ignorestat */ | |
93 | GIT_IGNORESTAT_DEFAULT = GIT_CVAR_FALSE, | |
94 | /* core.trustctime */ | |
95 | GIT_TRUSTCTIME_DEFAULT = GIT_CVAR_TRUE, | |
96 | /* core.abbrev */ | |
97 | GIT_ABBREV_DEFAULT = 7, | |
2fe54afa RB |
98 | /* core.precomposeunicode */ |
99 | GIT_PRECOMPOSE_DEFAULT = GIT_CVAR_FALSE, | |
855c66de ET |
100 | /* core.safecrlf */ |
101 | GIT_SAFE_CRLF_DEFAULT = GIT_CVAR_FALSE, | |
2b52a0bf RB |
102 | /* core.logallrefupdates */ |
103 | GIT_LOGALLREFUPDATES_UNSET = 2, | |
104 | GIT_LOGALLREFUPDATES_DEFAULT = GIT_LOGALLREFUPDATES_UNSET, | |
ec74b40c ET |
105 | /* core.protectHFS */ |
106 | GIT_PROTECTHFS_DEFAULT = GIT_CVAR_FALSE, | |
107 | /* core.protectNTFS */ | |
108 | GIT_PROTECTNTFS_DEFAULT = GIT_CVAR_FALSE, | |
f2c25d18 VM |
109 | } git_cvar_value; |
110 | ||
662880ca RB |
111 | /* internal repository init flags */ |
112 | enum { | |
113 | GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16), | |
114 | GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17), | |
115 | GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18), | |
116 | }; | |
117 | ||
662880ca | 118 | /** Internal structure for repository object */ |
3315782c | 119 | struct git_repository { |
9462c471 | 120 | git_odb *_odb; |
d00d5464 | 121 | git_refdb *_refdb; |
9462c471 VM |
122 | git_config *_config; |
123 | git_index *_index; | |
48c27f86 | 124 | |
72a3fe42 | 125 | git_cache objects; |
40ed4990 | 126 | git_attr_cache *attrcache; |
114f5a6c | 127 | git_diff_driver_registry *diff_drivers; |
6fd195d7 VM |
128 | |
129 | char *path_repository; | |
4196dd8e | 130 | char *path_gitlink; |
9462c471 | 131 | char *workdir; |
bade5194 | 132 | char *namespace; |
6fd195d7 | 133 | |
659cf202 CMN |
134 | char *ident_name; |
135 | char *ident_email; | |
136 | ||
4196dd8e ET |
137 | git_array_t(git_buf) reserved_names; |
138 | ||
139 | unsigned is_bare:1; | |
83ad46f7 | 140 | |
6b2a1941 | 141 | unsigned int lru_counter; |
450b40ca | 142 | |
9f779aac ET |
143 | git_atomic attr_session_key; |
144 | ||
f2c25d18 | 145 | git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX]; |
3315782c VM |
146 | }; |
147 | ||
95dfb031 RB |
148 | GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo) |
149 | { | |
40ed4990 | 150 | return repo->attrcache; |
95dfb031 RB |
151 | } |
152 | ||
f917481e RB |
153 | int git_repository_head_tree(git_tree **tree, git_repository *repo); |
154 | ||
f2c25d18 VM |
155 | /* |
156 | * Weak pointers to repository internals. | |
157 | * | |
158 | * The returned pointers do not need to be freed. Do not keep | |
159 | * permanent references to these (i.e. between API calls), since they may | |
160 | * become invalidated if the user replaces a repository internal. | |
161 | */ | |
9462c471 VM |
162 | int git_repository_config__weakptr(git_config **out, git_repository *repo); |
163 | int git_repository_odb__weakptr(git_odb **out, git_repository *repo); | |
d00d5464 | 164 | int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo); |
9462c471 VM |
165 | int git_repository_index__weakptr(git_index **out, git_repository *repo); |
166 | ||
f2c25d18 | 167 | /* |
c6ac28fd | 168 | * CVAR cache |
f2c25d18 VM |
169 | * |
170 | * Efficient access to the most used config variables of a repository. | |
b874629b | 171 | * The cache is cleared every time the config backend is replaced. |
f2c25d18 VM |
172 | */ |
173 | int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar); | |
174 | void git_repository__cvar_cache_clear(git_repository *repo); | |
175 | ||
ced8d142 | 176 | GIT_INLINE(int) git_repository__ensure_not_bare( |
177 | git_repository *repo, | |
178 | const char *operation_name) | |
179 | { | |
180 | if (!git_repository_is_bare(repo)) | |
181 | return 0; | |
182 | ||
183 | giterr_set( | |
184 | GITERR_REPOSITORY, | |
185 | "Cannot %s. This operation is not allowed against bare repositories.", | |
186 | operation_name); | |
187 | ||
188 | return GIT_EBAREREPO; | |
189 | } | |
190 | ||
867a36f3 ET |
191 | int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head); |
192 | ||
bab0b9f2 ET |
193 | int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len); |
194 | ||
4196dd8e ET |
195 | /* The default "reserved names" for a repository */ |
196 | extern git_buf git_repository__reserved_names_win32[]; | |
197 | extern size_t git_repository__reserved_names_win32_len; | |
198 | ||
199 | extern git_buf git_repository__reserved_names_posix[]; | |
200 | extern size_t git_repository__reserved_names_posix_len; | |
a64119e3 | 201 | |
4196dd8e ET |
202 | /* |
203 | * Gets any "reserved names" in the repository. This will return paths | |
204 | * that should not be allowed in the repository (like ".git") to avoid | |
205 | * conflicting with the repository path, or with alternate mechanisms to | |
206 | * the repository path (eg, "GIT~1"). Every attempt will be made to look | |
207 | * up all possible reserved names - if there was a conflict for the shortname | |
208 | * GIT~1, for example, this function will try to look up the alternate | |
209 | * shortname. If that fails, this function returns false, but out and outlen | |
210 | * will still be populated with good defaults. | |
a64119e3 | 211 | */ |
4196dd8e ET |
212 | bool git_repository__reserved_names( |
213 | git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs); | |
a64119e3 | 214 | |
3315782c | 215 | #endif |