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