]> git.proxmox.com Git - libgit2.git/blob - src/repository.h
Fixed size_t format string warning
[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 "object.h"
22 #include "attr.h"
23 #include "strmap.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_CACHE_MAX
35 } git_cvar_cached;
36
37 /**
38 * CVAR value enumerations
39 *
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"
44 */
45 typedef enum {
46 /* The value hasn't been loaded from the cache yet */
47 GIT_CVAR_NOT_CACHED = -1,
48
49 /* core.safecrlf: false, 'fail', 'warn' */
50 GIT_SAFE_CRLF_FALSE = 0,
51 GIT_SAFE_CRLF_FAIL = 1,
52 GIT_SAFE_CRLF_WARN = 2,
53
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,
59
60 /* core.eol: unset, 'crlf', 'lf', 'native' */
61 GIT_EOL_UNSET = 0,
62 GIT_EOL_CRLF = 1,
63 GIT_EOL_LF = 2,
64 #ifdef GIT_WIN32
65 GIT_EOL_NATIVE = GIT_EOL_CRLF,
66 #else
67 GIT_EOL_NATIVE = GIT_EOL_LF,
68 #endif
69 GIT_EOL_DEFAULT = GIT_EOL_NATIVE
70 } git_cvar_value;
71
72 /* internal repository init flags */
73 enum {
74 GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16),
75 GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17),
76 GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18),
77 };
78
79 /** Internal structure for repository object */
80 struct git_repository {
81 git_odb *_odb;
82 git_config *_config;
83 git_index *_index;
84
85 git_cache objects;
86 git_refcache references;
87 git_attr_cache attrcache;
88 git_strmap *submodules;
89
90 char *path_repository;
91 char *workdir;
92
93 unsigned is_bare:1;
94 unsigned int lru_counter;
95
96 git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX];
97 };
98
99 GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
100 {
101 return &repo->attrcache;
102 }
103
104 int git_repository_head_tree(git_tree **tree, git_repository *repo);
105
106 /*
107 * Weak pointers to repository internals.
108 *
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.
112 */
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);
116
117 /*
118 * CVAR cache
119 *
120 * Efficient access to the most used config variables of a repository.
121 * The cache is cleared everytime the config backend is replaced.
122 */
123 int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar);
124 void git_repository__cvar_cache_clear(git_repository *repo);
125
126 /*
127 * Submodule cache
128 */
129 extern void git_submodule_config_free(git_repository *repo);
130
131 GIT_INLINE(int) git_repository__ensure_not_bare(
132 git_repository *repo,
133 const char *operation_name)
134 {
135 if (!git_repository_is_bare(repo))
136 return 0;
137
138 giterr_set(
139 GITERR_REPOSITORY,
140 "Cannot %s. This operation is not allowed against bare repositories.",
141 operation_name);
142
143 return GIT_EBAREREPO;
144 }
145
146 #endif