33
44#include "hashmap.h"
55#include "object.h"
6- #include "odb/source.h"
76#include "oidset.h"
87#include "oidmap.h"
98#include "string-list.h"
1211struct oidmap ;
1312struct oidtree ;
1413struct strbuf ;
14+ struct strvec ;
1515struct repository ;
1616struct multi_pack_index ;
1717
@@ -110,10 +110,11 @@ struct object_database {
110110 /*
111111 * A fast, rough count of the number of objects in the repository.
112112 * These two fields are not meant for direct access. Use
113- * repo_approximate_object_count () instead.
113+ * odb_count_objects () instead.
114114 */
115- unsigned long approximate_object_count ;
116- unsigned approximate_object_count_valid : 1 ;
115+ unsigned long object_count ;
116+ unsigned object_count_flags ;
117+ unsigned object_count_valid : 1 ;
117118
118119 /*
119120 * Submodule source paths that will be added as additional sources to
@@ -339,6 +340,42 @@ struct object_info {
339340 */
340341#define OBJECT_INFO_INIT { 0 }
341342
343+ /* Flags that can be passed to `odb_read_object_info_extended()`. */
344+ enum object_info_flags {
345+ /* Invoke lookup_replace_object() on the given hash. */
346+ OBJECT_INFO_LOOKUP_REPLACE = (1 << 0 ),
347+
348+ /* Do not reprepare object sources when the first lookup has failed. */
349+ OBJECT_INFO_QUICK = (1 << 1 ),
350+
351+ /*
352+ * Do not attempt to fetch the object if missing (even if fetch_is_missing is
353+ * nonzero).
354+ */
355+ OBJECT_INFO_SKIP_FETCH_OBJECT = (1 << 2 ),
356+
357+ /* Die if object corruption (not just an object being missing) was detected. */
358+ OBJECT_INFO_DIE_IF_CORRUPT = (1 << 3 ),
359+
360+ /*
361+ * We have already tried reading the object, but it couldn't be found
362+ * via any of the attached sources, and are now doing a second read.
363+ * This second read asks the individual sources to also evaluate
364+ * whether any on-disk state may have changed that may have caused the
365+ * object to appear.
366+ *
367+ * This flag is for internal use, only. The second read only occurs
368+ * when `OBJECT_INFO_QUICK` was not passed.
369+ */
370+ OBJECT_INFO_SECOND_READ = (1 << 4 ),
371+
372+ /*
373+ * This is meant for bulk prefetching of missing blobs in a partial
374+ * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK.
375+ */
376+ OBJECT_INFO_FOR_PREFETCH = (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK ),
377+ };
378+
342379/*
343380 * Read object info from the object database and populate the `object_info`
344381 * structure. Returns 0 on success, a negative error code otherwise.
@@ -432,6 +469,18 @@ enum odb_for_each_object_flags {
432469 ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1 <<4 ),
433470};
434471
472+ /*
473+ * A callback function that can be used to iterate through objects. If given,
474+ * the optional `oi` parameter will be populated the same as if you would call
475+ * `odb_read_object_info()`.
476+ *
477+ * Returning a non-zero error code will cause iteration to abort. The error
478+ * code will be propagated.
479+ */
480+ typedef int (* odb_for_each_object_cb )(const struct object_id * oid ,
481+ struct object_info * oi ,
482+ void * cb_data );
483+
435484/*
436485 * Iterate through all objects contained in the object database. Note that
437486 * objects may be iterated over multiple times in case they are either stored
@@ -452,6 +501,27 @@ int odb_for_each_object(struct object_database *odb,
452501 void * cb_data ,
453502 unsigned flags );
454503
504+ enum odb_count_objects_flags {
505+ /*
506+ * Instead of providing an accurate count, allow the number of objects
507+ * to be approximated. Details of how this approximation works are
508+ * subject to the specific source's implementation.
509+ */
510+ ODB_COUNT_OBJECTS_APPROXIMATE = (1 << 0 ),
511+ };
512+
513+ /*
514+ * Count the number of objects in the given object database. This object count
515+ * may double-count objects that are stored in multiple backends, or which are
516+ * stored multiple times in a single backend.
517+ *
518+ * Returns 0 on success, a negative error code otherwise. The number of objects
519+ * will be assigned to the `out` pointer on success.
520+ */
521+ int odb_count_objects (struct object_database * odb ,
522+ enum odb_count_objects_flags flags ,
523+ unsigned long * out );
524+
455525enum {
456526 /*
457527 * By default, `odb_write_object()` does not actually write anything
0 commit comments