]>
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 | |
72a3fe42 | 17 | #include "cache.h" |
9282e921 | 18 | #include "refs.h" |
afeecf4f | 19 | #include "buffer.h" |
c6ac28fd | 20 | #include "object.h" |
5540d947 | 21 | #include "attrcache.h" |
c2b67043 | 22 | #include "strmap.h" |
114f5a6c | 23 | #include "diff_driver.h" |
3315782c | 24 | |
d2d6912e | 25 | #define DOT_GIT ".git" |
26 | #define GIT_DIR DOT_GIT "/" | |
ce8cd006 BR |
27 | #define GIT_DIR_MODE 0755 |
28 | #define GIT_BARE_DIR_MODE 0777 | |
d2d6912e | 29 | |
f2c25d18 VM |
30 | /** Cvar cache identifiers */ |
31 | typedef enum { | |
32 | GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */ | |
ab01cbd4 RB |
33 | GIT_CVAR_EOL, /* core.eol */ |
34 | GIT_CVAR_SYMLINKS, /* core.symlinks */ | |
35 | GIT_CVAR_IGNORECASE, /* core.ignorecase */ | |
36 | GIT_CVAR_FILEMODE, /* core.filemode */ | |
37 | GIT_CVAR_IGNORESTAT, /* core.ignorestat */ | |
38 | GIT_CVAR_TRUSTCTIME, /* core.trustctime */ | |
39 | GIT_CVAR_ABBREV, /* core.abbrev */ | |
2fe54afa | 40 | GIT_CVAR_PRECOMPOSE, /* core.precomposeunicode */ |
f2c25d18 VM |
41 | GIT_CVAR_CACHE_MAX |
42 | } git_cvar_cached; | |
43 | ||
44 | /** | |
45 | * CVAR value enumerations | |
46 | * | |
47 | * These are the values that are actually stored in the cvar cache, instead | |
48 | * of their string equivalents. These values are internal and symbolic; | |
49 | * make sure that none of them is set to `-1`, since that is the unique | |
50 | * identifier for "not cached" | |
51 | */ | |
52 | typedef enum { | |
53 | /* The value hasn't been loaded from the cache yet */ | |
54 | GIT_CVAR_NOT_CACHED = -1, | |
55 | ||
56 | /* core.safecrlf: false, 'fail', 'warn' */ | |
57 | GIT_SAFE_CRLF_FALSE = 0, | |
58 | GIT_SAFE_CRLF_FAIL = 1, | |
59 | GIT_SAFE_CRLF_WARN = 2, | |
60 | ||
61 | /* core.autocrlf: false, true, 'input; */ | |
62 | GIT_AUTO_CRLF_FALSE = 0, | |
63 | GIT_AUTO_CRLF_TRUE = 1, | |
64 | GIT_AUTO_CRLF_INPUT = 2, | |
65 | GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE, | |
66 | ||
67 | /* core.eol: unset, 'crlf', 'lf', 'native' */ | |
68 | GIT_EOL_UNSET = 0, | |
69 | GIT_EOL_CRLF = 1, | |
70 | GIT_EOL_LF = 2, | |
71 | #ifdef GIT_WIN32 | |
72 | GIT_EOL_NATIVE = GIT_EOL_CRLF, | |
73 | #else | |
74 | GIT_EOL_NATIVE = GIT_EOL_LF, | |
75 | #endif | |
ab01cbd4 RB |
76 | GIT_EOL_DEFAULT = GIT_EOL_NATIVE, |
77 | ||
78 | /* core.symlinks: bool */ | |
79 | GIT_SYMLINKS_DEFAULT = GIT_CVAR_TRUE, | |
80 | /* core.ignorecase */ | |
81 | GIT_IGNORECASE_DEFAULT = GIT_CVAR_FALSE, | |
82 | /* core.filemode */ | |
83 | GIT_FILEMODE_DEFAULT = GIT_CVAR_TRUE, | |
84 | /* core.ignorestat */ | |
85 | GIT_IGNORESTAT_DEFAULT = GIT_CVAR_FALSE, | |
86 | /* core.trustctime */ | |
87 | GIT_TRUSTCTIME_DEFAULT = GIT_CVAR_TRUE, | |
88 | /* core.abbrev */ | |
89 | GIT_ABBREV_DEFAULT = 7, | |
2fe54afa RB |
90 | /* core.precomposeunicode */ |
91 | GIT_PRECOMPOSE_DEFAULT = GIT_CVAR_FALSE, | |
ab01cbd4 | 92 | |
f2c25d18 VM |
93 | } git_cvar_value; |
94 | ||
662880ca RB |
95 | /* internal repository init flags */ |
96 | enum { | |
97 | GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16), | |
98 | GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17), | |
99 | GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18), | |
100 | }; | |
101 | ||
662880ca | 102 | /** Internal structure for repository object */ |
3315782c | 103 | struct git_repository { |
9462c471 | 104 | git_odb *_odb; |
d00d5464 | 105 | git_refdb *_refdb; |
9462c471 VM |
106 | git_config *_config; |
107 | git_index *_index; | |
48c27f86 | 108 | |
72a3fe42 | 109 | git_cache objects; |
ee1f0b1a | 110 | git_attr_cache attrcache; |
c2b67043 | 111 | git_strmap *submodules; |
114f5a6c | 112 | git_diff_driver_registry *diff_drivers; |
6fd195d7 VM |
113 | |
114 | char *path_repository; | |
9462c471 | 115 | char *workdir; |
bade5194 | 116 | char *namespace; |
6fd195d7 | 117 | |
6b2a1941 VM |
118 | unsigned is_bare:1; |
119 | unsigned int lru_counter; | |
450b40ca | 120 | |
f2c25d18 | 121 | git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX]; |
3315782c VM |
122 | }; |
123 | ||
95dfb031 RB |
124 | GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo) |
125 | { | |
126 | return &repo->attrcache; | |
127 | } | |
128 | ||
f917481e RB |
129 | int git_repository_head_tree(git_tree **tree, git_repository *repo); |
130 | ||
f2c25d18 VM |
131 | /* |
132 | * Weak pointers to repository internals. | |
133 | * | |
134 | * The returned pointers do not need to be freed. Do not keep | |
135 | * permanent references to these (i.e. between API calls), since they may | |
136 | * become invalidated if the user replaces a repository internal. | |
137 | */ | |
9462c471 VM |
138 | int git_repository_config__weakptr(git_config **out, git_repository *repo); |
139 | int git_repository_odb__weakptr(git_odb **out, git_repository *repo); | |
d00d5464 | 140 | int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo); |
9462c471 VM |
141 | int git_repository_index__weakptr(git_index **out, git_repository *repo); |
142 | ||
f2c25d18 | 143 | /* |
c6ac28fd | 144 | * CVAR cache |
f2c25d18 VM |
145 | * |
146 | * Efficient access to the most used config variables of a repository. | |
147 | * The cache is cleared everytime the config backend is replaced. | |
148 | */ | |
149 | int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar); | |
150 | void git_repository__cvar_cache_clear(git_repository *repo); | |
151 | ||
bfc9ca59 RB |
152 | /* |
153 | * Submodule cache | |
154 | */ | |
155 | extern void git_submodule_config_free(git_repository *repo); | |
156 | ||
ced8d142 | 157 | GIT_INLINE(int) git_repository__ensure_not_bare( |
158 | git_repository *repo, | |
159 | const char *operation_name) | |
160 | { | |
161 | if (!git_repository_is_bare(repo)) | |
162 | return 0; | |
163 | ||
164 | giterr_set( | |
165 | GITERR_REPOSITORY, | |
166 | "Cannot %s. This operation is not allowed against bare repositories.", | |
167 | operation_name); | |
168 | ||
169 | return GIT_EBAREREPO; | |
170 | } | |
171 | ||
3315782c | 172 | #endif |