t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / repository.h
blob24a66a496a6ff516ce06d47b7329b3d36eb701ca
1 #ifndef REPOSITORY_H
2 #define REPOSITORY_H
4 #include "strmap.h"
5 #include "repo-settings.h"
7 struct config_set;
8 struct git_hash_algo;
9 struct index_state;
10 struct lock_file;
11 struct pathspec;
12 struct raw_object_store;
13 struct submodule_cache;
14 struct promisor_remote_config;
15 struct remote_state;
17 enum ref_storage_format {
18 REF_STORAGE_FORMAT_UNKNOWN,
19 REF_STORAGE_FORMAT_FILES,
20 REF_STORAGE_FORMAT_REFTABLE,
23 struct repo_path_cache {
24 char *squash_msg;
25 char *merge_msg;
26 char *merge_rr;
27 char *merge_mode;
28 char *merge_head;
29 char *fetch_head;
30 char *shallow;
33 struct repository {
34 /* Environment */
36 * Path to the git directory.
37 * Cannot be NULL after initialization.
39 char *gitdir;
42 * Path to the common git directory.
43 * Cannot be NULL after initialization.
45 char *commondir;
48 * Holds any information related to accessing the raw object content.
50 struct raw_object_store *objects;
53 * All objects in this repository that have been parsed. This structure
54 * owns all objects it references, so users of "struct object *"
55 * generally do not need to free them; instead, when a repository is no
56 * longer used, call parsed_object_pool_clear() on this structure, which
57 * is called by the repositories repo_clear on its desconstruction.
59 struct parsed_object_pool *parsed_objects;
62 * The store in which the refs are held. This should generally only be
63 * accessed via get_main_ref_store(), as that will lazily initialize
64 * the ref object.
66 struct ref_store *refs_private;
69 * A strmap of ref_stores, stored by submodule name, accessible via
70 * `repo_get_submodule_ref_store()`.
72 struct strmap submodule_ref_stores;
75 * A strmap of ref_stores, stored by worktree id, accessible via
76 * `get_worktree_ref_store()`.
78 struct strmap worktree_ref_stores;
81 * Contains path to often used file names.
83 struct repo_path_cache cached_paths;
86 * Path to the repository's graft file.
87 * Cannot be NULL after initialization.
89 char *graft_file;
92 * Path to the current worktree's index file.
93 * Cannot be NULL after initialization.
95 char *index_file;
98 * Path to the working directory.
99 * A NULL value indicates that there is no working directory.
101 char *worktree;
104 * Path from the root of the top-level superproject down to this
105 * repository. This is only non-NULL if the repository is initialized
106 * as a submodule of another repository.
108 char *submodule_prefix;
110 struct repo_settings settings;
112 /* Subsystems */
114 * Repository's config which contains key-value pairs from the usual
115 * set of config files (i.e. repo specific .git/config, user wide
116 * ~/.gitconfig, XDG config file and the global /etc/gitconfig)
118 struct config_set *config;
120 /* Repository's submodule config as defined by '.gitmodules' */
121 struct submodule_cache *submodule_cache;
124 * Repository's in-memory index.
125 * 'repo_read_index()' can be used to populate 'index'.
127 struct index_state *index;
129 /* Repository's remotes and associated structures. */
130 struct remote_state *remote_state;
132 /* Repository's current hash algorithm, as serialized on disk. */
133 const struct git_hash_algo *hash_algo;
135 /* Repository's compatibility hash algorithm. */
136 const struct git_hash_algo *compat_hash_algo;
138 /* Repository's reference storage format, as serialized on disk. */
139 enum ref_storage_format ref_storage_format;
141 /* A unique-id for tracing purposes. */
142 int trace2_repo_id;
144 /* True if commit-graph has been disabled within this process. */
145 int commit_graph_disabled;
147 /* Configurations related to promisor remotes. */
148 char *repository_format_partial_clone;
149 struct promisor_remote_config *promisor_remote_config;
151 /* Configurations */
152 int repository_format_worktree_config;
154 /* Indicate if a repository has a different 'commondir' from 'gitdir' */
155 unsigned different_commondir:1;
158 #ifdef USE_THE_REPOSITORY_VARIABLE
159 extern struct repository *the_repository;
160 #endif
162 const char *repo_get_git_dir(struct repository *repo);
163 const char *repo_get_common_dir(struct repository *repo);
164 const char *repo_get_object_directory(struct repository *repo);
165 const char *repo_get_index_file(struct repository *repo);
166 const char *repo_get_graft_file(struct repository *repo);
167 const char *repo_get_work_tree(struct repository *repo);
170 * Define a custom repository layout. Any field can be NULL, which
171 * will default back to the path according to the default layout.
173 struct set_gitdir_args {
174 const char *commondir;
175 const char *object_dir;
176 const char *graft_file;
177 const char *index_file;
178 const char *alternate_db;
179 int disable_ref_updates;
182 void repo_set_gitdir(struct repository *repo, const char *root,
183 const struct set_gitdir_args *extra_args);
184 void repo_set_worktree(struct repository *repo, const char *path);
185 void repo_set_hash_algo(struct repository *repo, int algo);
186 void repo_set_compat_hash_algo(struct repository *repo, int compat_algo);
187 void repo_set_ref_storage_format(struct repository *repo,
188 enum ref_storage_format format);
189 void initialize_repository(struct repository *repo);
190 RESULT_MUST_BE_USED
191 int repo_init(struct repository *r, const char *gitdir, const char *worktree);
194 * Initialize the repository 'subrepo' as the submodule at the given path. If
195 * the submodule's gitdir cannot be found at <path>/.git, this function calls
196 * submodule_from_path() to try to find it. treeish_name is only used if
197 * submodule_from_path() needs to be called; see its documentation for more
198 * information.
199 * Return 0 upon success and a non-zero value upon failure.
201 struct object_id;
202 RESULT_MUST_BE_USED
203 int repo_submodule_init(struct repository *subrepo,
204 struct repository *superproject,
205 const char *path,
206 const struct object_id *treeish_name);
207 void repo_clear(struct repository *repo);
210 * Populates the repository's index from its index_file, an index struct will
211 * be allocated if needed.
213 * Return the number of index entries in the populated index or a value less
214 * than zero if an error occurred. If the repository's index has already been
215 * populated then the number of entries will simply be returned.
217 int repo_read_index(struct repository *repo);
218 int repo_hold_locked_index(struct repository *repo,
219 struct lock_file *lf,
220 int flags);
222 int repo_read_index_unmerged(struct repository *);
224 * Opportunistically update the index but do not complain if we can't.
225 * The lockfile is always committed or rolled back.
227 void repo_update_index_if_able(struct repository *, struct lock_file *);
230 * Return 1 if upgrade repository format to target_version succeeded,
231 * 0 if no upgrade is necessary, and -1 when upgrade is not possible.
233 int upgrade_repository_format(int target_version);
235 #endif /* REPOSITORY_H */