]> git.proxmox.com Git - libgit2.git/blob - src/repository.h
Merge pull request #844 from arrbee/init-extended
[libgit2.git] / src / repository.h
1 /*
2 * Copyright (C) 2009-2012 the libgit2 contributors
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
16 #include "index.h"
17 #include "cache.h"
18 #include "refs.h"
19 #include "buffer.h"
20 #include "odb.h"
21 #include "attr.h"
22 #include "strmap.h"
23
24 #define DOT_GIT ".git"
25 #define GIT_DIR DOT_GIT "/"
26 #define GIT_DIR_MODE 0755
27 #define GIT_BARE_DIR_MODE 0777
28
29 /** Cvar cache identifiers */
30 typedef enum {
31 GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */
32 GIT_CVAR_EOL, /* core.eol */
33 GIT_CVAR_CACHE_MAX
34 } git_cvar_cached;
35
36 /**
37 * CVAR value enumerations
38 *
39 * These are the values that are actually stored in the cvar cache, instead
40 * of their string equivalents. These values are internal and symbolic;
41 * make sure that none of them is set to `-1`, since that is the unique
42 * identifier for "not cached"
43 */
44 typedef enum {
45 /* The value hasn't been loaded from the cache yet */
46 GIT_CVAR_NOT_CACHED = -1,
47
48 /* core.safecrlf: false, 'fail', 'warn' */
49 GIT_SAFE_CRLF_FALSE = 0,
50 GIT_SAFE_CRLF_FAIL = 1,
51 GIT_SAFE_CRLF_WARN = 2,
52
53 /* core.autocrlf: false, true, 'input; */
54 GIT_AUTO_CRLF_FALSE = 0,
55 GIT_AUTO_CRLF_TRUE = 1,
56 GIT_AUTO_CRLF_INPUT = 2,
57 GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE,
58
59 /* core.eol: unset, 'crlf', 'lf', 'native' */
60 GIT_EOL_UNSET = 0,
61 GIT_EOL_CRLF = 1,
62 GIT_EOL_LF = 2,
63 #ifdef GIT_WIN32
64 GIT_EOL_NATIVE = GIT_EOL_CRLF,
65 #else
66 GIT_EOL_NATIVE = GIT_EOL_LF,
67 #endif
68 GIT_EOL_DEFAULT = GIT_EOL_NATIVE
69 } git_cvar_value;
70
71 /* internal repository init flags */
72 enum {
73 GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16),
74 GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17),
75 GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18),
76 };
77
78 /** Base git object for inheritance */
79 struct git_object {
80 git_cached_obj cached;
81 git_repository *repo;
82 git_otype type;
83 };
84
85 /** Internal structure for repository object */
86 struct git_repository {
87 git_odb *_odb;
88 git_config *_config;
89 git_index *_index;
90
91 git_cache objects;
92 git_refcache references;
93 git_attr_cache attrcache;
94 git_strmap *submodules;
95
96 char *path_repository;
97 char *workdir;
98
99 unsigned is_bare:1;
100 unsigned int lru_counter;
101
102 git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX];
103 };
104
105 /* fully free the object; internal method, DO NOT EXPORT */
106 void git_object__free(void *object);
107
108 GIT_INLINE(int) git_object__dup(git_object **dest, git_object *source)
109 {
110 git_cached_obj_incref(source);
111 *dest = source;
112 return 0;
113 }
114
115 int git_object__resolve_to_type(git_object **obj, git_otype type);
116
117 int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
118 void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid);
119
120 GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
121 {
122 return &repo->attrcache;
123 }
124
125 int git_repository_head_tree(git_tree **tree, git_repository *repo);
126
127 /*
128 * Weak pointers to repository internals.
129 *
130 * The returned pointers do not need to be freed. Do not keep
131 * permanent references to these (i.e. between API calls), since they may
132 * become invalidated if the user replaces a repository internal.
133 */
134 int git_repository_config__weakptr(git_config **out, git_repository *repo);
135 int git_repository_odb__weakptr(git_odb **out, git_repository *repo);
136 int git_repository_index__weakptr(git_index **out, git_repository *repo);
137
138 /*
139 * CVAR cache
140 *
141 * Efficient access to the most used config variables of a repository.
142 * The cache is cleared everytime the config backend is replaced.
143 */
144 int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar);
145 void git_repository__cvar_cache_clear(git_repository *repo);
146
147 /*
148 * Submodule cache
149 */
150 extern void git_submodule_config_free(git_repository *repo);
151
152 #endif