aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/source-files.c12
-rw-r--r--odb/source.h23
-rw-r--r--odb/streaming.c9
3 files changed, 37 insertions, 7 deletions
diff --git a/odb/source-files.c b/odb/source-files.c
index f2969a1214..b50a1f5492 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -55,6 +55,17 @@ static int odb_source_files_read_object_info(struct odb_source *source,
return -1;
}
+static int odb_source_files_read_object_stream(struct odb_read_stream **out,
+ struct odb_source *source,
+ const struct object_id *oid)
+{
+ struct odb_source_files *files = odb_source_files_downcast(source);
+ if (!packfile_store_read_object_stream(out, files->packed, oid) ||
+ !odb_source_loose_read_object_stream(out, source, oid))
+ return 0;
+ return -1;
+}
+
struct odb_source_files *odb_source_files_new(struct object_database *odb,
const char *path,
bool local)
@@ -70,6 +81,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
files->base.close = odb_source_files_close;
files->base.reprepare = odb_source_files_reprepare;
files->base.read_object_info = odb_source_files_read_object_info;
+ files->base.read_object_stream = odb_source_files_read_object_stream;
/*
* Ideally, we would only ever store absolute paths in the source. This
diff --git a/odb/source.h b/odb/source.h
index 150becafe6..4397cada27 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -50,6 +50,7 @@ enum object_info_flags {
struct object_id;
struct object_info;
+struct odb_read_stream;
/*
* The source is the part of the object database that stores the actual
@@ -138,6 +139,17 @@ struct odb_source {
const struct object_id *oid,
struct object_info *oi,
enum object_info_flags flags);
+
+ /*
+ * This callback is expected to create a new read stream that can be
+ * used to stream the object identified by the given ID.
+ *
+ * The callback is expected to return a negative error code in case
+ * creating the object stream has failed, 0 otherwise.
+ */
+ int (*read_object_stream)(struct odb_read_stream **out,
+ struct odb_source *source,
+ const struct object_id *oid);
};
/*
@@ -209,4 +221,15 @@ static inline int odb_source_read_object_info(struct odb_source *source,
return source->read_object_info(source, oid, oi, flags);
}
+/*
+ * Create a new read stream for the given object ID. Returns 0 on success, a
+ * negative error code otherwise.
+ */
+static inline int odb_source_read_object_stream(struct odb_read_stream **out,
+ struct odb_source *source,
+ const struct object_id *oid)
+{
+ return source->read_object_stream(out, source, oid);
+}
+
#endif
diff --git a/odb/streaming.c b/odb/streaming.c
index 19cda9407d..a4355cd245 100644
--- a/odb/streaming.c
+++ b/odb/streaming.c
@@ -6,11 +6,9 @@
#include "convert.h"
#include "environment.h"
#include "repository.h"
-#include "object-file.h"
#include "odb.h"
#include "odb/streaming.h"
#include "replace-object.h"
-#include "packfile.h"
#define FILTER_BUFFER (1024*16)
@@ -186,12 +184,9 @@ static int istream_source(struct odb_read_stream **out,
struct odb_source *source;
odb_prepare_alternates(odb);
- for (source = odb->sources; source; source = source->next) {
- struct odb_source_files *files = odb_source_files_downcast(source);
- if (!packfile_store_read_object_stream(out, files->packed, oid) ||
- !odb_source_loose_read_object_stream(out, source, oid))
+ for (source = odb->sources; source; source = source->next)
+ if (!odb_source_read_object_stream(out, source, oid))
return 0;
- }
return open_istream_incore(out, odb, oid);
}