]>
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 | |
7211b9e7 DS |
14 | struct repo_settings { |
15 | int initialized; | |
16 | ||
17 | int core_commit_graph; | |
18 | int gc_write_commit_graph; | |
19 | ||
20 | int index_version; | |
21 | ||
22 | int pack_use_sparse; | |
23 | }; | |
24 | ||
359efeff BW |
25 | struct repository { |
26 | /* Environment */ | |
27 | /* | |
28 | * Path to the git directory. | |
29 | * Cannot be NULL after initialization. | |
30 | */ | |
31 | char *gitdir; | |
32 | ||
33 | /* | |
34 | * Path to the common git directory. | |
35 | * Cannot be NULL after initialization. | |
36 | */ | |
37 | char *commondir; | |
38 | ||
39 | /* | |
90c62155 | 40 | * Holds any information related to accessing the raw object content. |
359efeff | 41 | */ |
90c62155 | 42 | struct raw_object_store *objects; |
7bc0dcaa | 43 | |
99bf115c SB |
44 | /* |
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. | |
50 | */ | |
51 | struct parsed_object_pool *parsed_objects; | |
52 | ||
64a74161 SB |
53 | /* The store in which the refs are held. */ |
54 | struct ref_store *refs; | |
55 | ||
102de880 SB |
56 | /* |
57 | * Contains path to often used file names. | |
58 | */ | |
59 | struct path_cache cached_paths; | |
60 | ||
359efeff BW |
61 | /* |
62 | * Path to the repository's graft file. | |
63 | * Cannot be NULL after initialization. | |
64 | */ | |
65 | char *graft_file; | |
66 | ||
67 | /* | |
68 | * Path to the current worktree's index file. | |
69 | * Cannot be NULL after initialization. | |
70 | */ | |
71 | char *index_file; | |
72 | ||
73 | /* | |
74 | * Path to the working directory. | |
75 | * A NULL value indicates that there is no working directory. | |
76 | */ | |
77 | char *worktree; | |
78 | ||
96dc883b BW |
79 | /* |
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. | |
83 | */ | |
84 | char *submodule_prefix; | |
85 | ||
7211b9e7 DS |
86 | struct repo_settings settings; |
87 | ||
3b256228 BW |
88 | /* Subsystems */ |
89 | /* | |
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) | |
93 | */ | |
94 | struct config_set *config; | |
95 | ||
bf12fcdf BW |
96 | /* Repository's submodule config as defined by '.gitmodules' */ |
97 | struct submodule_cache *submodule_cache; | |
98 | ||
639e30b5 BW |
99 | /* |
100 | * Repository's in-memory index. | |
101 | * 'repo_read_index()' can be used to populate 'index'. | |
102 | */ | |
103 | struct index_state *index; | |
104 | ||
78a67668 | 105 | /* Repository's current hash algorithm, as serialized on disk. */ |
106 | const struct git_hash_algo *hash_algo; | |
107 | ||
ee4512ed JH |
108 | /* A unique-id for tracing purposes. */ |
109 | int trace2_repo_id; | |
110 | ||
359efeff | 111 | /* Configurations */ |
359efeff BW |
112 | |
113 | /* Indicate if a repository has a different 'commondir' from 'gitdir' */ | |
114 | unsigned different_commondir:1; | |
115 | }; | |
116 | ||
117 | extern struct repository *the_repository; | |
118 | ||
00a3da2a NTND |
119 | /* |
120 | * Define a custom repository layout. Any field can be NULL, which | |
121 | * will default back to the path according to the default layout. | |
122 | */ | |
357a03eb NTND |
123 | struct set_gitdir_args { |
124 | const char *commondir; | |
125 | const char *object_dir; | |
126 | const char *graft_file; | |
127 | const char *index_file; | |
7bc0dcaa | 128 | const char *alternate_db; |
357a03eb NTND |
129 | }; |
130 | ||
c2ec4175 NTND |
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); | |
d5498e08 SB |
137 | |
138 | /* | |
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. | |
143 | */ | |
144 | struct submodule; | |
145 | int repo_submodule_init(struct repository *subrepo, | |
c2ec4175 | 146 | struct repository *superproject, |
d5498e08 | 147 | const struct submodule *sub); |
c2ec4175 | 148 | void repo_clear(struct repository *repo); |
359efeff | 149 | |
3f138775 BW |
150 | /* |
151 | * Populates the repository's index from its index_file, an index struct will | |
152 | * be allocated if needed. | |
153 | * | |
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. | |
157 | */ | |
c2ec4175 | 158 | int repo_read_index(struct repository *repo); |
3a95f31d NTND |
159 | int repo_hold_locked_index(struct repository *repo, |
160 | struct lock_file *lf, | |
161 | int flags); | |
639e30b5 | 162 | |
e1ff0a32 NTND |
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 *); | |
1b0d968b NTND |
167 | /* |
168 | * Opportunistically update the index but do not complain if we can't. | |
169 | * The lockfile is always committed or rolled back. | |
170 | */ | |
171 | void repo_update_index_if_able(struct repository *, struct lock_file *); | |
172 | ||
7211b9e7 | 173 | void prepare_repo_settings(struct repository *r); |
639e30b5 | 174 | |
359efeff | 175 | #endif /* REPOSITORY_H */ |