aboutsummaryrefslogtreecommitdiff
path: root/odb.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-05 15:19:56 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-05 11:45:17 -0800
commiteb9635d83b7ef16df527db3e84def9d0c772344d (patch)
tree3f99a1d51f8ca693aab88600c544612239d92560 /odb.c
parent7ae23630c3ed012180edc88f0a9615a0d570a77c (diff)
downloadgit-eb9635d83b7ef16df527db3e84def9d0c772344d.tar.xz
odb/source: make `write_alternate()` function pluggable
Introduce a new callback function in `struct odb_source` to make the function pluggable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'odb.c')
-rw-r--r--odb.c52
1 files changed, 0 insertions, 52 deletions
diff --git a/odb.c b/odb.c
index d9424cdfd0..84a31084d3 100644
--- a/odb.c
+++ b/odb.c
@@ -236,58 +236,6 @@ static struct odb_source *odb_add_alternate_recursively(struct object_database *
return alternate;
}
-static int odb_source_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;
-
- hold_lock_file_for_update(&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;
-}
-
void odb_add_to_alternates_file(struct object_database *odb,
const char *dir)
{