Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 1 | #ifndef REPOSITORY_H |
| 2 | #define REPOSITORY_H |
| 3 | |
Ævar Arnfjörð Bjarmason | 1e8697b | 2022-09-01 01:18:12 +0200 | [diff] [blame] | 4 | #include "git-compat-util.h" |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 5 | #include "path.h" |
| 6 | |
Brandon Williams | 3b25622 | 2017-06-22 11:43:42 -0700 | [diff] [blame] | 7 | struct config_set; |
Jeff Hostetler | 1e0ea5c | 2022-03-25 18:02:46 +0000 | [diff] [blame] | 8 | struct fsmonitor_settings; |
brian m. carlson | 78a6766 | 2017-11-12 21:28:53 +0000 | [diff] [blame] | 9 | struct git_hash_algo; |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 10 | struct index_state; |
Nguyễn Thái Ngọc Duy | 3a95f31 | 2019-01-12 09:13:24 +0700 | [diff] [blame] | 11 | struct lock_file; |
Nguyễn Thái Ngọc Duy | e1ff0a3 | 2019-01-12 09:13:26 +0700 | [diff] [blame] | 12 | struct pathspec; |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 13 | struct raw_object_store; |
| 14 | struct submodule_cache; |
Jonathan Tan | ef7dc2e | 2021-06-17 10:13:23 -0700 | [diff] [blame] | 15 | struct promisor_remote_config; |
Glen Choo | fd3cb05 | 2021-11-17 16:53:22 -0800 | [diff] [blame] | 16 | struct remote_state; |
Brandon Williams | 3b25622 | 2017-06-22 11:43:42 -0700 | [diff] [blame] | 17 | |
Derrick Stolee | ad0fb65 | 2019-08-13 11:37:46 -0700 | [diff] [blame] | 18 | enum untracked_cache_setting { |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 19 | UNTRACKED_CACHE_KEEP, |
| 20 | UNTRACKED_CACHE_REMOVE, |
| 21 | UNTRACKED_CACHE_WRITE, |
Derrick Stolee | ad0fb65 | 2019-08-13 11:37:46 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Derrick Stolee | aaf633c | 2019-08-13 11:37:48 -0700 | [diff] [blame] | 24 | enum fetch_negotiation_setting { |
Elijah Newren | 714edc6 | 2022-02-02 03:42:40 +0000 | [diff] [blame] | 25 | FETCH_NEGOTIATION_CONSECUTIVE, |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 26 | FETCH_NEGOTIATION_SKIPPING, |
| 27 | FETCH_NEGOTIATION_NOOP, |
Derrick Stolee | aaf633c | 2019-08-13 11:37:48 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 30 | struct repo_settings { |
| 31 | int initialized; |
| 32 | |
| 33 | int core_commit_graph; |
Taylor Blau | a92d852 | 2022-07-14 14:43:06 -0700 | [diff] [blame] | 34 | int commit_graph_generation_version; |
Taylor Blau | b66d847 | 2020-09-09 11:23:10 -0400 | [diff] [blame] | 35 | int commit_graph_read_changed_paths; |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 36 | int gc_write_commit_graph; |
Emily Shaffer | c695592 | 2022-10-26 17:32:45 -0400 | [diff] [blame] | 37 | int gc_cruft_packs; |
Derrick Stolee | 50f26bd | 2019-09-02 19:22:02 -0700 | [diff] [blame] | 38 | int fetch_write_commit_graph; |
Ævar Arnfjörð Bjarmason | c21919f | 2021-09-21 15:13:03 +0200 | [diff] [blame] | 39 | int command_requires_full_index; |
| 40 | int sparse_index; |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 41 | |
Jeff Hostetler | 1e0ea5c | 2022-03-25 18:02:46 +0000 | [diff] [blame] | 42 | struct fsmonitor_settings *fsmonitor; /* lazily loaded */ |
| 43 | |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 44 | int index_version; |
Derrick Stolee | ad0fb65 | 2019-08-13 11:37:46 -0700 | [diff] [blame] | 45 | enum untracked_cache_setting core_untracked_cache; |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 46 | |
| 47 | int pack_use_sparse; |
Derrick Stolee | aaf633c | 2019-08-13 11:37:48 -0700 | [diff] [blame] | 48 | enum fetch_negotiation_setting fetch_negotiation_algorithm; |
Derrick Stolee | 18e449f | 2020-09-25 12:33:34 +0000 | [diff] [blame] | 49 | |
| 50 | int core_multi_pack_index; |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Ævar Arnfjörð Bjarmason | 759f340 | 2022-03-04 19:32:17 +0100 | [diff] [blame] | 53 | struct repo_path_cache { |
| 54 | char *squash_msg; |
| 55 | char *merge_msg; |
| 56 | char *merge_rr; |
| 57 | char *merge_mode; |
| 58 | char *merge_head; |
| 59 | char *merge_autostash; |
| 60 | char *auto_merge; |
| 61 | char *fetch_head; |
| 62 | char *shallow; |
| 63 | }; |
| 64 | |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 65 | struct repository { |
| 66 | /* Environment */ |
| 67 | /* |
| 68 | * Path to the git directory. |
| 69 | * Cannot be NULL after initialization. |
| 70 | */ |
| 71 | char *gitdir; |
| 72 | |
| 73 | /* |
| 74 | * Path to the common git directory. |
| 75 | * Cannot be NULL after initialization. |
| 76 | */ |
| 77 | char *commondir; |
| 78 | |
| 79 | /* |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 80 | * Holds any information related to accessing the raw object content. |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 81 | */ |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 82 | struct raw_object_store *objects; |
Nguyễn Thái Ngọc Duy | 7bc0dca | 2018-03-03 18:35:57 +0700 | [diff] [blame] | 83 | |
Stefan Beller | 99bf115 | 2018-05-08 12:37:24 -0700 | [diff] [blame] | 84 | /* |
| 85 | * All objects in this repository that have been parsed. This structure |
| 86 | * owns all objects it references, so users of "struct object *" |
| 87 | * generally do not need to free them; instead, when a repository is no |
| 88 | * longer used, call parsed_object_pool_clear() on this structure, which |
| 89 | * is called by the repositories repo_clear on its desconstruction. |
| 90 | */ |
| 91 | struct parsed_object_pool *parsed_objects; |
| 92 | |
Jeff King | 0220461 | 2020-04-09 23:04:11 -0400 | [diff] [blame] | 93 | /* |
| 94 | * The store in which the refs are held. This should generally only be |
| 95 | * accessed via get_main_ref_store(), as that will lazily initialize |
| 96 | * the ref object. |
| 97 | */ |
| 98 | struct ref_store *refs_private; |
Stefan Beller | 64a7416 | 2018-04-11 17:21:14 -0700 | [diff] [blame] | 99 | |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 100 | /* |
Stefan Beller | 102de88 | 2018-05-17 15:51:51 -0700 | [diff] [blame] | 101 | * Contains path to often used file names. |
| 102 | */ |
Ævar Arnfjörð Bjarmason | 759f340 | 2022-03-04 19:32:17 +0100 | [diff] [blame] | 103 | struct repo_path_cache cached_paths; |
Stefan Beller | 102de88 | 2018-05-17 15:51:51 -0700 | [diff] [blame] | 104 | |
| 105 | /* |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 106 | * Path to the repository's graft file. |
| 107 | * Cannot be NULL after initialization. |
| 108 | */ |
| 109 | char *graft_file; |
| 110 | |
| 111 | /* |
| 112 | * Path to the current worktree's index file. |
| 113 | * Cannot be NULL after initialization. |
| 114 | */ |
| 115 | char *index_file; |
| 116 | |
| 117 | /* |
| 118 | * Path to the working directory. |
| 119 | * A NULL value indicates that there is no working directory. |
| 120 | */ |
| 121 | char *worktree; |
| 122 | |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 123 | /* |
| 124 | * Path from the root of the top-level superproject down to this |
| 125 | * repository. This is only non-NULL if the repository is initialized |
| 126 | * as a submodule of another repository. |
| 127 | */ |
| 128 | char *submodule_prefix; |
| 129 | |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 130 | struct repo_settings settings; |
| 131 | |
Brandon Williams | 3b25622 | 2017-06-22 11:43:42 -0700 | [diff] [blame] | 132 | /* Subsystems */ |
| 133 | /* |
| 134 | * Repository's config which contains key-value pairs from the usual |
| 135 | * set of config files (i.e. repo specific .git/config, user wide |
| 136 | * ~/.gitconfig, XDG config file and the global /etc/gitconfig) |
| 137 | */ |
| 138 | struct config_set *config; |
| 139 | |
Brandon Williams | bf12fcd | 2017-06-22 11:43:44 -0700 | [diff] [blame] | 140 | /* Repository's submodule config as defined by '.gitmodules' */ |
| 141 | struct submodule_cache *submodule_cache; |
| 142 | |
Brandon Williams | 639e30b | 2017-06-22 11:43:43 -0700 | [diff] [blame] | 143 | /* |
| 144 | * Repository's in-memory index. |
| 145 | * 'repo_read_index()' can be used to populate 'index'. |
| 146 | */ |
| 147 | struct index_state *index; |
| 148 | |
Glen Choo | fd3cb05 | 2021-11-17 16:53:22 -0800 | [diff] [blame] | 149 | /* Repository's remotes and associated structures. */ |
| 150 | struct remote_state *remote_state; |
| 151 | |
brian m. carlson | 78a6766 | 2017-11-12 21:28:53 +0000 | [diff] [blame] | 152 | /* Repository's current hash algorithm, as serialized on disk. */ |
| 153 | const struct git_hash_algo *hash_algo; |
| 154 | |
Jeff Hostetler | ee4512e | 2019-02-22 14:25:01 -0800 | [diff] [blame] | 155 | /* A unique-id for tracing purposes. */ |
| 156 | int trace2_repo_id; |
| 157 | |
Jeff King | 6abada1 | 2019-09-12 10:44:45 -0400 | [diff] [blame] | 158 | /* True if commit-graph has been disabled within this process. */ |
| 159 | int commit_graph_disabled; |
| 160 | |
Jonathan Tan | ebaf3bc | 2021-06-17 10:13:22 -0700 | [diff] [blame] | 161 | /* Configurations related to promisor remotes. */ |
| 162 | char *repository_format_partial_clone; |
Jonathan Tan | ef7dc2e | 2021-06-17 10:13:23 -0700 | [diff] [blame] | 163 | struct promisor_remote_config *promisor_remote_config; |
Jonathan Tan | ebaf3bc | 2021-06-17 10:13:22 -0700 | [diff] [blame] | 164 | |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 165 | /* Configurations */ |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 166 | |
| 167 | /* Indicate if a repository has a different 'commondir' from 'gitdir' */ |
| 168 | unsigned different_commondir:1; |
| 169 | }; |
| 170 | |
| 171 | extern struct repository *the_repository; |
| 172 | |
Nguyễn Thái Ngọc Duy | 00a3da2 | 2018-03-23 16:55:23 +0100 | [diff] [blame] | 173 | /* |
| 174 | * Define a custom repository layout. Any field can be NULL, which |
| 175 | * will default back to the path according to the default layout. |
| 176 | */ |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 177 | struct set_gitdir_args { |
| 178 | const char *commondir; |
| 179 | const char *object_dir; |
| 180 | const char *graft_file; |
| 181 | const char *index_file; |
Nguyễn Thái Ngọc Duy | 7bc0dca | 2018-03-03 18:35:57 +0700 | [diff] [blame] | 182 | const char *alternate_db; |
Neeraj Singh | ecd81df | 2021-12-06 22:05:05 +0000 | [diff] [blame] | 183 | int disable_ref_updates; |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 184 | }; |
| 185 | |
Nguyễn Thái Ngọc Duy | c2ec417 | 2018-06-30 11:20:29 +0200 | [diff] [blame] | 186 | void repo_set_gitdir(struct repository *repo, const char *root, |
| 187 | const struct set_gitdir_args *extra_args); |
| 188 | void repo_set_worktree(struct repository *repo, const char *path); |
| 189 | void repo_set_hash_algo(struct repository *repo, int algo); |
| 190 | void initialize_the_repository(void); |
Ævar Arnfjörð Bjarmason | 1e8697b | 2022-09-01 01:18:12 +0200 | [diff] [blame] | 191 | RESULT_MUST_BE_USED |
Nguyễn Thái Ngọc Duy | c2ec417 | 2018-06-30 11:20:29 +0200 | [diff] [blame] | 192 | int repo_init(struct repository *r, const char *gitdir, const char *worktree); |
Stefan Beller | d5498e0 | 2018-11-28 16:27:53 -0800 | [diff] [blame] | 193 | |
| 194 | /* |
Jonathan Tan | 8eb8dcf | 2021-09-09 11:47:28 -0700 | [diff] [blame] | 195 | * Initialize the repository 'subrepo' as the submodule at the given path. If |
| 196 | * the submodule's gitdir cannot be found at <path>/.git, this function calls |
| 197 | * submodule_from_path() to try to find it. treeish_name is only used if |
| 198 | * submodule_from_path() needs to be called; see its documentation for more |
| 199 | * information. |
| 200 | * Return 0 upon success and a non-zero value upon failure. |
Stefan Beller | d5498e0 | 2018-11-28 16:27:53 -0800 | [diff] [blame] | 201 | */ |
Jonathan Tan | 8eb8dcf | 2021-09-09 11:47:28 -0700 | [diff] [blame] | 202 | struct object_id; |
Ævar Arnfjörð Bjarmason | 1e8697b | 2022-09-01 01:18:12 +0200 | [diff] [blame] | 203 | RESULT_MUST_BE_USED |
Stefan Beller | d5498e0 | 2018-11-28 16:27:53 -0800 | [diff] [blame] | 204 | int repo_submodule_init(struct repository *subrepo, |
Nguyễn Thái Ngọc Duy | c2ec417 | 2018-06-30 11:20:29 +0200 | [diff] [blame] | 205 | struct repository *superproject, |
Jonathan Tan | 8eb8dcf | 2021-09-09 11:47:28 -0700 | [diff] [blame] | 206 | const char *path, |
| 207 | const struct object_id *treeish_name); |
Nguyễn Thái Ngọc Duy | c2ec417 | 2018-06-30 11:20:29 +0200 | [diff] [blame] | 208 | void repo_clear(struct repository *repo); |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 209 | |
Brandon Williams | 3f13877 | 2017-07-18 12:05:18 -0700 | [diff] [blame] | 210 | /* |
| 211 | * Populates the repository's index from its index_file, an index struct will |
| 212 | * be allocated if needed. |
| 213 | * |
| 214 | * Return the number of index entries in the populated index or a value less |
Elijah Newren | 15beaaa | 2019-11-05 17:07:23 +0000 | [diff] [blame] | 215 | * than zero if an error occurred. If the repository's index has already been |
Brandon Williams | 3f13877 | 2017-07-18 12:05:18 -0700 | [diff] [blame] | 216 | * populated then the number of entries will simply be returned. |
| 217 | */ |
Nguyễn Thái Ngọc Duy | c2ec417 | 2018-06-30 11:20:29 +0200 | [diff] [blame] | 218 | int repo_read_index(struct repository *repo); |
Nguyễn Thái Ngọc Duy | 3a95f31 | 2019-01-12 09:13:24 +0700 | [diff] [blame] | 219 | int repo_hold_locked_index(struct repository *repo, |
| 220 | struct lock_file *lf, |
| 221 | int flags); |
Brandon Williams | 639e30b | 2017-06-22 11:43:43 -0700 | [diff] [blame] | 222 | |
Nguyễn Thái Ngọc Duy | e1ff0a3 | 2019-01-12 09:13:26 +0700 | [diff] [blame] | 223 | int repo_read_index_preload(struct repository *, |
| 224 | const struct pathspec *pathspec, |
| 225 | unsigned refresh_flags); |
| 226 | int repo_read_index_unmerged(struct repository *); |
Nguyễn Thái Ngọc Duy | 1b0d968 | 2019-01-12 09:13:27 +0700 | [diff] [blame] | 227 | /* |
| 228 | * Opportunistically update the index but do not complain if we can't. |
| 229 | * The lockfile is always committed or rolled back. |
| 230 | */ |
| 231 | void repo_update_index_if_able(struct repository *, struct lock_file *); |
| 232 | |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 233 | void prepare_repo_settings(struct repository *r); |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 234 | |
Xin Li | 16af5f1 | 2020-06-05 02:10:01 -0700 | [diff] [blame] | 235 | /* |
| 236 | * Return 1 if upgrade repository format to target_version succeeded, |
| 237 | * 0 if no upgrade is necessary, and -1 when upgrade is not possible. |
| 238 | */ |
| 239 | int upgrade_repository_format(int target_version); |
| 240 | |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 241 | #endif /* REPOSITORY_H */ |