]> git.proxmox.com Git - libgit2.git/blob - src/repository.h
Merge pull request #2974 from libgit2/cmn/clone-everything
[libgit2.git] / src / repository.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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 */
7 #ifndef INCLUDE_repository_h__
8 #define INCLUDE_repository_h__
9
10 #include "git2/common.h"
11 #include "git2/oid.h"
12 #include "git2/odb.h"
13 #include "git2/repository.h"
14 #include "git2/object.h"
15 #include "git2/config.h"
16
17 #include "array.h"
18 #include "cache.h"
19 #include "refs.h"
20 #include "buffer.h"
21 #include "object.h"
22 #include "attrcache.h"
23 #include "submodule.h"
24 #include "diff_driver.h"
25
26 #define DOT_GIT ".git"
27 #define GIT_DIR DOT_GIT "/"
28 #define GIT_DIR_MODE 0755
29 #define GIT_BARE_DIR_MODE 0777
30
31 /* Default DOS-compatible 8.3 "short name" for a git repository, "GIT~1" */
32 #define GIT_DIR_SHORTNAME "GIT~1"
33
34 /** Cvar cache identifiers */
35 typedef enum {
36 GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */
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 */
44 GIT_CVAR_PRECOMPOSE, /* core.precomposeunicode */
45 GIT_CVAR_SAFE_CRLF, /* core.safecrlf */
46 GIT_CVAR_LOGALLREFUPDATES, /* core.logallrefupdates */
47 GIT_CVAR_PROTECTHFS, /* core.protectHFS */
48 GIT_CVAR_PROTECTNTFS, /* core.protectNTFS */
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
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,
98 /* core.precomposeunicode */
99 GIT_PRECOMPOSE_DEFAULT = GIT_CVAR_FALSE,
100 /* core.safecrlf */
101 GIT_SAFE_CRLF_DEFAULT = GIT_CVAR_FALSE,
102 /* core.logallrefupdates */
103 GIT_LOGALLREFUPDATES_UNSET = 2,
104 GIT_LOGALLREFUPDATES_DEFAULT = GIT_LOGALLREFUPDATES_UNSET,
105 /* core.protectHFS */
106 GIT_PROTECTHFS_DEFAULT = GIT_CVAR_FALSE,
107 /* core.protectNTFS */
108 GIT_PROTECTNTFS_DEFAULT = GIT_CVAR_FALSE,
109 } git_cvar_value;
110
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
118 /** Internal structure for repository object */
119 struct git_repository {
120 git_odb *_odb;
121 git_refdb *_refdb;
122 git_config *_config;
123 git_index *_index;
124 git_submodule_cache *_submodules;
125
126 git_cache objects;
127 git_attr_cache *attrcache;
128 git_diff_driver_registry *diff_drivers;
129
130 char *path_repository;
131 char *path_gitlink;
132 char *workdir;
133 char *namespace;
134
135 char *ident_name;
136 char *ident_email;
137
138 git_array_t(git_buf) reserved_names;
139
140 unsigned is_bare:1;
141
142 unsigned int lru_counter;
143
144 git_atomic attr_session_key;
145
146 git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX];
147 };
148
149 GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
150 {
151 return repo->attrcache;
152 }
153
154 int git_repository_head_tree(git_tree **tree, git_repository *repo);
155
156 /*
157 * Weak pointers to repository internals.
158 *
159 * The returned pointers do not need to be freed. Do not keep
160 * permanent references to these (i.e. between API calls), since they may
161 * become invalidated if the user replaces a repository internal.
162 */
163 int git_repository_config__weakptr(git_config **out, git_repository *repo);
164 int git_repository_odb__weakptr(git_odb **out, git_repository *repo);
165 int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo);
166 int git_repository_index__weakptr(git_index **out, git_repository *repo);
167
168 /*
169 * CVAR cache
170 *
171 * Efficient access to the most used config variables of a repository.
172 * The cache is cleared every time the config backend is replaced.
173 */
174 int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar);
175 void git_repository__cvar_cache_clear(git_repository *repo);
176
177 GIT_INLINE(int) git_repository__ensure_not_bare(
178 git_repository *repo,
179 const char *operation_name)
180 {
181 if (!git_repository_is_bare(repo))
182 return 0;
183
184 giterr_set(
185 GITERR_REPOSITORY,
186 "Cannot %s. This operation is not allowed against bare repositories.",
187 operation_name);
188
189 return GIT_EBAREREPO;
190 }
191
192 int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head);
193
194 int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len);
195
196 /* The default "reserved names" for a repository */
197 extern git_buf git_repository__reserved_names_win32[];
198 extern size_t git_repository__reserved_names_win32_len;
199
200 extern git_buf git_repository__reserved_names_posix[];
201 extern size_t git_repository__reserved_names_posix_len;
202
203 /*
204 * Gets any "reserved names" in the repository. This will return paths
205 * that should not be allowed in the repository (like ".git") to avoid
206 * conflicting with the repository path, or with alternate mechanisms to
207 * the repository path (eg, "GIT~1"). Every attempt will be made to look
208 * up all possible reserved names - if there was a conflict for the shortname
209 * GIT~1, for example, this function will try to look up the alternate
210 * shortname. If that fails, this function returns false, but out and outlen
211 * will still be populated with good defaults.
212 */
213 bool git_repository__reserved_names(
214 git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs);
215
216 #endif