repo-settings: consolidate some config settings
[git.git] / repository.h
blobcc285ad3278bf8ac40dfb780afa523e2ee280029
1 #ifndef REPOSITORY_H
2 #define REPOSITORY_H
4 #include "path.h"
6 struct config_set;
7 struct git_hash_algo;
8 struct index_state;
9 struct lock_file;
10 struct pathspec;
11 struct raw_object_store;
12 struct submodule_cache;
14 struct repo_settings {
15 int initialized;
17 int core_commit_graph;
18 int gc_write_commit_graph;
20 int index_version;
22 int pack_use_sparse;
25 struct repository {
26 /* Environment */
28 * Path to the git directory.
29 * Cannot be NULL after initialization.
31 char *gitdir;
34 * Path to the common git directory.
35 * Cannot be NULL after initialization.
37 char *commondir;
40 * Holds any information related to accessing the raw object content.
42 struct raw_object_store *objects;
45 * All objects in this repository that have been parsed. This structure
46 * owns all objects it references, so users of "struct object *"
47 * generally do not need to free them; instead, when a repository is no
48 * longer used, call parsed_object_pool_clear() on this structure, which
49 * is called by the repositories repo_clear on its desconstruction.
51 struct parsed_object_pool *parsed_objects;
53 /* The store in which the refs are held. */
54 struct ref_store *refs;
57 * Contains path to often used file names.
59 struct path_cache cached_paths;
62 * Path to the repository's graft file.
63 * Cannot be NULL after initialization.
65 char *graft_file;
68 * Path to the current worktree's index file.
69 * Cannot be NULL after initialization.
71 char *index_file;
74 * Path to the working directory.
75 * A NULL value indicates that there is no working directory.
77 char *worktree;
80 * Path from the root of the top-level superproject down to this
81 * repository. This is only non-NULL if the repository is initialized
82 * as a submodule of another repository.
84 char *submodule_prefix;
86 struct repo_settings settings;
88 /* Subsystems */
90 * Repository's config which contains key-value pairs from the usual
91 * set of config files (i.e. repo specific .git/config, user wide
92 * ~/.gitconfig, XDG config file and the global /etc/gitconfig)
94 struct config_set *config;
96 /* Repository's submodule config as defined by '.gitmodules' */
97 struct submodule_cache *submodule_cache;
100 * Repository's in-memory index.
101 * 'repo_read_index()' can be used to populate 'index'.
103 struct index_state *index;
105 /* Repository's current hash algorithm, as serialized on disk. */
106 const struct git_hash_algo *hash_algo;
108 /* A unique-id for tracing purposes. */
109 int trace2_repo_id;
111 /* Configurations */
113 /* Indicate if a repository has a different 'commondir' from 'gitdir' */
114 unsigned different_commondir:1;
117 extern struct repository *the_repository;
120 * Define a custom repository layout. Any field can be NULL, which
121 * will default back to the path according to the default layout.
123 struct set_gitdir_args {
124 const char *commondir;
125 const char *object_dir;
126 const char *graft_file;
127 const char *index_file;
128 const char *alternate_db;
131 void repo_set_gitdir(struct repository *repo, const char *root,
132 const struct set_gitdir_args *extra_args);
133 void repo_set_worktree(struct repository *repo, const char *path);
134 void repo_set_hash_algo(struct repository *repo, int algo);
135 void initialize_the_repository(void);
136 int repo_init(struct repository *r, const char *gitdir, const char *worktree);
139 * Initialize the repository 'subrepo' as the submodule given by the
140 * struct submodule 'sub' in parent repository 'superproject'.
141 * Return 0 upon success and a non-zero value upon failure, which may happen
142 * if the submodule is not found, or 'sub' is NULL.
144 struct submodule;
145 int repo_submodule_init(struct repository *subrepo,
146 struct repository *superproject,
147 const struct submodule *sub);
148 void repo_clear(struct repository *repo);
151 * Populates the repository's index from its index_file, an index struct will
152 * be allocated if needed.
154 * Return the number of index entries in the populated index or a value less
155 * than zero if an error occured. If the repository's index has already been
156 * populated then the number of entries will simply be returned.
158 int repo_read_index(struct repository *repo);
159 int repo_hold_locked_index(struct repository *repo,
160 struct lock_file *lf,
161 int flags);
163 int repo_read_index_preload(struct repository *,
164 const struct pathspec *pathspec,
165 unsigned refresh_flags);
166 int repo_read_index_unmerged(struct repository *);
168 * Opportunistically update the index but do not complain if we can't.
169 * The lockfile is always committed or rolled back.
171 void repo_update_index_if_able(struct repository *, struct lock_file *);
173 void prepare_repo_settings(struct repository *r);
175 #endif /* REPOSITORY_H */