| 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 "common.h" |
| 11 |
|
| |
| 12 |
|
| #include "git2/common.h" |
| 13 |
|
| #include "git2/oid.h" |
| 14 |
|
| #include "git2/odb.h" |
| 15 |
|
| #include "git2/repository.h" |
| 16 |
|
| #include "git2/object.h" |
| 17 |
|
| #include "git2/config.h" |
| 18 |
|
| |
| 19 |
|
| #include "array.h" |
| 20 |
|
| #include "cache.h" |
| 21 |
|
| #include "refs.h" |
| 22 |
|
| #include "str.h" |
| 23 |
|
| #include "object.h" |
| 24 |
|
| #include "attrcache.h" |
| 25 |
|
| #include "submodule.h" |
| 26 |
|
| #include "diff_driver.h" |
| 27 |
|
| |
| 28 |
|
| #define DOT_GIT ".git" |
| 29 |
|
| #define GIT_DIR DOT_GIT "/" |
| 30 |
|
| #define GIT_DIR_MODE 0755 |
| 31 |
|
| #define GIT_BARE_DIR_MODE 0777 |
| 32 |
|
| |
| 33 |
|
| /* Default DOS-compatible 8.3 "short name" for a git repository, "GIT~1" */ |
| 34 |
|
| #define GIT_DIR_SHORTNAME "GIT~1" |
| 35 |
|
| |
| 36 |
|
| extern bool git_repository__fsync_gitdir; |
| 37 |
|
| extern bool git_repository__validate_ownership; |
| 38 |
|
| |
| 39 |
|
| /** Cvar cache identifiers */ |
| 40 |
|
| typedef enum { |
| 41 |
|
| GIT_CONFIGMAP_AUTO_CRLF = 0, /* core.autocrlf */ |
| 42 |
|
| GIT_CONFIGMAP_EOL, /* core.eol */ |
| 43 |
|
| GIT_CONFIGMAP_SYMLINKS, /* core.symlinks */ |
| 44 |
|
| GIT_CONFIGMAP_IGNORECASE, /* core.ignorecase */ |
| 45 |
|
| GIT_CONFIGMAP_FILEMODE, /* core.filemode */ |
| 46 |
|
| GIT_CONFIGMAP_IGNORESTAT, /* core.ignorestat */ |
| 47 |
|
| GIT_CONFIGMAP_TRUSTCTIME, /* core.trustctime */ |
| 48 |
|
| GIT_CONFIGMAP_ABBREV, /* core.abbrev */ |
| 49 |
|
| GIT_CONFIGMAP_PRECOMPOSE, /* core.precomposeunicode */ |
| 50 |
|
| GIT_CONFIGMAP_SAFE_CRLF, /* core.safecrlf */ |
| 51 |
|
| GIT_CONFIGMAP_LOGALLREFUPDATES, /* core.logallrefupdates */ |
| 52 |
|
| GIT_CONFIGMAP_PROTECTHFS, /* core.protectHFS */ |
| 53 |
|
| GIT_CONFIGMAP_PROTECTNTFS, /* core.protectNTFS */ |
| 54 |
|
| GIT_CONFIGMAP_FSYNCOBJECTFILES, /* core.fsyncObjectFiles */ |
| 55 |
|
| GIT_CONFIGMAP_LONGPATHS, /* core.longpaths */ |
| 56 |
|
| GIT_CONFIGMAP_CACHE_MAX |
| 57 |
|
| } git_configmap_item; |
| 58 |
|
| |
| 59 |
|
| /** |
| 60 |
|
| * Configuration map value enumerations |
| 61 |
|
| * |
| 62 |
|
| * These are the values that are actually stored in the configmap cache, |
| 63 |
|
| * instead of their string equivalents. These values are internal and |
| 64 |
|
| * symbolic; make sure that none of them is set to `-1`, since that is |
| 65 |
|
| * the unique identifier for "not cached" |
| 66 |
|
| */ |
| 67 |
|
| typedef enum { |
| 68 |
|
| /* The value hasn't been loaded from the cache yet */ |
| 69 |
|
| GIT_CONFIGMAP_NOT_CACHED = -1, |
| 70 |
|
| |
| 71 |
|
| /* core.safecrlf: false, 'fail', 'warn' */ |
| 72 |
|
| GIT_SAFE_CRLF_FALSE = 0, |
| 73 |
|
| GIT_SAFE_CRLF_FAIL = 1, |
| 74 |
|
| GIT_SAFE_CRLF_WARN = 2, |
| 75 |
|
| |
| 76 |
|
| /* core.autocrlf: false, true, 'input; */ |
| 77 |
|
| GIT_AUTO_CRLF_FALSE = 0, |
| 78 |
|
| GIT_AUTO_CRLF_TRUE = 1, |
| 79 |
|
| GIT_AUTO_CRLF_INPUT = 2, |
| 80 |
|
| GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE, |
| 81 |
|
| |
| 82 |
|
| /* core.eol: unset, 'crlf', 'lf', 'native' */ |
| 83 |
|
| GIT_EOL_UNSET = 0, |
| 84 |
|
| GIT_EOL_CRLF = 1, |
| 85 |
|
| GIT_EOL_LF = 2, |
| 86 |
|
| #ifdef GIT_WIN32 |
| 87 |
|
| GIT_EOL_NATIVE = GIT_EOL_CRLF, |
| 88 |
|
| #else |
| 89 |
|
| GIT_EOL_NATIVE = GIT_EOL_LF, |
| 90 |
|
| #endif |
| 91 |
|
| GIT_EOL_DEFAULT = GIT_EOL_NATIVE, |
| 92 |
|
| |
| 93 |
|
| /* core.symlinks: bool */ |
| 94 |
|
| GIT_SYMLINKS_DEFAULT = GIT_CONFIGMAP_TRUE, |
| 95 |
|
| /* core.ignorecase */ |
| 96 |
|
| GIT_IGNORECASE_DEFAULT = GIT_CONFIGMAP_FALSE, |
| 97 |
|
| /* core.filemode */ |
| 98 |
|
| GIT_FILEMODE_DEFAULT = GIT_CONFIGMAP_TRUE, |
| 99 |
|
| /* core.ignorestat */ |
| 100 |
|
| GIT_IGNORESTAT_DEFAULT = GIT_CONFIGMAP_FALSE, |
| 101 |
|
| /* core.trustctime */ |
| 102 |
|
| GIT_TRUSTCTIME_DEFAULT = GIT_CONFIGMAP_TRUE, |
| 103 |
|
| /* core.abbrev */ |
| 104 |
|
| GIT_ABBREV_DEFAULT = 7, |
| 105 |
|
| /* core.precomposeunicode */ |
| 106 |
|
| GIT_PRECOMPOSE_DEFAULT = GIT_CONFIGMAP_FALSE, |
| 107 |
|
| /* core.safecrlf */ |
| 108 |
|
| GIT_SAFE_CRLF_DEFAULT = GIT_CONFIGMAP_FALSE, |
| 109 |
|
| /* core.logallrefupdates */ |
| 110 |
|
| GIT_LOGALLREFUPDATES_FALSE = GIT_CONFIGMAP_FALSE, |
| 111 |
|
| GIT_LOGALLREFUPDATES_TRUE = GIT_CONFIGMAP_TRUE, |
| 112 |
|
| GIT_LOGALLREFUPDATES_UNSET = 2, |
| 113 |
|
| GIT_LOGALLREFUPDATES_ALWAYS = 3, |
| 114 |
|
| GIT_LOGALLREFUPDATES_DEFAULT = GIT_LOGALLREFUPDATES_UNSET, |
| 115 |
|
| /* core.protectHFS */ |
| 116 |
|
| GIT_PROTECTHFS_DEFAULT = GIT_CONFIGMAP_FALSE, |
| 117 |
|
| /* core.protectNTFS */ |
| 118 |
|
| GIT_PROTECTNTFS_DEFAULT = GIT_CONFIGMAP_TRUE, |
| 119 |
|
| /* core.fsyncObjectFiles */ |
| 120 |
|
| GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CONFIGMAP_FALSE, |
| 121 |
|
| /* core.longpaths */ |
| 122 |
|
| GIT_LONGPATHS_DEFAULT = GIT_CONFIGMAP_FALSE |
| 123 |
|
| } git_configmap_value; |
| 124 |
|
| |
| 125 |
|
| /* internal repository init flags */ |
| 126 |
|
| enum { |
| 127 |
|
| GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16), |
| 128 |
|
| GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17), |
| 129 |
|
| GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18) |
| 130 |
|
| }; |
| 131 |
|
| |
| 132 |
|
| /** Internal structure for repository object */ |
| 133 |
|
| struct git_repository { |
| 134 |
|
| git_odb *_odb; |
| 135 |
|
| git_refdb *_refdb; |
| 136 |
|
| git_config *_config; |
| 137 |
|
| git_index *_index; |
| 138 |
|
| |
| 139 |
|
| git_cache objects; |
| 140 |
|
| git_attr_cache *attrcache; |
| 141 |
|
| git_diff_driver_registry *diff_drivers; |
| 142 |
|
| |
| 143 |
|
| char *gitlink; |
| 144 |
|
| char *gitdir; |
| 145 |
|
| char *commondir; |
| 146 |
|
| char *workdir; |
| 147 |
|
| char *namespace; |
| 148 |
|
| |
| 149 |
|
| char *ident_name; |
| 150 |
|
| char *ident_email; |
| 151 |
|
| |
| 152 |
|
| git_array_t(git_str) reserved_names; |
| 153 |
|
| |
| 154 |
|
| unsigned is_bare:1; |
| 155 |
|
| unsigned is_worktree:1; |
| 156 |
|
| |
| 157 |
|
| unsigned int lru_counter; |
| 158 |
|
| |
| 159 |
|
| git_atomic32 attr_session_key; |
| 160 |
|
| |
| 161 |
|
| intptr_t configmap_cache[GIT_CONFIGMAP_CACHE_MAX]; |
| 162 |
|
| git_strmap *submodule_cache; |
| 163 |
|
| }; |
| 164 |
|
| |
| 165 |
|
| GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo) |
| 166 |
|
| { |
| 167 |
|
| return repo->attrcache; |
| 168 |
|
| } |
| 169 |
|
| |
| 170 |
|
| int git_repository_head_tree(git_tree **tree, git_repository *repo); |
| 171 |
|
| int git_repository_create_head(const char *git_dir, const char *ref_name); |
| 172 |
|
| |
| 173 |
|
| typedef int (*git_repository_foreach_worktree_cb)(git_repository *, void *); |
| 174 |
|
| |
| 175 |
|
| int git_repository_foreach_worktree(git_repository *repo, |
| 176 |
|
| git_repository_foreach_worktree_cb cb, |
| 177 |
|
| void *payload); |
| 178 |
|
| |
| 179 |
|
| /* |
| 180 |
|
| * Weak pointers to repository internals. |
| 181 |
|
| * |
| 182 |
|
| * The returned pointers do not need to be freed. Do not keep |
| 183 |
|
| * permanent references to these (i.e. between API calls), since they may |
| 184 |
|
| * become invalidated if the user replaces a repository internal. |
| 185 |
|
| */ |
| 186 |
|
| int git_repository_config__weakptr(git_config **out, git_repository *repo); |
| 187 |
|
| int git_repository_odb__weakptr(git_odb **out, git_repository *repo); |
| 188 |
|
| int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo); |
| 189 |
|
| int git_repository_index__weakptr(git_index **out, git_repository *repo); |
| 190 |
|
| |
| 191 |
|
| /* |
| 192 |
|
| * Configuration map cache |
| 193 |
|
| * |
| 194 |
|
| * Efficient access to the most used config variables of a repository. |
| 195 |
|
| * The cache is cleared every time the config backend is replaced. |
| 196 |
|
| */ |
| 197 |
|
| int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item); |
| 198 |
|
| void git_repository__configmap_lookup_cache_clear(git_repository *repo); |
| 199 |
|
| |
| 200 |
|
| int git_repository__item_path(git_str *out, const git_repository *repo, git_repository_item_t item); |
| 201 |
|
| |
| 202 |
6 |
| GIT_INLINE(int) git_repository__ensure_not_bare( |
| 203 |
|
| git_repository *repo, |
| 204 |
|
| const char *operation_name) |
| 205 |
|
| { |
| 206 |
6 |
▶ | if (!git_repository_is_bare(repo)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!git_repository_is_bare(repo)) |
6 |
0 |
6 |
|
| 207 |
6 |
| return 0; |
| 208 |
|
| |
| 209 |
0 |
| git_error_set( |
| 210 |
|
| GIT_ERROR_REPOSITORY, |
| 211 |
|
| "cannot %s. This operation is not allowed against bare repositories.", |
| 212 |
|
| operation_name); |
| 213 |
|
| |
| 214 |
0 |
| return GIT_EBAREREPO; |
| 215 |
|
| } |
| 216 |
|
| |
| 217 |
|
| int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head); |
| 218 |
|
| |
| 219 |
|
| int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len); |
| 220 |
|
| |
| 221 |
|
| /* The default "reserved names" for a repository */ |
| 222 |
|
| extern git_str git_repository__reserved_names_win32[]; |
| 223 |
|
| extern size_t git_repository__reserved_names_win32_len; |
| 224 |
|
| |
| 225 |
|
| extern git_str git_repository__reserved_names_posix[]; |
| 226 |
|
| extern size_t git_repository__reserved_names_posix_len; |
| 227 |
|
| |
| 228 |
|
| /* |
| 229 |
|
| * Gets any "reserved names" in the repository. This will return paths |
| 230 |
|
| * that should not be allowed in the repository (like ".git") to avoid |
| 231 |
|
| * conflicting with the repository path, or with alternate mechanisms to |
| 232 |
|
| * the repository path (eg, "GIT~1"). Every attempt will be made to look |
| 233 |
|
| * up all possible reserved names - if there was a conflict for the shortname |
| 234 |
|
| * GIT~1, for example, this function will try to look up the alternate |
| 235 |
|
| * shortname. If that fails, this function returns false, but out and outlen |
| 236 |
|
| * will still be populated with good defaults. |
| 237 |
|
| */ |
| 238 |
|
| bool git_repository__reserved_names( |
| 239 |
|
| git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs); |
| 240 |
|
| |
| 241 |
|
| /* |
| 242 |
|
| * The default branch for the repository; the `init.defaultBranch` |
| 243 |
|
| * configuration option, if set, or `master` if it is not. |
| 244 |
|
| */ |
| 245 |
|
| int git_repository_initialbranch(git_str *out, git_repository *repo); |
| 246 |
|
| |
| 247 |
|
| /* |
| 248 |
|
| * Given a relative `path`, this makes it absolute based on the |
| 249 |
|
| * repository's working directory. This will perform validation |
| 250 |
|
| * to ensure that the path is not longer than MAX_PATH on Windows |
| 251 |
|
| * (unless `core.longpaths` is set in the repo config). |
| 252 |
|
| */ |
| 253 |
|
| int git_repository_workdir_path(git_str *out, git_repository *repo, const char *path); |
| 254 |
|
| |
| 255 |
|
| int git_repository__extensions(char ***out, size_t *out_len); |
| 256 |
|
| int git_repository__set_extensions(const char **extensions, size_t len); |
| 257 |
|
| void git_repository__free_extensions(void); |
| 258 |
|
| |
| 259 |
|
| #endif |