return 0;
}
-static int read_object_info_from_path(struct odb_source *source,
- const char *path,
- const struct object_id *oid,
- struct object_info *oi,
- enum object_info_flags flags)
+int read_object_info_from_path(struct odb_source_loose *loose,
+ const char *path,
+ const struct object_id *oid,
+ struct object_info *oi,
+ enum object_info_flags flags)
{
- struct odb_source_files *files = odb_source_files_downcast(source);
int ret;
int fd;
unsigned long mapsize;
struct stat st;
if ((!oi || (!oi->disk_sizep && !oi->mtimep)) && (flags & OBJECT_INFO_QUICK)) {
- ret = quick_has_loose(files->loose, oid) ? 0 : -1;
+ ret = quick_has_loose(loose, oid) ? 0 : -1;
goto out;
}
if (oi->typep == &type_scratch)
oi->typep = NULL;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, source->odb->repo->hash_algo);
+ oidclr(oi->delta_base_oid, loose->base.odb->repo->hash_algo);
if (!ret)
oi->whence = OI_LOOSE;
}
return ret;
}
-int odb_source_loose_read_object_info(struct odb_source *source,
- const struct object_id *oid,
- struct object_info *oi,
- enum object_info_flags flags)
-{
- static struct strbuf buf = STRBUF_INIT;
-
- /*
- * The second read shouldn't cause new loose objects to show up, unless
- * there was a race condition with a secondary process. We don't care
- * about this case though, so we simply skip reading loose objects a
- * second time.
- */
- if (flags & OBJECT_INFO_SECOND_READ)
- return -1;
-
- odb_loose_path(source, &buf, oid);
- return read_object_info_from_path(source, buf.buf, oid, oi, flags);
-}
-
static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
const void *buf, unsigned long len,
struct object_id *oid,
}
struct for_each_object_wrapper_data {
- struct odb_source *source;
+ struct odb_source_loose *loose;
const struct object_info *request;
odb_for_each_object_cb cb;
void *cb_data;
if (data->request) {
struct object_info oi = *data->request;
- if (read_object_info_from_path(data->source, path, oid, &oi, 0) < 0)
+ if (read_object_info_from_path(data->loose, path, oid, &oi, 0) < 0)
return -1;
return data->cb(oid, &oi, data->cb_data);
if (data->request) {
struct object_info oi = *data->request;
- if (odb_source_loose_read_object_info(data->source,
- oid, &oi, 0) < 0)
+ if (odb_source_read_object_info(&data->loose->base,
+ oid, &oi, 0) < 0)
return -1;
return data->cb(oid, &oi, data->cb_data);
void *cb_data,
const struct odb_for_each_object_options *opts)
{
+ struct odb_source_files *files = odb_source_files_downcast(source);
struct for_each_object_wrapper_data data = {
- .source = source,
+ .loose = files->loose,
.request = request,
.cb = cb,
.cb_data = cb_data,
struct odb_read_stream;
struct odb_source;
-int odb_source_loose_read_object_info(struct odb_source *source,
- const struct object_id *oid,
- struct object_info *oi,
- enum object_info_flags flags);
-
int odb_source_loose_read_object_stream(struct odb_read_stream **out,
struct odb_source *source,
const struct object_id *oid);
void **contents,
struct object_info *oi);
+int read_object_info_from_path(struct odb_source_loose *loose,
+ const char *path,
+ const struct object_id *oid,
+ struct object_info *oi,
+ enum object_info_flags flags);
+
struct odb_transaction;
/*
#include "abspath.h"
#include "chdir-notify.h"
#include "loose.h"
+#include "object-file.h"
#include "odb.h"
#include "odb/source-files.h"
#include "odb/source-loose.h"
#include "oidtree.h"
+#include "strbuf.h"
+
+static int odb_source_loose_read_object_info(struct odb_source *source,
+ const struct object_id *oid,
+ struct object_info *oi,
+ enum object_info_flags flags)
+{
+ struct odb_source_loose *loose = odb_source_loose_downcast(source);
+ static struct strbuf buf = STRBUF_INIT;
+
+ /*
+ * The second read shouldn't cause new loose objects to show up, unless
+ * there was a race condition with a secondary process. We don't care
+ * about this case though, so we simply skip reading loose objects a
+ * second time.
+ */
+ if (flags & OBJECT_INFO_SECOND_READ)
+ return -1;
+
+ odb_loose_path(source, &buf, oid);
+ return read_object_info_from_path(loose, buf.buf, oid, oi, flags);
+}
static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
{
loose->base.free = odb_source_loose_free;
loose->base.close = odb_source_loose_close;
loose->base.reprepare = odb_source_loose_reprepare;
+ loose->base.read_object_info = odb_source_loose_read_object_info;
if (!is_absolute_path(loose->base.path))
chdir_notify_register(NULL, odb_source_loose_reparent, loose);