odb: convert object info flags into an enum

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 12, 2026 at 07:59 UTC f6516a5241684355f3fb9f7b70e287e98b48d0ef
6 files changed +30 -22
object-file.c
+2 -1
@@ -414,7 +414,8 @@ static int parse_loose_header(const char *hdr, struct object_info *oi)
414
415 int odb_source_loose_read_object_info(struct odb_source *source,
416 const struct object_id *oid,
417 - struct object_info *oi, int flags)
417 + struct object_info *oi,
418 + enum object_info_flags flags)
419 {
420 int ret;
421 int fd;
object-file.h
+2 -1
@@ -47,7 +47,8 @@ void odb_source_loose_reprepare(struct odb_source *source);
47
48 int odb_source_loose_read_object_info(struct odb_source *source,
49 const struct object_id *oid,
50 - struct object_info *oi, int flags);
50 + struct object_info *oi,
51 + enum object_info_flags flags);
52
53 int odb_source_loose_read_object_stream(struct odb_read_stream **out,
54 struct odb_source *source,
odb.c
+1 -1
@@ -842,7 +842,7 @@ static int oid_object_info_convert(struct repository *r,
842 int odb_read_object_info_extended(struct object_database *odb,
843 const struct object_id *oid,
844 struct object_info *oi,
845 - unsigned flags)
845 + enum object_info_flags flags)
846 {
847 int ret;
848
odb.h
+23 -17
@@ -352,23 +352,29 @@ struct object_info {
352 */
353 #define OBJECT_INFO_INIT { 0 }
354
355 -/* Invoke lookup_replace_object() on the given hash */
356 -#define OBJECT_INFO_LOOKUP_REPLACE (1 << 0)
357 -/* Do not retry packed storage after checking packed and loose storage */
358 -#define OBJECT_INFO_QUICK (1 << 1)
359 -/*
360 - * Do not attempt to fetch the object if missing (even if fetch_is_missing is
361 - * nonzero).
362 - */
363 -#define OBJECT_INFO_SKIP_FETCH_OBJECT (1 << 2)
364 -/*
365 - * This is meant for bulk prefetching of missing blobs in a partial
366 - * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
367 - */
368 -#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)
355 +/* Flags that can be passed to `odb_read_object_info_extended()`. */
356 +enum object_info_flags {
357 + /* Invoke lookup_replace_object() on the given hash. */
358 + OBJECT_INFO_LOOKUP_REPLACE = (1 << 0),
359 +
360 + /* Do not reprepare object sources when the first lookup has failed. */
361 + OBJECT_INFO_QUICK = (1 << 1),
362 +
363 + /*
364 + * Do not attempt to fetch the object if missing (even if fetch_is_missing is
365 + * nonzero).
366 + */
367 + OBJECT_INFO_SKIP_FETCH_OBJECT = (1 << 2),
368 +
369 + /* Die if object corruption (not just an object being missing) was detected. */
370 + OBJECT_INFO_DIE_IF_CORRUPT = (1 << 3),
371
370 -/* Die if object corruption (not just an object being missing) was detected. */
371 -#define OBJECT_INFO_DIE_IF_CORRUPT (1 << 3)
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
379 /*
380 * Read object info from the object database and populate the `object_info`
@@ -377,7 +383,7 @@ struct object_info {
383 int odb_read_object_info_extended(struct object_database *odb,
384 const struct object_id *oid,
385 struct object_info *oi,
380 - unsigned flags);
386 + enum object_info_flags flags);
387
388 /*
389 * Read a subset of object info for the given object ID. Returns an `enum
packfile.c
+1 -1
@@ -2149,7 +2149,7 @@ int packfile_store_freshen_object(struct packfile_store *store,
2149 int packfile_store_read_object_info(struct packfile_store *store,
2150 const struct object_id *oid,
2151 struct object_info *oi,
2152 - unsigned flags UNUSED)
2152 + enum object_info_flags flags UNUSED)
2153 {
2154 struct pack_entry e;
2155 int ret;
packfile.h
+1 -1
@@ -247,7 +247,7 @@ int packfile_store_read_object_stream(struct odb_read_stream **out,
247 int packfile_store_read_object_info(struct packfile_store *store,
248 const struct object_id *oid,
249 struct object_info *oi,
250 - unsigned flags);
250 + enum object_info_flags flags);
251
252 /*
253 * Open the packfile and add it to the store if it isn't yet known. Returns