]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: convert object info flags into an enum
authorPatrick Steinhardt <ps@pks.im>
Thu, 12 Feb 2026 06:59:40 +0000 (07:59 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Feb 2026 19:05:08 +0000 (11:05 -0800)
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>
object-file.c
object-file.h
odb.c
odb.h
packfile.c
packfile.h

index e7e4c3348f9c1bb2bc909d13a41e1eb38a946743..0ab6c4d4f36d4bec232825abfd73ba308cd09f12 100644 (file)
@@ -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;
index 1229d5f675b44aa002cb49d9cdafe6842405cf2c..cdb54b52183fb6a0f2708d6ad0d5bd58c0884c5a 100644 (file)
@@ -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 ac70b6a099f5882862f55e0650f7f502a65cc1aa..d437aa8b0614488f8f9e91ec770fd240601f1454 100644 (file)
--- 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 8e1fca775512436c2744701ea10d76a38825b868..e94cdc3665da4759c57578f0b4e6312b6c785c20 100644 (file)
--- 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
index 402c3b5dc731318a8faed0dae320172958191558..cb418846aef49a588ff08f0f1ed05b05388783c6 100644 (file)
@@ -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;
index acc5c55ad57754eef058317a3a4254399d742f28..989fd10cb64eb8b917a81fcb49aed7ff7b147591 100644 (file)
@@ -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