The fifth batch
[alt-git.git] / repository.h
blobc4c92b2ab9c9e3b425dc2974636e33d1f4089c69
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;
153 int repository_format_relative_worktrees;
155 /* Indicate if a repository has a different 'commondir' from 'gitdir' */
156 unsigned different_commondir:1;
159 #ifdef USE_THE_REPOSITORY_VARIABLE
160 extern struct repository *the_repository;
161 #endif
163 const char *repo_get_git_dir(struct repository *repo);
164 const char *repo_get_common_dir(struct repository *repo);
165 const char *repo_get_object_directory(struct repository *repo);
166 const char *repo_get_index_file(struct repository *repo);
167 const char *repo_get_graft_file(struct repository *repo);
168 const char *repo_get_work_tree(struct repository *repo);
171 * Define a custom repository layout. Any field can be NULL, which
172 * will default back to the path according to the default layout.
174 struct set_gitdir_args {
175 const char *commondir;
176 const char *object_dir;
177 const char *graft_file;
178 const char *index_file;
179 const char *alternate_db;
180 int disable_ref_updates;
183 void repo_set_gitdir(struct repository *repo, const char *root,
184 const struct set_gitdir_args *extra_args);
185 void repo_set_worktree(struct repository *repo, const char *path);
186 void repo_set_hash_algo(struct repository *repo, int algo);
187 void repo_set_compat_hash_algo(struct repository *repo, int compat_algo);
188 void repo_set_ref_storage_format(struct repository *repo,
189 enum ref_storage_format format);
190 void initialize_repository(struct repository *repo);
191 RESULT_MUST_BE_USED
192 int repo_init(struct repository *r, const char *gitdir, const char *worktree);
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.
202 struct object_id;
203 RESULT_MUST_BE_USED
204 int repo_submodule_init(struct repository *subrepo,
205 struct repository *superproject,
206 const char *path,
207 const struct object_id *treeish_name);
208 void repo_clear(struct repository *repo);
211 * Populates the repository's index from its index_file, an index struct will
212 * be allocated if needed.
214 * Return the number of index entries in the populated index or a value less
215 * than zero if an error occurred. If the repository's index has already been
216 * populated then the number of entries will simply be returned.
218 int repo_read_index(struct repository *repo);
219 int repo_hold_locked_index(struct repository *repo,
220 struct lock_file *lf,
221 int flags);
223 int repo_read_index_unmerged(struct repository *);
225 * Opportunistically update the index but do not complain if we can't.
226 * The lockfile is always committed or rolled back.
228 void repo_update_index_if_able(struct repository *, struct lock_file *);
231 * Return 1 if upgrade repository format to target_version succeeded,
232 * 0 if no upgrade is necessary, and -1 when upgrade is not possible.
234 int upgrade_repository_format(int target_version);
236 #endif /* REPOSITORY_H */