odb: drop forward declaration of `read_info_alternates()`

Now that we have removed the mutual recursion in the preceding commit it is not necessary anymore to have a forward declaration of the `read_info_alternates()` function. Move the function and its dependencies further up so that we can remove it. Note that this commit also removes the function documentation of `read_info_alternates()`. It's unclear what it's documenting, but it for sure isn't documenting the modern behaviour of the function anymore. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 11, 2025 at 10:30 UTC 3f42555322f86f17a2dac4f585edab1d84f3df57
1 file changed +54 -71
odb.c
+54 -71
@@ -132,77 +132,6 @@ out:
132 return usable;
133 }
134
135 -/*
136 - * Prepare alternate object database registry.
137 - *
138 - * The variable alt_odb_list points at the list of struct
139 - * odb_source. The elements on this list come from
140 - * non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
141 - * environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
142 - * whose contents is similar to that environment variable but can be
143 - * LF separated. Its base points at a statically allocated buffer that
144 - * contains "/the/directory/corresponding/to/.git/objects/...", while
145 - * its name points just after the slash at the end of ".git/objects/"
146 - * in the example above, and has enough space to hold all hex characters
147 - * of the object ID, an extra slash for the first level indirection, and
148 - * the terminating NUL.
149 - */
150 -static void read_info_alternates(const char *relative_base,
151 - struct strvec *out);
152 -
153 -static struct odb_source *odb_source_new(struct object_database *odb,
154 - const char *path,
155 - bool local)
156 -{
157 - struct odb_source *source;
158 -
159 - CALLOC_ARRAY(source, 1);
160 - source->odb = odb;
161 - source->local = local;
162 - source->path = xstrdup(path);
163 - source->loose = odb_source_loose_new(source);
164 -
165 - return source;
166 -}
167 -
168 -static struct odb_source *odb_add_alternate_recursively(struct object_database *odb,
169 - const char *source,
170 - int depth)
171 -{
172 - struct odb_source *alternate = NULL;
173 - struct strvec sources = STRVEC_INIT;
174 - khiter_t pos;
175 - int ret;
176 -
177 - if (!odb_is_source_usable(odb, source))
178 - goto error;
179 -
180 - alternate = odb_source_new(odb, source, false);
181 -
182 - /* add the alternate entry */
183 - *odb->sources_tail = alternate;
184 - odb->sources_tail = &(alternate->next);
185 -
186 - pos = kh_put_odb_path_map(odb->source_by_path, alternate->path, &ret);
187 - if (!ret)
188 - BUG("source must not yet exist");
189 - kh_value(odb->source_by_path, pos) = alternate;
190 -
191 - /* recursively add alternates */
192 - read_info_alternates(alternate->path, &sources);
193 - if (sources.nr && depth + 1 > 5) {
194 - error(_("%s: ignoring alternate object stores, nesting too deep"),
195 - source);
196 - } else {
197 - for (size_t i = 0; i < sources.nr; i++)
198 - odb_add_alternate_recursively(odb, sources.v[i], depth + 1);
199 - }
200 -
201 - error:
202 - strvec_clear(&sources);
203 - return alternate;
204 -}
205 -
135 static void parse_alternates(const char *string,
136 int sep,
137 const char *relative_base,
@@ -288,6 +217,60 @@ static void read_info_alternates(const char *relative_base,
217 free(path);
218 }
219
220 +
221 +static struct odb_source *odb_source_new(struct object_database *odb,
222 + const char *path,
223 + bool local)
224 +{
225 + struct odb_source *source;
226 +
227 + CALLOC_ARRAY(source, 1);
228 + source->odb = odb;
229 + source->local = local;
230 + source->path = xstrdup(path);
231 + source->loose = odb_source_loose_new(source);
232 +
233 + return source;
234 +}
235 +
236 +static struct odb_source *odb_add_alternate_recursively(struct object_database *odb,
237 + const char *source,
238 + int depth)
239 +{
240 + struct odb_source *alternate = NULL;
241 + struct strvec sources = STRVEC_INIT;
242 + khiter_t pos;
243 + int ret;
244 +
245 + if (!odb_is_source_usable(odb, source))
246 + goto error;
247 +
248 + alternate = odb_source_new(odb, source, false);
249 +
250 + /* add the alternate entry */
251 + *odb->sources_tail = alternate;
252 + odb->sources_tail = &(alternate->next);
253 +
254 + pos = kh_put_odb_path_map(odb->source_by_path, alternate->path, &ret);
255 + if (!ret)
256 + BUG("source must not yet exist");
257 + kh_value(odb->source_by_path, pos) = alternate;
258 +
259 + /* recursively add alternates */
260 + read_info_alternates(alternate->path, &sources);
261 + if (sources.nr && depth + 1 > 5) {
262 + error(_("%s: ignoring alternate object stores, nesting too deep"),
263 + source);
264 + } else {
265 + for (size_t i = 0; i < sources.nr; i++)
266 + odb_add_alternate_recursively(odb, sources.v[i], depth + 1);
267 + }
268 +
269 + error:
270 + strvec_clear(&sources);
271 + return alternate;
272 +}
273 +
274 void odb_add_to_alternates_file(struct object_database *odb,
275 const char *dir)
276 {