2 * Copyright (C) 2009-2012 the libgit2 contributors
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"
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 */
38 * CVAR value enumerations
40 * These are the values that are actually stored in the cvar cache, instead
41 * of their string equivalents. These values are internal and symbolic;
42 * make sure that none of them is set to `-1`, since that is the unique
43 * identifier for "not cached"
46 /* The value hasn't been loaded from the cache yet */
47 GIT_CVAR_NOT_CACHED
= -1,
49 /* core.safecrlf: false, 'fail', 'warn' */
50 GIT_SAFE_CRLF_FALSE
= 0,
51 GIT_SAFE_CRLF_FAIL
= 1,
52 GIT_SAFE_CRLF_WARN
= 2,
54 /* core.autocrlf: false, true, 'input; */
55 GIT_AUTO_CRLF_FALSE
= 0,
56 GIT_AUTO_CRLF_TRUE
= 1,
57 GIT_AUTO_CRLF_INPUT
= 2,
58 GIT_AUTO_CRLF_DEFAULT
= GIT_AUTO_CRLF_FALSE
,
60 /* core.eol: unset, 'crlf', 'lf', 'native' */
65 GIT_EOL_NATIVE
= GIT_EOL_CRLF
,
67 GIT_EOL_NATIVE
= GIT_EOL_LF
,
69 GIT_EOL_DEFAULT
= GIT_EOL_NATIVE
72 /* internal repository init flags */
74 GIT_REPOSITORY_INIT__HAS_DOTGIT
= (1u << 16),
75 GIT_REPOSITORY_INIT__NATURAL_WD
= (1u << 17),
76 GIT_REPOSITORY_INIT__IS_REINIT
= (1u << 18),
79 /** Internal structure for repository object */
80 struct git_repository
{
86 git_refcache references
;
87 git_attr_cache attrcache
;
88 git_strmap
*submodules
;
90 char *path_repository
;
94 unsigned int lru_counter
;
96 git_cvar_value cvar_cache
[GIT_CVAR_CACHE_MAX
];
99 GIT_INLINE(git_attr_cache
*) git_repository_attr_cache(git_repository
*repo
)
101 return &repo
->attrcache
;
104 int git_repository_head_tree(git_tree
**tree
, git_repository
*repo
);
107 * Weak pointers to repository internals.
109 * The returned pointers do not need to be freed. Do not keep
110 * permanent references to these (i.e. between API calls), since they may
111 * become invalidated if the user replaces a repository internal.
113 int git_repository_config__weakptr(git_config
**out
, git_repository
*repo
);
114 int git_repository_odb__weakptr(git_odb
**out
, git_repository
*repo
);
115 int git_repository_index__weakptr(git_index
**out
, git_repository
*repo
);
120 * Efficient access to the most used config variables of a repository.
121 * The cache is cleared everytime the config backend is replaced.
123 int git_repository__cvar(int *out
, git_repository
*repo
, git_cvar_cached cvar
);
124 void git_repository__cvar_cache_clear(git_repository
*repo
);
129 extern void git_submodule_config_free(git_repository
*repo
);
131 GIT_INLINE(int) git_repository__ensure_not_bare(
132 git_repository
*repo
,
133 const char *operation_name
)
135 if (!git_repository_is_bare(repo
))
140 "Cannot %s. This operation is not allowed against bare repositories.",
143 return GIT_EBAREREPO
;