| 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 | #ifdef WITH_BREAKING_CHANGES /* Git 3.0 */ |
| 26 | # define REF_STORAGE_FORMAT_DEFAULT REF_STORAGE_FORMAT_REFTABLE |
| 27 | #else |
| 28 | # define REF_STORAGE_FORMAT_DEFAULT REF_STORAGE_FORMAT_FILES |
| 29 | #endif |
| 30 | |
| 31 | struct repo_path_cache { |
| 32 | char *squash_msg; |
| 33 | char *merge_msg; |
| 34 | char *merge_rr; |
| 35 | char *merge_mode; |
| 36 | char *merge_head; |
| 37 | char *fetch_head; |
| 38 | char *shallow; |
| 39 | }; |
| 40 | |
| 41 | struct repository { |
| 42 | /* Environment */ |
| 43 | /* |
| 44 | * Path to the git directory. |
| 45 | * Cannot be NULL after initialization. |
| 46 | */ |
| 47 | char *gitdir; |
| 48 | |
| 49 | /* |
| 50 | * Path to the common git directory. |
| 51 | * Cannot be NULL after initialization. |
| 52 | */ |
| 53 | char *commondir; |
| 54 | |
| 55 | /* |
| 56 | * Holds any information related to accessing the raw object content. |
| 57 | */ |
| 58 | struct object_database *objects; |
| 59 | |
| 60 | /* |
| 61 | * All objects in this repository that have been parsed. This structure |
| 62 | * owns all objects it references, so users of "struct object *" |
| 63 | * generally do not need to free them; instead, when a repository is no |
| 64 | * longer used, call parsed_object_pool_clear() on this structure, which |
| 65 | * is called by the repositories repo_clear on its desconstruction. |
| 66 | */ |
| 67 | struct parsed_object_pool *parsed_objects; |
| 68 | |
| 69 | /* |
| 70 | * The store in which the refs are held. This should generally only be |
| 71 | * accessed via get_main_ref_store(), as that will lazily initialize |
| 72 | * the ref object. |
| 73 | */ |
| 74 | struct ref_store *refs_private; |
| 75 | |
| 76 | /* |
| 77 | * Disable ref updates. This is especially used in contexts where |
| 78 | * transactions may still be rolled back so that we don't start to |
| 79 | * reference objects that may vanish. |
| 80 | */ |
| 81 | bool disable_ref_updates; |
| 82 | |
| 83 | /* |
| 84 | * A strmap of ref_stores, stored by submodule name, accessible via |
| 85 | * `repo_get_submodule_ref_store()`. |
| 86 | */ |
| 87 | struct strmap submodule_ref_stores; |
| 88 | |
| 89 | /* |
| 90 | * A strmap of ref_stores, stored by worktree id, accessible via |
| 91 | * `get_worktree_ref_store()`. |
| 92 | */ |
| 93 | struct strmap worktree_ref_stores; |
| 94 | |
| 95 | /* |
| 96 | * Contains path to often used file names. |
| 97 | */ |
| 98 | struct repo_path_cache cached_paths; |
| 99 | |
| 100 | /* |
| 101 | * Path to the repository's graft file. |
| 102 | * Cannot be NULL after initialization. |
| 103 | */ |
| 104 | char *graft_file; |
| 105 | |
| 106 | /* |
| 107 | * Path to the current worktree's index file. |
| 108 | * Cannot be NULL after initialization. |
| 109 | */ |
| 110 | char *index_file; |
| 111 | |
| 112 | /* |
| 113 | * Path to the working directory. |
| 114 | * A NULL value indicates that there is no working directory. |
| 115 | */ |
| 116 | char *worktree; |
| 117 | bool worktree_initialized; |
| 118 | bool worktree_config_is_bogus; |
| 119 | |
| 120 | /* |
| 121 | * Path from the root of the top-level superproject down to this |
| 122 | * repository. This is only non-NULL if the repository is initialized |
| 123 | * as a submodule of another repository. |
| 124 | */ |
| 125 | char *submodule_prefix; |
| 126 | |
| 127 | struct repo_settings settings; |
| 128 | |
| 129 | /* Subsystems */ |
| 130 | /* |
| 131 | * Repository's config which contains key-value pairs from the usual |
| 132 | * set of config files (i.e. repo specific .git/config, user wide |
| 133 | * ~/.gitconfig, XDG config file and the global /etc/gitconfig) |
| 134 | */ |
| 135 | struct config_set *config; |
| 136 | |
| 137 | /* Repository's submodule config as defined by '.gitmodules' */ |
| 138 | struct submodule_cache *submodule_cache; |
| 139 | |
| 140 | /* |
| 141 | * Repository's in-memory index. |
| 142 | * 'repo_read_index()' can be used to populate 'index'. |
| 143 | */ |
| 144 | struct index_state *index; |
| 145 | |
| 146 | /* Repository's remotes and associated structures. */ |
| 147 | struct remote_state *remote_state; |
| 148 | |
| 149 | /* Repository's current hash algorithm, as serialized on disk. */ |
| 150 | const struct git_hash_algo *hash_algo; |
| 151 | |
| 152 | /* Repository's compatibility hash algorithm. */ |
| 153 | const struct git_hash_algo *compat_hash_algo; |
| 154 | |
| 155 | /* Repository's config values parsed by git_default_config() */ |
| 156 | struct repo_config_values config_values_private_; |
| 157 | |
| 158 | /* Repository's reference storage format, as serialized on disk. */ |
| 159 | enum ref_storage_format ref_storage_format; |
| 160 | /* |
| 161 | * Reference storage information as needed for the backend. This contains |
| 162 | * only the payload from the reference URI without the schema. |
| 163 | */ |
| 164 | char *ref_storage_payload; |
| 165 | |
| 166 | /* A unique-id for tracing purposes. */ |
| 167 | int trace2_repo_id; |
| 168 | |
| 169 | /* True if commit-graph has been disabled within this process. */ |
| 170 | int commit_graph_disabled; |
| 171 | |
| 172 | /* |
| 173 | * Lazily-populated cache mapping hook event names to configured hooks. |
| 174 | * NULL until first hook use. |
| 175 | */ |
| 176 | struct strmap *hook_config_cache; |
| 177 | |
| 178 | /* Cached value of hook.jobs config (0 if unset, defaults to serial). */ |
| 179 | unsigned int hook_jobs; |
| 180 | |
| 181 | /* Cached map of event-name -> jobs count (as uintptr_t) from hook.<event>.jobs. */ |
| 182 | struct strmap event_jobs; |
| 183 | |
| 184 | /* Cached list of event names with hook.<event>.enabled = false. */ |
| 185 | struct string_list disabled_events; |
| 186 | |
| 187 | /* Configurations related to promisor remotes. */ |
| 188 | char *repository_format_partial_clone; |
| 189 | struct promisor_remote_config *promisor_remote_config; |
| 190 | |
| 191 | /* Configurations */ |
| 192 | int repository_format_worktree_config; |
| 193 | int repository_format_relative_worktrees; |
| 194 | int repository_format_precious_objects; |
| 195 | int repository_format_submodule_path_cfg; |
| 196 | |
| 197 | /* Indicate if a repository has a different 'commondir' from 'gitdir' */ |
| 198 | unsigned different_commondir:1; |
| 199 | |
| 200 | /* Should repo_config() check for deprecated settings */ |
| 201 | bool check_deprecated_config; |
| 202 | |
| 203 | /* Has this repository instance been initialized? */ |
| 204 | bool initialized; |
| 205 | }; |
| 206 | |
| 207 | #ifdef USE_THE_REPOSITORY_VARIABLE |
| 208 | extern struct repository *the_repository; |
| 209 | #endif |
| 210 | |
| 211 | const char *repo_get_git_dir(struct repository *repo); |
| 212 | const char *repo_get_common_dir(struct repository *repo); |
| 213 | const char *repo_get_object_directory(struct repository *repo); |
| 214 | const char *repo_get_index_file(struct repository *repo); |
| 215 | const char *repo_get_graft_file(struct repository *repo); |
| 216 | const char *repo_get_work_tree(struct repository *repo); |
| 217 | |
| 218 | /* |
| 219 | * Define a custom repository layout. Any field can be NULL, which |
| 220 | * will default back to the path according to the default layout. |
| 221 | */ |
| 222 | struct set_gitdir_args { |
| 223 | const char *commondir; |
| 224 | const char *graft_file; |
| 225 | const char *index_file; |
| 226 | bool disable_ref_updates; |
| 227 | }; |
| 228 | |
| 229 | void repo_set_gitdir(struct repository *repo, const char *root, |
| 230 | const struct set_gitdir_args *extra_args); |
| 231 | void repo_set_worktree(struct repository *repo, const char *path); |
| 232 | void repo_set_hash_algo(struct repository *repo, uint32_t algo); |
| 233 | void repo_set_compat_hash_algo(struct repository *repo, uint32_t compat_algo); |
| 234 | void repo_set_ref_storage_format(struct repository *repo, |
| 235 | enum ref_storage_format format, |
| 236 | const char *payload); |
| 237 | void initialize_repository(struct repository *repo); |
| 238 | RESULT_MUST_BE_USED |
| 239 | int repo_init(struct repository *r, const char *gitdir, const char *worktree); |
| 240 | |
| 241 | /* |
| 242 | * Initialize the repository 'subrepo' as the submodule at the given path. If |
| 243 | * the submodule's gitdir cannot be found at <path>/.git, this function calls |
| 244 | * submodule_from_path() to try to find it. treeish_name is only used if |
| 245 | * submodule_from_path() needs to be called; see its documentation for more |
| 246 | * information. |
| 247 | * Return 0 upon success and a non-zero value upon failure. |
| 248 | */ |
| 249 | struct object_id; |
| 250 | RESULT_MUST_BE_USED |
| 251 | int repo_submodule_init(struct repository *subrepo, |
| 252 | struct repository *superproject, |
| 253 | const char *path, |
| 254 | const struct object_id *treeish_name); |
| 255 | void repo_clear(struct repository *repo); |
| 256 | |
| 257 | /* |
| 258 | * Populates the repository's index from its index_file, an index struct will |
| 259 | * be allocated if needed. |
| 260 | * |
| 261 | * Return the number of index entries in the populated index or a value less |
| 262 | * than zero if an error occurred. If the repository's index has already been |
| 263 | * populated then the number of entries will simply be returned. |
| 264 | */ |
| 265 | int repo_read_index(struct repository *repo); |
| 266 | int repo_hold_locked_index(struct repository *repo, |
| 267 | struct lock_file *lf, |
| 268 | int flags); |
| 269 | |
| 270 | int repo_read_index_unmerged(struct repository *); |
| 271 | /* |
| 272 | * Opportunistically update the index but do not complain if we can't. |
| 273 | * The lockfile is always committed or rolled back. |
| 274 | */ |
| 275 | void repo_update_index_if_able(struct repository *, struct lock_file *); |
| 276 | |
| 277 | /* |
| 278 | * Return 1 if upgrade repository format to target_version succeeded, |
| 279 | * 0 if no upgrade is necessary, and -1 when upgrade is not possible. |
| 280 | */ |
| 281 | int upgrade_repository_format(struct repository *repo, int target_version); |
| 282 | |
| 283 | #endif /* REPOSITORY_H */ |