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)
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
struct object_id;
struct object_info;
+struct odb_read_stream;
/*
* The source is the part of the object database that stores the actual
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);
};
/*
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
#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)
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);
}