mirror of
https://github.com/git/git.git
synced 2025-12-23 12:14:22 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
430e0e0f2e
commit
3f42555322
125
odb.c
125
odb.c
@@ -132,77 +132,6 @@ out:
|
|||||||
return usable;
|
return usable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Prepare alternate object database registry.
|
|
||||||
*
|
|
||||||
* The variable alt_odb_list points at the list of struct
|
|
||||||
* odb_source. The elements on this list come from
|
|
||||||
* non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
|
|
||||||
* environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
|
|
||||||
* whose contents is similar to that environment variable but can be
|
|
||||||
* LF separated. Its base points at a statically allocated buffer that
|
|
||||||
* contains "/the/directory/corresponding/to/.git/objects/...", while
|
|
||||||
* its name points just after the slash at the end of ".git/objects/"
|
|
||||||
* in the example above, and has enough space to hold all hex characters
|
|
||||||
* of the object ID, an extra slash for the first level indirection, and
|
|
||||||
* the terminating NUL.
|
|
||||||
*/
|
|
||||||
static void read_info_alternates(const char *relative_base,
|
|
||||||
struct strvec *out);
|
|
||||||
|
|
||||||
static struct odb_source *odb_source_new(struct object_database *odb,
|
|
||||||
const char *path,
|
|
||||||
bool local)
|
|
||||||
{
|
|
||||||
struct odb_source *source;
|
|
||||||
|
|
||||||
CALLOC_ARRAY(source, 1);
|
|
||||||
source->odb = odb;
|
|
||||||
source->local = local;
|
|
||||||
source->path = xstrdup(path);
|
|
||||||
source->loose = odb_source_loose_new(source);
|
|
||||||
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct odb_source *odb_add_alternate_recursively(struct object_database *odb,
|
|
||||||
const char *source,
|
|
||||||
int depth)
|
|
||||||
{
|
|
||||||
struct odb_source *alternate = NULL;
|
|
||||||
struct strvec sources = STRVEC_INIT;
|
|
||||||
khiter_t pos;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!odb_is_source_usable(odb, source))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
alternate = odb_source_new(odb, source, false);
|
|
||||||
|
|
||||||
/* add the alternate entry */
|
|
||||||
*odb->sources_tail = alternate;
|
|
||||||
odb->sources_tail = &(alternate->next);
|
|
||||||
|
|
||||||
pos = kh_put_odb_path_map(odb->source_by_path, alternate->path, &ret);
|
|
||||||
if (!ret)
|
|
||||||
BUG("source must not yet exist");
|
|
||||||
kh_value(odb->source_by_path, pos) = alternate;
|
|
||||||
|
|
||||||
/* recursively add alternates */
|
|
||||||
read_info_alternates(alternate->path, &sources);
|
|
||||||
if (sources.nr && depth + 1 > 5) {
|
|
||||||
error(_("%s: ignoring alternate object stores, nesting too deep"),
|
|
||||||
source);
|
|
||||||
} else {
|
|
||||||
for (size_t i = 0; i < sources.nr; i++)
|
|
||||||
odb_add_alternate_recursively(odb, sources.v[i], depth + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
error:
|
|
||||||
strvec_clear(&sources);
|
|
||||||
return alternate;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void parse_alternates(const char *string,
|
static void parse_alternates(const char *string,
|
||||||
int sep,
|
int sep,
|
||||||
const char *relative_base,
|
const char *relative_base,
|
||||||
@@ -288,6 +217,60 @@ static void read_info_alternates(const char *relative_base,
|
|||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static struct odb_source *odb_source_new(struct object_database *odb,
|
||||||
|
const char *path,
|
||||||
|
bool local)
|
||||||
|
{
|
||||||
|
struct odb_source *source;
|
||||||
|
|
||||||
|
CALLOC_ARRAY(source, 1);
|
||||||
|
source->odb = odb;
|
||||||
|
source->local = local;
|
||||||
|
source->path = xstrdup(path);
|
||||||
|
source->loose = odb_source_loose_new(source);
|
||||||
|
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct odb_source *odb_add_alternate_recursively(struct object_database *odb,
|
||||||
|
const char *source,
|
||||||
|
int depth)
|
||||||
|
{
|
||||||
|
struct odb_source *alternate = NULL;
|
||||||
|
struct strvec sources = STRVEC_INIT;
|
||||||
|
khiter_t pos;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!odb_is_source_usable(odb, source))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
alternate = odb_source_new(odb, source, false);
|
||||||
|
|
||||||
|
/* add the alternate entry */
|
||||||
|
*odb->sources_tail = alternate;
|
||||||
|
odb->sources_tail = &(alternate->next);
|
||||||
|
|
||||||
|
pos = kh_put_odb_path_map(odb->source_by_path, alternate->path, &ret);
|
||||||
|
if (!ret)
|
||||||
|
BUG("source must not yet exist");
|
||||||
|
kh_value(odb->source_by_path, pos) = alternate;
|
||||||
|
|
||||||
|
/* recursively add alternates */
|
||||||
|
read_info_alternates(alternate->path, &sources);
|
||||||
|
if (sources.nr && depth + 1 > 5) {
|
||||||
|
error(_("%s: ignoring alternate object stores, nesting too deep"),
|
||||||
|
source);
|
||||||
|
} else {
|
||||||
|
for (size_t i = 0; i < sources.nr; i++)
|
||||||
|
odb_add_alternate_recursively(odb, sources.v[i], depth + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
error:
|
||||||
|
strvec_clear(&sources);
|
||||||
|
return alternate;
|
||||||
|
}
|
||||||
|
|
||||||
void odb_add_to_alternates_file(struct object_database *odb,
|
void odb_add_to_alternates_file(struct object_database *odb,
|
||||||
const char *dir)
|
const char *dir)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user