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