return 0;
}
+static int odb_source_files_count_objects(struct odb_source *source,
+ enum odb_count_objects_flags flags,
+ unsigned long *out)
+{
+ struct odb_source_files *files = odb_source_files_downcast(source);
+ unsigned long count;
+ int ret;
+
+ ret = packfile_store_count_objects(files->packed, flags, &count);
+ if (ret < 0)
+ goto out;
+
+ if (!(flags & ODB_COUNT_OBJECTS_APPROXIMATE)) {
+ unsigned long loose_count;
+
+ ret = odb_source_loose_count_objects(source, flags, &loose_count);
+ if (ret < 0)
+ goto out;
+
+ count += loose_count;
+ }
+
+ *out = count;
+ ret = 0;
+
+out:
+ return ret;
+}
+
static int odb_source_files_freshen_object(struct odb_source *source,
const struct object_id *oid)
{
files->base.read_object_info = odb_source_files_read_object_info;
files->base.read_object_stream = odb_source_files_read_object_stream;
files->base.for_each_object = odb_source_files_for_each_object;
+ files->base.count_objects = odb_source_files_count_objects;
files->base.freshen_object = odb_source_files_freshen_object;
files->base.write_object = odb_source_files_write_object;
files->base.write_object_stream = odb_source_files_write_object_stream;
void *cb_data,
unsigned flags);
+ /*
+ * This callback is expected to count objects in the given object
+ * database source. The callback function does not have to guarantee
+ * that only unique objects are counted. The result shall be assigned
+ * to the `out` pointer.
+ *
+ * Accepts `enum odb_count_objects_flag` flags to alter the behaviour.
+ *
+ * The callback is expected to return 0 on success, or a negative error
+ * code otherwise.
+ */
+ int (*count_objects)(struct odb_source *source,
+ enum odb_count_objects_flags flags,
+ unsigned long *out);
+
/*
* This callback is expected to freshen the given object so that its
* last access time is set to the current time. This is used to ensure
return source->for_each_object(source, request, cb, cb_data, flags);
}
+/*
+ * Count the number of objects in the given object database source.
+ *
+ * Returns 0 on success, a negative error code otherwise.
+ */
+static inline int odb_source_count_objects(struct odb_source *source,
+ enum odb_count_objects_flags flags,
+ unsigned long *out)
+{
+ return source->count_objects(source, flags, out);
+}
+
/*
* Freshen an object in the object database by updating its timestamp.
* Returns 1 in case the object has been freshened, 0 in case the object does
}
int packfile_store_count_objects(struct packfile_store *store,
+ enum odb_count_objects_flags flags UNUSED,
unsigned long *out)
{
struct packfile_list_entry *e;
odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
- struct odb_source_files *files = odb_source_files_downcast(source);
unsigned long c;
- if (!packfile_store_count_objects(files->packed, &c))
+ if (!odb_source_count_objects(source, ODB_COUNT_OBJECTS_APPROXIMATE, &c))
count += c;
}
* Return 0 on success, a negative error code otherwise.
*/
int packfile_store_count_objects(struct packfile_store *store,
+ enum odb_count_objects_flags flags,
unsigned long *out);
/*