Thread (14 messages) 14 messages, 1 author, 2d ago

[PATCH 11/13] odb/source-files: extract reading alternates

WARM2d

From: Patrick Steinhardt <hidden>
Date: 2026-10-02 10:08:58
Subsystem: the rest · Maintainer: Linus Torvalds

In the next commit we'll add a new callsite that wants to read
alternates without having a proper object database source for a given
alternate available to it. Prepare for this by extracting the logic into
a separate function that only requires an object directory path as
input.

Signed-off-by: Patrick Steinhardt <redacted>
---
 odb/source-files.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/odb/source-files.c b/odb/source-files.c
index 9389546b3e..6aaf625352 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -174,6 +174,24 @@ static int odb_source_files_create_on_disk(struct odb_source *source,
 	return ret;
 }
 
+static int read_alternates(const char *object_dir, struct strvec *out)
+{
+	struct strbuf buf = STRBUF_INIT;
+	char *path;
+
+	path = xstrfmt("%s/info/alternates", object_dir);
+	if (strbuf_read_file(&buf, path, 1024) < 0) {
+		warn_on_fopen_errors(path);
+		free(path);
+		return 0;
+	}
+	parse_alternates(buf.buf, '\n', object_dir, out);
+
+	strbuf_release(&buf);
+	free(path);
+	return 0;
+}
+
 static void odb_source_files_prepare(struct odb_source *source,
 				     enum odb_prepare_flags flags)
 {
@@ -364,20 +382,7 @@ static int odb_source_files_begin_transaction(struct odb_source *source,
 static int odb_source_files_read_alternates(struct odb_source *source,
 					    struct strvec *out)
 {
-	struct strbuf buf = STRBUF_INIT;
-	char *path;
-
-	path = xstrfmt("%s/info/alternates", source->path);
-	if (strbuf_read_file(&buf, path, 1024) < 0) {
-		warn_on_fopen_errors(path);
-		free(path);
-		return 0;
-	}
-	parse_alternates(buf.buf, '\n', source->path, out);
-
-	strbuf_release(&buf);
-	free(path);
-	return 0;
+	return read_alternates(source->path, out);
 }
 
 static int too_many_loose_objects(struct odb_source_files *files, int limit)
-- 
2.56.0.379.gc618271300.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help