[PATCH v2 4/5] odb: convert object info flags into an enum
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Feb 12, 2026, 06:59 UTC
- Message-ID
- <20260212-b4-pks-read-object-info-flags-v2-4-3bfa9bb149ef@pks.im>
- In-Reply-To
- <20260212-b4-pks-read-object-info-flags-v2-0-3bfa9bb149ef@pks.im>
Convert the object info flags into an enum and adapt all functions that receive these flags as parameters to use the enum instead of an integer. This serves two purposes:
- The function signatures become more self-documenting, as callers
don't have to wonder which flags they expect.- The compiler can warn when a wrong flag type is passed.
Note that the second benefit is somewhat limited. For example, when or-ing multiple enum flags together the result will be an integer, and the compiler will not warn about such use cases. But where it does help is when a single flag of the wrong type is passed, as the compiler would generate a warning in that case.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- object-file.c | 3 ++- object-file.h | 3 ++- odb.c | 2 +- odb.h | 40 +++++++++++++++++++++++----------------- packfile.c | 2 +- packfile.h | 2 +- 6 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/object-file.c b/object-file.c index e7e4c3348f..0ab6c4d4f3 100644 --- a/object-file.c +++ b/object-file.c @@ -414,7 +414,8 @@ static int parse_loose_header(const char *hdr, struct object_info *oi) int odb_source_loose_read_object_info(struct odb_source *source, const struct object_id *oid, - struct object_info *oi, int flags) + struct object_info *oi, + enum object_info_flags flags) { int ret; int fd; diff --git a/object-file.h b/object-file.h index 1229d5f675..cdb54b5218 100644 --- a/object-file.h +++ b/object-file.h @@ -47,7 +47,8 @@ void odb_source_loose_reprepare(struct odb_source *source); int odb_source_loose_read_object_info(struct odb_source *source, const struct object_id *oid, - struct object_info *oi, int flags); + 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, diff --git a/odb.c b/odb.c index ac70b6a099..d437aa8b06 100644 --- a/odb.c +++ b/odb.c @@ -842,7 +842,7 @@ static int oid_object_info_convert(struct repository *r, int odb_read_object_info_extended(struct object_database *odb, const struct object_id *oid, struct object_info *oi, - unsigned flags) + enum object_info_flags flags) { int ret; diff --git a/odb.h b/odb.h index 8e1fca7755..e94cdc3665 100644 --- a/odb.h +++ b/odb.h @@ -352,23 +352,29 @@ struct object_info { */ #define OBJECT_INFO_INIT { 0 } -/* Invoke lookup_replace_object() on the given hash */ -#define OBJECT_INFO_LOOKUP_REPLACE (1 << 0) -/* Do not retry packed storage after checking packed and loose storage */ -#define OBJECT_INFO_QUICK (1 << 1) -/* - * Do not attempt to fetch the object if missing (even if fetch_is_missing is - * nonzero). - */ -#define OBJECT_INFO_SKIP_FETCH_OBJECT (1 << 2) -/* - * This is meant for bulk prefetching of missing blobs in a partial - * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK - */ -#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK) +/* Flags that can be passed to `odb_read_object_info_extended()`. */ +enum object_info_flags { + /* Invoke lookup_replace_object() on the given hash. */ + OBJECT_INFO_LOOKUP_REPLACE = (1 << 0), + + /* Do not reprepare object sources when the first lookup has failed. */ + OBJECT_INFO_QUICK = (1 << 1), + + /* + * Do not attempt to fetch the object if missing (even if fetch_is_missing is + * nonzero). + */ + OBJECT_INFO_SKIP_FETCH_OBJECT = (1 << 2), + + /* Die if object corruption (not just an object being missing) was detected. */ + OBJECT_INFO_DIE_IF_CORRUPT = (1 << 3), -/* Die if object corruption (not just an object being missing) was detected. */ -#define OBJECT_INFO_DIE_IF_CORRUPT (1 << 3) + /* + * This is meant for bulk prefetching of missing blobs in a partial + * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK. + */ + OBJECT_INFO_FOR_PREFETCH = (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK), +}; /* * Read object info from the object database and populate the `object_info` @@ -377,7 +383,7 @@ struct object_info { int odb_read_object_info_extended(struct object_database *odb, const struct object_id *oid, struct object_info *oi, - unsigned flags); + enum object_info_flags flags); /* * Read a subset of object info for the given object ID. Returns an `enum diff --git a/packfile.c b/packfile.c index 402c3b5dc7..cb418846ae 100644 --- a/packfile.c +++ b/packfile.c @@ -2149,7 +2149,7 @@ int packfile_store_freshen_object(struct packfile_store *store, int packfile_store_read_object_info(struct packfile_store *store, const struct object_id *oid, struct object_info *oi, - unsigned flags UNUSED) + enum object_info_flags flags UNUSED) { struct pack_entry e; int ret; diff --git a/packfile.h b/packfile.h index acc5c55ad5..989fd10cb6 100644 --- a/packfile.h +++ b/packfile.h @@ -247,7 +247,7 @@ int packfile_store_read_object_stream(struct odb_read_stream **out, int packfile_store_read_object_info(struct packfile_store *store, const struct object_id *oid, struct object_info *oi, - unsigned flags); + enum object_info_flags flags); /* * Open the packfile and add it to the store if it isn't yet known. Returns
-- 2.53.0.295.g64333814d3.dirty