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