Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/repository.h # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / repository.h` 336 lines ยท 9967 bytes Raw Blame History 1 #ifndef REPOSITORY_H 2 #define REPOSITORY_H 3 4 #include "strmap.h" 5 #include "string-list.h" 6 #include "repo-settings.h" 7 #include "environment.h" 8 9 struct config_set; 10 struct git_hash_algo; 11 struct index_state; 12 struct lock_file; 13 struct pathspec; 14 struct object_database; 15 struct submodule_cache; 16 struct promisor_remote_config; 17 struct remote_state; 18 19 enum ref_storage_format { 20 REF_STORAGE_FORMAT_UNKNOWN, 21 REF_STORAGE_FORMAT_FILES, 22 REF_STORAGE_FORMAT_REFTABLE, 23 }; 24 25 enum object_storage_format { 26 OBJECT_STORAGE_FORMAT_UNKNOWN, 27 OBJECT_STORAGE_FORMAT_FILES, 28 }; 29 30 #ifdef WITH_BREAKING_CHANGES /* Git 3.0 */ 31 # define REF_STORAGE_FORMAT_DEFAULT REF_STORAGE_FORMAT_REFTABLE 32 #else 33 # define REF_STORAGE_FORMAT_DEFAULT REF_STORAGE_FORMAT_FILES 34 #endif 35 36 struct repo_path_cache { 37 char *squash_msg; 38 char *merge_msg; 39 char *merge_rr; 40 char *merge_mode; 41 char *merge_head; 42 char *fetch_head; 43 char *shallow; 44 char *merge_labels; 45 }; 46 47 struct repository { 48 /* Environment */ 49 /* 50 * Path to the git directory. 51 * Cannot be NULL after initialization. 52 */ 53 char *gitdir; 54 55 /* 56 * Path to the common git directory. 57 * Cannot be NULL after initialization. 58 */ 59 char *commondir; 60 61 /* 62 * The "prefix", a path to the current working directory relative to 63 * the work tree root, or NULL, if the current working directory is not 64 * a strict subdirectory of the work tree root. The prefix always ends 65 * with a '/' character. 66 */ 67 char *prefix; 68 69 /* 70 * Holds any information related to accessing the raw object content. 71 */ 72 struct object_database *objects; 73 74 /* 75 * All objects in this repository that have been parsed. This structure 76 * owns all objects it references, so users of "struct object *" 77 * generally do not need to free them; instead, when a repository is no 78 * longer used, call parsed_object_pool_clear() on this structure, which 79 * is called by the repositories repo_clear on its desconstruction. 80 */ 81 struct parsed_object_pool *parsed_objects; 82 83 /* 84 * The store in which the refs are held. This should generally only be 85 * accessed via get_main_ref_store(), as that will lazily initialize 86 * the ref object. 87 */ 88 struct ref_store *refs_private; 89 90 /* 91 * Disable ref updates. This is especially used in contexts where 92 * transactions may still be rolled back so that we don't start to 93 * reference objects that may vanish. 94 */ 95 bool disable_ref_updates; 96 97 /* 98 * A strmap of ref_stores, stored by submodule name, accessible via 99 * `repo_get_submodule_ref_store()`. 100 */ 101 struct strmap submodule_ref_stores; 102 103 /* 104 * A strmap of ref_stores, stored by worktree id, accessible via 105 * `get_worktree_ref_store()`. 106 */ 107 struct strmap worktree_ref_stores; 108 109 /* 110 * Contains path to often used file names. 111 */ 112 struct repo_path_cache cached_paths; 113 114 /* 115 * Path to the repository's graft file. 116 * Cannot be NULL after initialization. 117 */ 118 char *graft_file; 119 120 /* 121 * Path to the current worktree's index file. 122 * Cannot be NULL after initialization. 123 */ 124 char *index_file; 125 126 /* 127 * Path to the working directory. 128 * A NULL value indicates that there is no working directory. 129 */ 130 char *worktree; 131 bool worktree_initialized; 132 bool worktree_config_is_bogus; 133 134 /* 135 * Whether the repository is bare, as set by "core.bare" config or 136 * inferred during repository discovery. -1 means unset/unknown, 0 137 * means non-bare, 1 means bare. 138 */ 139 int bare_cfg; 140 141 /* 142 * Path from the root of the top-level superproject down to this 143 * repository. This is only non-NULL if the repository is initialized 144 * as a submodule of another repository. 145 */ 146 char *submodule_prefix; 147 148 struct repo_settings settings; 149 150 /* Subsystems */ 151 /* 152 * Repository's config which contains key-value pairs from the usual 153 * set of config files (i.e. repo specific .git/config, user wide 154 * ~/.gitconfig, XDG config file and the global /etc/gitconfig) 155 */ 156 struct config_set *config; 157 158 /* Repository's submodule config as defined by '.gitmodules' */ 159 struct submodule_cache *submodule_cache; 160 161 /* 162 * Repository's in-memory index. 163 * 'repo_read_index()' can be used to populate 'index'. 164 */ 165 struct index_state *index; 166 167 /* Repository's remotes and associated structures. */ 168 struct remote_state *remote_state; 169 170 /* Repository's current hash algorithm, as serialized on disk. */ 171 const struct git_hash_algo *hash_algo; 172 173 /* Repository's compatibility hash algorithm. */ 174 const struct git_hash_algo *compat_hash_algo; 175 176 /* Repository-specific configuration values. */ 177 struct repo_config_values config_values_private_; 178 179 /* Repository's reference storage format, as serialized on disk. */ 180 enum ref_storage_format ref_storage_format; 181 /* 182 * Reference storage information as needed for the backend. This contains 183 * only the payload from the reference URI without the schema. 184 */ 185 char *ref_storage_payload; 186 187 /* Repository's object storage format, as serialized on disk. */ 188 enum object_storage_format object_storage_format; 189 190 /* 191 * Object storage information as needed for the backend. This contains 192 * only the payload from the object storage format URI without the 193 * schema. 194 */ 195 char *object_storage_payload; 196 197 /* A unique-id for tracing purposes. */ 198 int trace2_repo_id; 199 200 /* True if commit-graph has been disabled within this process. */ 201 int commit_graph_disabled; 202 203 /* 204 * Indicates whether the rerere-cache has been enabled. -1 (the default 205 * value) causes us to perform auto-detection via ".git/rr-cache". 206 */ 207 int rerere_cache_enabled; 208 209 /* 210 * Controls whether the repository should lazily fetch missing 211 * objects from promisor remotes. Defaults to 1. 212 */ 213 int fetch_if_missing; 214 215 /* 216 * Lazily-populated cache mapping hook event names to configured hooks. 217 * NULL until first hook use. 218 */ 219 struct strmap *hook_config_cache; 220 221 /* Cached value of hook.jobs config (0 if unset, defaults to serial). */ 222 unsigned int hook_jobs; 223 224 /* Cached map of event-name -> jobs count (as uintptr_t) from hook..jobs. */ 225 struct strmap event_jobs; 226 227 /* Cached list of event names with hook..enabled = false. */ 228 struct string_list disabled_events; 229 230 /* Configurations related to promisor remotes. */ 231 char *repository_format_partial_clone; 232 struct promisor_remote_config *promisor_remote_config; 233 234 /* Configurations */ 235 int repository_format_worktree_config; 236 int repository_format_relative_worktrees; 237 int repository_format_precious_objects; 238 int repository_format_submodule_path_cfg; 239 240 /* Indicate if a repository has a different 'commondir' from 'gitdir' */ 241 unsigned different_commondir:1; 242 243 /* Should repo_config() check for deprecated settings */ 244 bool check_deprecated_config; 245 246 /* Has this repository instance been initialized? */ 247 bool initialized; 248 }; 249 250 #ifdef USE_THE_REPOSITORY_VARIABLE 251 extern struct repository *the_repository; 252 #endif 253 254 const char *repo_get_git_dir(struct repository *repo); 255 const char *repo_get_common_dir(struct repository *repo); 256 const char *repo_get_object_directory(struct repository *repo); 257 const char *repo_get_index_file(struct repository *repo); 258 const char *repo_get_graft_file(struct repository *repo); 259 const char *repo_get_work_tree(struct repository *repo); 260 261 /* 262 * Define a custom repository layout. Any field can be NULL, which 263 * will default back to the path according to the default layout. 264 */ 265 struct set_gitdir_args { 266 const char *commondir; 267 const char *graft_file; 268 const char *index_file; 269 bool disable_ref_updates; 270 }; 271 272 void repo_set_gitdir(struct repository *repo, const char *root, 273 const struct set_gitdir_args *extra_args); 274 void repo_set_worktree(struct repository *repo, const char *path); 275 void repo_set_hash_algo(struct repository *repo, uint32_t algo); 276 void repo_set_compat_hash_algo(struct repository *repo, uint32_t compat_algo); 277 void repo_set_ref_storage_format(struct repository *repo, 278 enum ref_storage_format format, 279 const char *payload); 280 void repo_set_object_storage_format(struct repository *repo, 281 enum object_storage_format format, 282 const char *payload); 283 void initialize_repository(struct repository *repo); 284 RESULT_MUST_BE_USED 285 int repo_init(struct repository *r, const char *gitdir, const char *worktree); 286 void repo_clear(struct repository *repo); 287 288 /* 289 * Initialize the repository 'subrepo' as the submodule at the given path. If 290 * the submodule's gitdir cannot be found at /.git, this function calls 291 * submodule_from_path() to try to find it. treeish_name is only used if 292 * submodule_from_path() needs to be called; see its documentation for more 293 * information. 294 * Return 0 upon success and a non-zero value upon failure. 295 */ 296 struct object_id; 297 RESULT_MUST_BE_USED 298 int repo_submodule_init(struct repository *subrepo, 299 struct repository *superproject, 300 const char *path, 301 const struct object_id *treeish_name); 302 303 /* 304 * Populates the repository's index from its index_file, an index struct will 305 * be allocated if needed. 306 * 307 * Return the number of index entries in the populated index or a value less 308 * than zero if an error occurred. If the repository's index has already been 309 * populated then the number of entries will simply be returned. 310 */ 311 int repo_read_index(struct repository *repo); 312 int repo_hold_locked_index(struct repository *repo, 313 struct lock_file *lf, 314 int flags); 315 316 int repo_read_index_unmerged(struct repository *); 317 /* 318 * Opportunistically update the index but do not complain if we can't. 319 * The lockfile is always committed or rolled back. 320 */ 321 void repo_update_index_if_able(struct repository *, struct lock_file *); 322 323 /* 324 * Like repo_update_index_if_able(), but take the lock only if the index 325 * has something to write, so that a caller that read the index without 326 * the lock holds it only for the write. 327 */ 328 void repo_lock_and_update_index_if_able(struct repository *); 329 330 /* 331 * Return 1 if upgrade repository format to target_version succeeded, 332 * 0 if no upgrade is necessary, and -1 when upgrade is not possible. 333 */ 334 int upgrade_repository_format(struct repository *repo, int target_version); 335 336 #endif /* REPOSITORY_H */