5 #include "repo-settings.h"
12 struct object_database
;
13 struct submodule_cache
;
14 struct promisor_remote_config
;
17 enum ref_storage_format
{
18 REF_STORAGE_FORMAT_UNKNOWN
,
19 REF_STORAGE_FORMAT_FILES
,
20 REF_STORAGE_FORMAT_REFTABLE
,
23 #ifdef WITH_BREAKING_CHANGES /* Git 3.0 */
24 # define REF_STORAGE_FORMAT_DEFAULT REF_STORAGE_FORMAT_REFTABLE
26 # define REF_STORAGE_FORMAT_DEFAULT REF_STORAGE_FORMAT_FILES
29 struct repo_path_cache
{
42 * Path to the git directory.
43 * Cannot be NULL after initialization.
48 * Path to the common git directory.
49 * Cannot be NULL after initialization.
54 * Holds any information related to accessing the raw object content.
56 struct object_database
*objects
;
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.
65 struct parsed_object_pool
*parsed_objects
;
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
72 struct ref_store
*refs_private
;
75 * A strmap of ref_stores, stored by submodule name, accessible via
76 * `repo_get_submodule_ref_store()`.
78 struct strmap submodule_ref_stores
;
81 * A strmap of ref_stores, stored by worktree id, accessible via
82 * `get_worktree_ref_store()`.
84 struct strmap worktree_ref_stores
;
87 * Contains path to often used file names.
89 struct repo_path_cache cached_paths
;
92 * Path to the repository's graft file.
93 * Cannot be NULL after initialization.
98 * Path to the current worktree's index file.
99 * Cannot be NULL after initialization.
104 * Path to the working directory.
105 * A NULL value indicates that there is no working directory.
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.
114 char *submodule_prefix
;
116 struct repo_settings settings
;
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)
124 struct config_set
*config
;
126 /* Repository's submodule config as defined by '.gitmodules' */
127 struct submodule_cache
*submodule_cache
;
130 * Repository's in-memory index.
131 * 'repo_read_index()' can be used to populate 'index'.
133 struct index_state
*index
;
135 /* Repository's remotes and associated structures. */
136 struct remote_state
*remote_state
;
138 /* Repository's current hash algorithm, as serialized on disk. */
139 const struct git_hash_algo
*hash_algo
;
141 /* Repository's compatibility hash algorithm. */
142 const struct git_hash_algo
*compat_hash_algo
;
144 /* Repository's reference storage format, as serialized on disk. */
145 enum ref_storage_format ref_storage_format
;
147 /* A unique-id for tracing purposes. */
150 /* True if commit-graph has been disabled within this process. */
151 int commit_graph_disabled
;
153 /* Configurations related to promisor remotes. */
154 char *repository_format_partial_clone
;
155 struct promisor_remote_config
*promisor_remote_config
;
158 int repository_format_worktree_config
;
159 int repository_format_relative_worktrees
;
160 int repository_format_precious_objects
;
162 /* Indicate if a repository has a different 'commondir' from 'gitdir' */
163 unsigned different_commondir
:1;
166 #ifdef USE_THE_REPOSITORY_VARIABLE
167 extern struct repository
*the_repository
;
170 const char *repo_get_git_dir(struct repository
*repo
);
171 const char *repo_get_common_dir(struct repository
*repo
);
172 const char *repo_get_object_directory(struct repository
*repo
);
173 const char *repo_get_index_file(struct repository
*repo
);
174 const char *repo_get_graft_file(struct repository
*repo
);
175 const char *repo_get_work_tree(struct repository
*repo
);
178 * Define a custom repository layout. Any field can be NULL, which
179 * will default back to the path according to the default layout.
181 struct set_gitdir_args
{
182 const char *commondir
;
183 const char *object_dir
;
184 const char *graft_file
;
185 const char *index_file
;
186 const char *alternate_db
;
187 int disable_ref_updates
;
190 void repo_set_gitdir(struct repository
*repo
, const char *root
,
191 const struct set_gitdir_args
*extra_args
);
192 void repo_set_worktree(struct repository
*repo
, const char *path
);
193 void repo_set_hash_algo(struct repository
*repo
, int algo
);
194 void repo_set_compat_hash_algo(struct repository
*repo
, int compat_algo
);
195 void repo_set_ref_storage_format(struct repository
*repo
,
196 enum ref_storage_format format
);
197 void initialize_repository(struct repository
*repo
);
199 int repo_init(struct repository
*r
, const char *gitdir
, const char *worktree
);
202 * Initialize the repository 'subrepo' as the submodule at the given path. If
203 * the submodule's gitdir cannot be found at <path>/.git, this function calls
204 * submodule_from_path() to try to find it. treeish_name is only used if
205 * submodule_from_path() needs to be called; see its documentation for more
207 * Return 0 upon success and a non-zero value upon failure.
211 int repo_submodule_init(struct repository
*subrepo
,
212 struct repository
*superproject
,
214 const struct object_id
*treeish_name
);
215 void repo_clear(struct repository
*repo
);
218 * Populates the repository's index from its index_file, an index struct will
219 * be allocated if needed.
221 * Return the number of index entries in the populated index or a value less
222 * than zero if an error occurred. If the repository's index has already been
223 * populated then the number of entries will simply be returned.
225 int repo_read_index(struct repository
*repo
);
226 int repo_hold_locked_index(struct repository
*repo
,
227 struct lock_file
*lf
,
230 int repo_read_index_unmerged(struct repository
*);
232 * Opportunistically update the index but do not complain if we can't.
233 * The lockfile is always committed or rolled back.
235 void repo_update_index_if_able(struct repository
*, struct lock_file
*);
238 * Return 1 if upgrade repository format to target_version succeeded,
239 * 0 if no upgrade is necessary, and -1 when upgrade is not possible.
241 int upgrade_repository_format(int target_version
);
243 #endif /* REPOSITORY_H */