2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_repository_h__
8 #define INCLUDE_repository_h__
10 #include "git2/common.h"
13 #include "git2/repository.h"
14 #include "git2/object.h"
15 #include "git2/config.h"
21 #include "attrcache.h"
22 #include "submodule.h"
23 #include "diff_driver.h"
25 #define DOT_GIT ".git"
26 #define GIT_DIR DOT_GIT "/"
27 #define GIT_DIR_MODE 0755
28 #define GIT_BARE_DIR_MODE 0777
30 /** Cvar cache identifiers */
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 */
47 * CVAR value enumerations
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"
55 /* The value hasn't been loaded from the cache yet */
56 GIT_CVAR_NOT_CACHED
= -1,
58 /* core.safecrlf: false, 'fail', 'warn' */
59 GIT_SAFE_CRLF_FALSE
= 0,
60 GIT_SAFE_CRLF_FAIL
= 1,
61 GIT_SAFE_CRLF_WARN
= 2,
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
,
69 /* core.eol: unset, 'crlf', 'lf', 'native' */
74 GIT_EOL_NATIVE
= GIT_EOL_CRLF
,
76 GIT_EOL_NATIVE
= GIT_EOL_LF
,
78 GIT_EOL_DEFAULT
= GIT_EOL_NATIVE
,
80 /* core.symlinks: bool */
81 GIT_SYMLINKS_DEFAULT
= GIT_CVAR_TRUE
,
83 GIT_IGNORECASE_DEFAULT
= GIT_CVAR_FALSE
,
85 GIT_FILEMODE_DEFAULT
= GIT_CVAR_TRUE
,
87 GIT_IGNORESTAT_DEFAULT
= GIT_CVAR_FALSE
,
89 GIT_TRUSTCTIME_DEFAULT
= GIT_CVAR_TRUE
,
91 GIT_ABBREV_DEFAULT
= 7,
92 /* core.precomposeunicode */
93 GIT_PRECOMPOSE_DEFAULT
= GIT_CVAR_FALSE
,
95 GIT_SAFE_CRLF_DEFAULT
= GIT_CVAR_FALSE
,
96 /* core.logallrefupdates */
97 GIT_LOGALLREFUPDATES_UNSET
= 2,
98 GIT_LOGALLREFUPDATES_DEFAULT
= GIT_LOGALLREFUPDATES_UNSET
,
101 /* internal repository init flags */
103 GIT_REPOSITORY_INIT__HAS_DOTGIT
= (1u << 16),
104 GIT_REPOSITORY_INIT__NATURAL_WD
= (1u << 17),
105 GIT_REPOSITORY_INIT__IS_REINIT
= (1u << 18),
108 /** Internal structure for repository object */
109 struct git_repository
{
114 git_submodule_cache
*_submodules
;
117 git_attr_cache
*attrcache
;
118 git_diff_driver_registry
*diff_drivers
;
120 char *path_repository
;
125 unsigned int lru_counter
;
127 git_cvar_value cvar_cache
[GIT_CVAR_CACHE_MAX
];
130 GIT_INLINE(git_attr_cache
*) git_repository_attr_cache(git_repository
*repo
)
132 return repo
->attrcache
;
135 int git_repository_head_tree(git_tree
**tree
, git_repository
*repo
);
138 * Weak pointers to repository internals.
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.
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
);
152 * Efficient access to the most used config variables of a repository.
153 * The cache is cleared everytime the config backend is replaced.
155 int git_repository__cvar(int *out
, git_repository
*repo
, git_cvar_cached cvar
);
156 void git_repository__cvar_cache_clear(git_repository
*repo
);
158 GIT_INLINE(int) git_repository__ensure_not_bare(
159 git_repository
*repo
,
160 const char *operation_name
)
162 if (!git_repository_is_bare(repo
))
167 "Cannot %s. This operation is not allowed against bare repositories.",
170 return GIT_EBAREREPO
;
173 int git_repository__cleanup_files(git_repository
*repo
, const char *files
[], size_t files_len
);