git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] odb: use enum for `odb_write_object` flags

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 31, 2026, 23:57 UTC
Message-ID
<20260401-pks-odb-cleanups-v1-4-89adba9ada68@pks.im>
In-Reply-To
<20260401-pks-odb-cleanups-v1-0-89adba9ada68@pks.im>

We've got a couple of functions that accept `odb_write_object()` flags, but all of them accept the flags as an `unsigned` integer. In fact, we don't even have an `enum` for the flags field.

Introduce this `enum` and adapt functions accordingly according to our coding style.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 object-file.c      | 3 ++-
 object-file.h      | 3 ++-
 odb.c              | 2 +-
 odb.h              | 4 ++--
 odb/source-files.c | 2 +-
 odb/source.h       | 4 ++--
 6 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/object-file.c b/object-file.c
index db1a420ab6..2146104de8 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1169,7 +1169,8 @@ int odb_source_loose_write_stream(struct odb_source *source,
 int odb_source_loose_write_object(struct odb_source *source,
 				  const void *buf, unsigned long len,
 				  enum object_type type, struct object_id *oid,
-				  struct object_id *compat_oid_in, unsigned flags)
+				  struct object_id *compat_oid_in,
+				  enum odb_write_object_flags flags)
 {
 	const struct git_hash_algo *algo = source->odb->repo->hash_algo;
 	const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
diff --git a/object-file.h b/object-file.h
index 3686f182e4..5241b8dd5c 100644
--- a/object-file.h
+++ b/object-file.h
@@ -68,7 +68,8 @@ int odb_source_loose_freshen_object(struct odb_source *source,
 int odb_source_loose_write_object(struct odb_source *source,
 				  const void *buf, unsigned long len,
 				  enum object_type type, struct object_id *oid,
-				  struct object_id *compat_oid_in, unsigned flags);
+				  struct object_id *compat_oid_in,
+				  enum odb_write_object_flags flags);
 
 int odb_source_loose_write_stream(struct odb_source *source,
 				  struct odb_write_stream *stream, size_t len,
diff --git a/odb.c b/odb.c
index 9a11c60048..8220661356 100644
--- a/odb.c
+++ b/odb.c
@@ -1053,7 +1053,7 @@ int odb_write_object_ext(struct object_database *odb,
 			 enum object_type type,
 			 struct object_id *oid,
 			 struct object_id *compat_oid,
-			 unsigned flags)
+			 enum odb_write_object_flags flags)
 {
 	return odb_source_write_object(odb->sources, buf, len, type,
 				       oid, compat_oid, flags);
diff --git a/odb.h b/odb.h
index 083c25609e..9aadc1177a 100644
--- a/odb.h
+++ b/odb.h
@@ -561,7 +561,7 @@ int odb_find_abbrev_len(struct object_database *odb,
 			int min_len,
 			unsigned *out);
 
-enum {
+enum odb_write_object_flags {
 	/*
 	 * By default, `odb_write_object()` does not actually write anything
 	 * into the object store, but only computes the object ID. This flag
@@ -589,7 +589,7 @@ int odb_write_object_ext(struct object_database *odb,
 			 enum object_type type,
 			 struct object_id *oid,
 			 struct object_id *compat_oid,
-			 unsigned flags);
+			 enum odb_write_object_flags flags);
 
 static inline int odb_write_object(struct object_database *odb,
 				   const void *buf, unsigned long len,
diff --git a/odb/source-files.c b/odb/source-files.c
index 76797569de..b5abd20e97 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -161,7 +161,7 @@ static int odb_source_files_write_object(struct odb_source *source,
 					 enum object_type type,
 					 struct object_id *oid,
 					 struct object_id *compat_oid,
-					 unsigned flags)
+					 enum odb_write_object_flags flags)
 {
 	return odb_source_loose_write_object(source, buf, len, type,
 					     oid, compat_oid, flags);
diff --git a/odb/source.h b/odb/source.h
index a9d7d0b96f..f706e0608a 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -197,7 +197,7 @@ struct odb_source {
 			    enum object_type type,
 			    struct object_id *oid,
 			    struct object_id *compat_oid,
-			    unsigned flags);
+			    enum odb_write_object_flags flags);
 
 	/*
 	 * This callback is expected to persist the given object stream into
@@ -405,7 +405,7 @@ static inline int odb_source_write_object(struct odb_source *source,
 					  enum object_type type,
 					  struct object_id *oid,
 					  struct object_id *compat_oid,
-					  unsigned flags)
+					  enum odb_write_object_flags flags)
 {
 	return source->write_object(source, buf, len, type, oid,
 				    compat_oid, flags);
-- 
2.53.0.1185.g05d4b7b318.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 of 7 in “odb: small set of cleanups”
  1. 0/6 odb: small set of cleanupsPatrick Steinhardt, Mar 31, 2026
  2. 1/6 CodingGuidelines: document our style for flagsPatrick Steinhardt, Mar 31, 2026
  3. 2/6 treewide: use enum for `odb_for_each_object()` flagsPatrick Steinhardt, Mar 31, 2026
  4. 3/6 odb: rename `odb_write_object()` flagsPatrick Steinhardt, Mar 31, 2026
  5. 4/6 odb: use enum for `odb_write_object` flagsPatrick Steinhardt, Mar 31, 2026
  6. 5/6 odb: rename `odb_has_object()` flagsPatrick Steinhardt, Mar 31, 2026
  7. 6/6 odb: drop unneeded headers and forward declsPatrick Steinhardt, Mar 31, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.