odb/source: remove the ability to write alternates

There are no users of `odb_source_write_alternates()` in our tree
anymore. Remove that function and its supporting infrastructure.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
jch
Patrick Steinhardt 2026-08-31 12:02:12 +02:00 committed by Junio C Hamano
parent 1b65c850a5
commit 9e665c13b7
7 changed files with 0 additions and 117 deletions

9
odb.c
View File

@ -239,15 +239,6 @@ static struct odb_source *odb_add_alternate_recursively(struct object_database *
return alternate;
}

void odb_add_to_alternates_file(struct object_database *odb,
const char *dir)
{
int ret = odb_source_write_alternate(odb->sources, dir);
if (ret < 0)
die(NULL);
odb_add_alternate_recursively(odb, dir, 0);
}

struct odb_source *odb_add_to_alternates_memory(struct object_database *odb,
const char *dir)
{

7
odb.h
View File

@ -270,13 +270,6 @@ int odb_mkstemp(struct object_database *odb,
*/
int odb_has_alternates(struct object_database *odb);

/*
* Add the directory to the on-disk alternates file; the new entry will also
* take effect in the current process.
*/
void odb_add_to_alternates_file(struct object_database *odb,
const char *dir);

/*
* Add the directory to the in-memory list of alternate sources (along with any
* recursive alternates it points to), but do not modify the on-disk alternates

View File

@ -306,59 +306,6 @@ static int odb_source_files_read_alternates(struct odb_source *source,
return 0;
}

static int odb_source_files_write_alternate(struct odb_source *source,
const char *alternate)
{
struct lock_file lock = LOCK_INIT;
char *path = xstrfmt("%s/%s", source->path, "info/alternates");
FILE *in, *out;
int found = 0;
int ret;

repo_hold_lock_file_for_update(source->odb->repo, &lock, path,
LOCK_DIE_ON_ERROR);
out = fdopen_lock_file(&lock, "w");
if (!out) {
ret = error_errno(_("unable to fdopen alternates lockfile"));
goto out;
}

in = fopen(path, "r");
if (in) {
struct strbuf line = STRBUF_INIT;

while (strbuf_getline(&line, in) != EOF) {
if (!strcmp(alternate, line.buf)) {
found = 1;
break;
}
fprintf_or_die(out, "%s\n", line.buf);
}

strbuf_release(&line);
fclose(in);
} else if (errno != ENOENT) {
ret = error_errno(_("unable to read alternates file"));
goto out;
}

if (found) {
rollback_lock_file(&lock);
} else {
fprintf_or_die(out, "%s\n", alternate);
if (commit_lock_file(&lock)) {
ret = error_errno(_("unable to move new alternates file into place"));
goto out;
}
}

ret = 0;

out:
free(path);
return ret;
}

static int too_many_loose_objects(struct odb_source_files *files, int limit)
{
unsigned long loose_count;
@ -842,7 +789,6 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
files->base.write_object_stream = odb_source_files_write_object_stream;
files->base.begin_transaction = odb_source_files_begin_transaction;
files->base.read_alternates = odb_source_files_read_alternates;
files->base.write_alternate = odb_source_files_write_alternate;
files->base.optimize = odb_source_files_optimize;
files->base.optimize_required = odb_source_files_optimize_required;


View File

@ -326,12 +326,6 @@ static int odb_source_inmemory_read_alternates(struct odb_source *source UNUSED,
return 0;
}

static int odb_source_inmemory_write_alternate(struct odb_source *source UNUSED,
const char *alternate UNUSED)
{
return error("in-memory source does not support alternates");
}

static void odb_source_inmemory_close(struct odb_source *source UNUSED)
{
}
@ -388,7 +382,6 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
source->base.freshen_object = odb_source_inmemory_freshen_object;
source->base.begin_transaction = odb_source_inmemory_begin_transaction;
source->base.read_alternates = odb_source_inmemory_read_alternates;
source->base.write_alternate = odb_source_inmemory_write_alternate;

return source;
}

View File

@ -982,12 +982,6 @@ static int odb_source_loose_read_alternates(struct odb_source *source UNUSED,
return 0;
}

static int odb_source_loose_write_alternate(struct odb_source *source UNUSED,
const char *alternate UNUSED)
{
return error("loose source does not support alternates");
}

static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
{
oidtree_clear(loose->cache);
@ -1053,7 +1047,6 @@ struct odb_source_loose *odb_source_loose_new(struct object_database *odb,
loose->base.write_object_stream = odb_source_loose_write_object_stream;
loose->base.begin_transaction = odb_source_loose_begin_transaction;
loose->base.read_alternates = odb_source_loose_read_alternates;
loose->base.write_alternate = odb_source_loose_write_alternate;

if (!is_absolute_path(loose->base.path))
chdir_notify_register(NULL, odb_source_loose_reparent, loose);

View File

@ -628,12 +628,6 @@ static int odb_source_packed_read_alternates(struct odb_source *source UNUSED,
return 0;
}

static int odb_source_packed_write_alternate(struct odb_source *source UNUSED,
const char *alternate UNUSED)
{
return error("packed backend cannot write alternates");
}

void (*report_garbage)(unsigned seen_bits, const char *path);

static void report_helper(const struct string_list *list,
@ -849,7 +843,6 @@ struct odb_source_packed *odb_source_packed_new(struct object_database *odb,
packed->base.write_object_stream = odb_source_packed_write_object_stream;
packed->base.begin_transaction = odb_source_packed_begin_transaction;
packed->base.read_alternates = odb_source_packed_read_alternates;
packed->base.write_alternate = odb_source_packed_write_alternate;

if (!is_absolute_path(path))
chdir_notify_register(NULL, odb_source_packed_reparent, packed);

View File

@ -286,19 +286,6 @@ struct odb_source {
int (*read_alternates)(struct odb_source *source,
struct strvec *out);

/*
* This callback is expected to persist the singular alternate passed
* to it into its list of alternates. Any pre-existing alternates are
* expected to remain active. Subsequent calls to `read_alternates` are
* thus expected to yield the pre-existing list of alternates plus the
* newly added alternate appended to its end.
*
* The callback is expected to return 0 on success, a negative error
* code otherwise.
*/
int (*write_alternate)(struct odb_source *source,
const char *alternate);

/*
* This callback is expected to optimize the object database source.
* Returns 0 on success, a negative error code otherwise.
@ -518,19 +505,6 @@ static inline int odb_source_read_alternates(struct odb_source *source,
return source->read_alternates(source, out);
}

/*
* Write and persist a new alternate object database source for the given
* source. Any preexisting alternates are expected to stay valid, and the new
* alternate shall be appended to the end of the list.
*
* Returns 0 on success, a negative error code otherwise.
*/
static inline int odb_source_write_alternate(struct odb_source *source,
const char *alternate)
{
return source->write_alternate(source, alternate);
}

/*
* Create a new transaction that can be used to write objects into a temporary
* staging area. The objects will only be persisted when the transaction is