debian: new upstream release
[git/debian.git] / repository.h
blob5f18486f6465c44b44abb2ded74bcdda14ba7bd9
1 #ifndef REPOSITORY_H
2 #define REPOSITORY_H
4 struct config_set;
5 struct fsmonitor_settings;
6 struct git_hash_algo;
7 struct index_state;
8 struct lock_file;
9 struct pathspec;
10 struct raw_object_store;
11 struct submodule_cache;
12 struct promisor_remote_config;
13 struct remote_state;
15 enum untracked_cache_setting {
16 UNTRACKED_CACHE_KEEP,
17 UNTRACKED_CACHE_REMOVE,
18 UNTRACKED_CACHE_WRITE,
21 enum fetch_negotiation_setting {
22 FETCH_NEGOTIATION_CONSECUTIVE,
23 FETCH_NEGOTIATION_SKIPPING,
24 FETCH_NEGOTIATION_NOOP,
27 struct repo_settings {
28 int initialized;
30 int core_commit_graph;
31 int commit_graph_generation_version;
32 int commit_graph_read_changed_paths;
33 int gc_write_commit_graph;
34 int fetch_write_commit_graph;
35 int command_requires_full_index;
36 int sparse_index;
37 int pack_read_reverse_index;
38 int pack_use_bitmap_boundary_traversal;
41 * Does this repository have core.useReplaceRefs=true (on by
42 * default)? This provides a repository-scoped version of this
43 * config, though it could be disabled process-wide via some Git
44 * builtins or the --no-replace-objects option. See
45 * replace_refs_enabled() for more details.
47 int read_replace_refs;
49 struct fsmonitor_settings *fsmonitor; /* lazily loaded */
51 int index_version;
52 int index_skip_hash;
53 enum untracked_cache_setting core_untracked_cache;
55 int pack_use_sparse;
56 enum fetch_negotiation_setting fetch_negotiation_algorithm;
58 int core_multi_pack_index;
61 struct repo_path_cache {
62 char *squash_msg;
63 char *merge_msg;
64 char *merge_rr;
65 char *merge_mode;
66 char *merge_head;
67 char *merge_autostash;
68 char *auto_merge;
69 char *fetch_head;
70 char *shallow;
73 struct repository {
74 /* Environment */
76 * Path to the git directory.
77 * Cannot be NULL after initialization.
79 char *gitdir;
82 * Path to the common git directory.
83 * Cannot be NULL after initialization.
85 char *commondir;
88 * Holds any information related to accessing the raw object content.
90 struct raw_object_store *objects;
93 * All objects in this repository that have been parsed. This structure
94 * owns all objects it references, so users of "struct object *"
95 * generally do not need to free them; instead, when a repository is no
96 * longer used, call parsed_object_pool_clear() on this structure, which
97 * is called by the repositories repo_clear on its desconstruction.
99 struct parsed_object_pool *parsed_objects;
102 * The store in which the refs are held. This should generally only be
103 * accessed via get_main_ref_store(), as that will lazily initialize
104 * the ref object.
106 struct ref_store *refs_private;
109 * Contains path to often used file names.
111 struct repo_path_cache cached_paths;
114 * Path to the repository's graft file.
115 * Cannot be NULL after initialization.
117 char *graft_file;
120 * Path to the current worktree's index file.
121 * Cannot be NULL after initialization.
123 char *index_file;
126 * Path to the working directory.
127 * A NULL value indicates that there is no working directory.
129 char *worktree;
132 * Path from the root of the top-level superproject down to this
133 * repository. This is only non-NULL if the repository is initialized
134 * as a submodule of another repository.
136 char *submodule_prefix;
138 struct repo_settings settings;
140 /* Subsystems */
142 * Repository's config which contains key-value pairs from the usual
143 * set of config files (i.e. repo specific .git/config, user wide
144 * ~/.gitconfig, XDG config file and the global /etc/gitconfig)
146 struct config_set *config;
148 /* Repository's submodule config as defined by '.gitmodules' */
149 struct submodule_cache *submodule_cache;
152 * Repository's in-memory index.
153 * 'repo_read_index()' can be used to populate 'index'.
155 struct index_state *index;
157 /* Repository's remotes and associated structures. */
158 struct remote_state *remote_state;
160 /* Repository's current hash algorithm, as serialized on disk. */
161 const struct git_hash_algo *hash_algo;
163 /* A unique-id for tracing purposes. */
164 int trace2_repo_id;
166 /* True if commit-graph has been disabled within this process. */
167 int commit_graph_disabled;
169 /* Configurations related to promisor remotes. */
170 char *repository_format_partial_clone;
171 struct promisor_remote_config *promisor_remote_config;
173 /* Configurations */
174 int repository_format_worktree_config;
176 /* Indicate if a repository has a different 'commondir' from 'gitdir' */
177 unsigned different_commondir:1;
180 extern struct repository *the_repository;
181 #ifdef USE_THE_INDEX_VARIABLE
182 extern struct index_state the_index;
183 #endif
186 * Define a custom repository layout. Any field can be NULL, which
187 * will default back to the path according to the default layout.
189 struct set_gitdir_args {
190 const char *commondir;
191 const char *object_dir;
192 const char *graft_file;
193 const char *index_file;
194 const char *alternate_db;
195 int disable_ref_updates;
198 void repo_set_gitdir(struct repository *repo, const char *root,
199 const struct set_gitdir_args *extra_args);
200 void repo_set_worktree(struct repository *repo, const char *path);
201 void repo_set_hash_algo(struct repository *repo, int algo);
202 void initialize_the_repository(void);
203 RESULT_MUST_BE_USED
204 int repo_init(struct repository *r, const char *gitdir, const char *worktree);
207 * Initialize the repository 'subrepo' as the submodule at the given path. If
208 * the submodule's gitdir cannot be found at <path>/.git, this function calls
209 * submodule_from_path() to try to find it. treeish_name is only used if
210 * submodule_from_path() needs to be called; see its documentation for more
211 * information.
212 * Return 0 upon success and a non-zero value upon failure.
214 struct object_id;
215 RESULT_MUST_BE_USED
216 int repo_submodule_init(struct repository *subrepo,
217 struct repository *superproject,
218 const char *path,
219 const struct object_id *treeish_name);
220 void repo_clear(struct repository *repo);
223 * Populates the repository's index from its index_file, an index struct will
224 * be allocated if needed.
226 * Return the number of index entries in the populated index or a value less
227 * than zero if an error occurred. If the repository's index has already been
228 * populated then the number of entries will simply be returned.
230 int repo_read_index(struct repository *repo);
231 int repo_hold_locked_index(struct repository *repo,
232 struct lock_file *lf,
233 int flags);
235 int repo_read_index_unmerged(struct repository *);
237 * Opportunistically update the index but do not complain if we can't.
238 * The lockfile is always committed or rolled back.
240 void repo_update_index_if_able(struct repository *, struct lock_file *);
242 void prepare_repo_settings(struct repository *r);
245 * Return 1 if upgrade repository format to target_version succeeded,
246 * 0 if no upgrade is necessary, and -1 when upgrade is not possible.
248 int upgrade_repository_format(int target_version);
250 #endif /* REPOSITORY_H */