]>
Commit | Line | Data |
---|---|---|
359efeff BW |
1 | #ifndef REPOSITORY_H |
2 | #define REPOSITORY_H | |
3 | ||
ef3ca954 EN |
4 | #include "path.h" |
5 | ||
3b256228 | 6 | struct config_set; |
90c62155 | 7 | struct git_hash_algo; |
639e30b5 | 8 | struct index_state; |
3a95f31d | 9 | struct lock_file; |
e1ff0a32 | 10 | struct pathspec; |
90c62155 | 11 | struct raw_object_store; |
bf12fcdf | 12 | struct submodule_cache; |
3b256228 | 13 | |
ad0fb659 DS |
14 | enum untracked_cache_setting { |
15 | UNTRACKED_CACHE_UNSET = -1, | |
16 | UNTRACKED_CACHE_REMOVE = 0, | |
17 | UNTRACKED_CACHE_KEEP = 1, | |
18 | UNTRACKED_CACHE_WRITE = 2 | |
19 | }; | |
20 | ||
7211b9e7 DS |
21 | struct repo_settings { |
22 | int initialized; | |
23 | ||
24 | int core_commit_graph; | |
25 | int gc_write_commit_graph; | |
26 | ||
27 | int index_version; | |
ad0fb659 | 28 | enum untracked_cache_setting core_untracked_cache; |
7211b9e7 DS |
29 | |
30 | int pack_use_sparse; | |
31 | }; | |
32 | ||
359efeff BW |
33 | struct repository { |
34 | /* Environment */ | |
35 | /* | |
36 | * Path to the git directory. | |
37 | * Cannot be NULL after initialization. | |
38 | */ | |
39 | char *gitdir; | |
40 | ||
41 | /* | |
42 | * Path to the common git directory. | |
43 | * Cannot be NULL after initialization. | |
44 | */ | |
45 | char *commondir; | |
46 | ||
47 | /* | |
90c62155 | 48 | * Holds any information related to accessing the raw object content. |
359efeff | 49 | */ |
90c62155 | 50 | struct raw_object_store *objects; |
7bc0dcaa | 51 | |
99bf115c SB |
52 | /* |
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. | |
58 | */ | |
59 | struct parsed_object_pool *parsed_objects; | |
60 | ||
64a74161 SB |
61 | /* The store in which the refs are held. */ |
62 | struct ref_store *refs; | |
63 | ||
102de880 SB |
64 | /* |
65 | * Contains path to often used file names. | |
66 | */ | |
67 | struct path_cache cached_paths; | |
68 | ||
359efeff BW |
69 | /* |
70 | * Path to the repository's graft file. | |
71 | * Cannot be NULL after initialization. | |
72 | */ | |
73 | char *graft_file; | |
74 | ||
75 | /* | |
76 | * Path to the current worktree's index file. | |
77 | * Cannot be NULL after initialization. | |
78 | */ | |
79 | char *index_file; | |
80 | ||
81 | /* | |
82 | * Path to the working directory. | |
83 | * A NULL value indicates that there is no working directory. | |
84 | */ | |
85 | char *worktree; | |
86 | ||
96dc883b BW |
87 | /* |
88 | * Path from the root of the top-level superproject down to this | |
89 | * repository. This is only non-NULL if the repository is initialized | |
90 | * as a submodule of another repository. | |
91 | */ | |
92 | char *submodule_prefix; | |
93 | ||
7211b9e7 DS |
94 | struct repo_settings settings; |
95 | ||
3b256228 BW |
96 | /* Subsystems */ |
97 | /* | |
98 | * Repository's config which contains key-value pairs from the usual | |
99 | * set of config files (i.e. repo specific .git/config, user wide | |
100 | * ~/.gitconfig, XDG config file and the global /etc/gitconfig) | |
101 | */ | |
102 | struct config_set *config; | |
103 | ||
bf12fcdf BW |
104 | /* Repository's submodule config as defined by '.gitmodules' */ |
105 | struct submodule_cache *submodule_cache; | |
106 | ||
639e30b5 BW |
107 | /* |
108 | * Repository's in-memory index. | |
109 | * 'repo_read_index()' can be used to populate 'index'. | |
110 | */ | |
111 | struct index_state *index; | |
112 | ||
78a67668 | 113 | /* Repository's current hash algorithm, as serialized on disk. */ |
114 | const struct git_hash_algo *hash_algo; | |
115 | ||
ee4512ed JH |
116 | /* A unique-id for tracing purposes. */ |
117 | int trace2_repo_id; | |
118 | ||
359efeff | 119 | /* Configurations */ |
359efeff BW |
120 | |
121 | /* Indicate if a repository has a different 'commondir' from 'gitdir' */ | |
122 | unsigned different_commondir:1; | |
123 | }; | |
124 | ||
125 | extern struct repository *the_repository; | |
126 | ||
00a3da2a NTND |
127 | /* |
128 | * Define a custom repository layout. Any field can be NULL, which | |
129 | * will default back to the path according to the default layout. | |
130 | */ | |
357a03eb NTND |
131 | struct set_gitdir_args { |
132 | const char *commondir; | |
133 | const char *object_dir; | |
134 | const char *graft_file; | |
135 | const char *index_file; | |
7bc0dcaa | 136 | const char *alternate_db; |
357a03eb NTND |
137 | }; |
138 | ||
c2ec4175 NTND |
139 | void repo_set_gitdir(struct repository *repo, const char *root, |
140 | const struct set_gitdir_args *extra_args); | |
141 | void repo_set_worktree(struct repository *repo, const char *path); | |
142 | void repo_set_hash_algo(struct repository *repo, int algo); | |
143 | void initialize_the_repository(void); | |
144 | int repo_init(struct repository *r, const char *gitdir, const char *worktree); | |
d5498e08 SB |
145 | |
146 | /* | |
147 | * Initialize the repository 'subrepo' as the submodule given by the | |
148 | * struct submodule 'sub' in parent repository 'superproject'. | |
149 | * Return 0 upon success and a non-zero value upon failure, which may happen | |
150 | * if the submodule is not found, or 'sub' is NULL. | |
151 | */ | |
152 | struct submodule; | |
153 | int repo_submodule_init(struct repository *subrepo, | |
c2ec4175 | 154 | struct repository *superproject, |
d5498e08 | 155 | const struct submodule *sub); |
c2ec4175 | 156 | void repo_clear(struct repository *repo); |
359efeff | 157 | |
3f138775 BW |
158 | /* |
159 | * Populates the repository's index from its index_file, an index struct will | |
160 | * be allocated if needed. | |
161 | * | |
162 | * Return the number of index entries in the populated index or a value less | |
163 | * than zero if an error occured. If the repository's index has already been | |
164 | * populated then the number of entries will simply be returned. | |
165 | */ | |
c2ec4175 | 166 | int repo_read_index(struct repository *repo); |
3a95f31d NTND |
167 | int repo_hold_locked_index(struct repository *repo, |
168 | struct lock_file *lf, | |
169 | int flags); | |
639e30b5 | 170 | |
e1ff0a32 NTND |
171 | int repo_read_index_preload(struct repository *, |
172 | const struct pathspec *pathspec, | |
173 | unsigned refresh_flags); | |
174 | int repo_read_index_unmerged(struct repository *); | |
1b0d968b NTND |
175 | /* |
176 | * Opportunistically update the index but do not complain if we can't. | |
177 | * The lockfile is always committed or rolled back. | |
178 | */ | |
179 | void repo_update_index_if_able(struct repository *, struct lock_file *); | |
180 | ||
7211b9e7 | 181 | void prepare_repo_settings(struct repository *r); |
639e30b5 | 182 | |
359efeff | 183 | #endif /* REPOSITORY_H */ |