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