object-file: use `container_of()` to convert from base types

To improve code hygiene, replace direct casts from `struct odb_transaction` and `struct odb_read_stream` to their concrete implementations with `container_of()`. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Feb 18, 2026 at 15:01 UTC 20daad2db4d5ff6c108d473ae068785198868d68
1 file changed +16 -7
object-file.c
+16 -7
@@ -719,7 +719,8 @@ struct odb_transaction_files {
719
720 static void prepare_loose_object_transaction(struct odb_transaction *base)
721 {
722 - struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
722 + struct odb_transaction_files *transaction =
723 + container_of(base, struct odb_transaction_files, base);
724
725 /*
726 * We lazily create the temporary object directory
@@ -738,7 +739,8 @@ static void prepare_loose_object_transaction(struct odb_transaction *base)
739 static void fsync_loose_object_transaction(struct odb_transaction *base,
740 int fd, const char *filename)
741 {
741 - struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
742 + struct odb_transaction_files *transaction =
743 + container_of(base, struct odb_transaction_files, base);
744
745 /*
746 * If we have an active ODB transaction, we issue a call that
@@ -1634,11 +1636,14 @@ int index_fd(struct index_state *istate, struct object_id *oid,
1636 type, path, flags);
1637 } else {
1638 struct object_database *odb = the_repository->objects;
1639 + struct odb_transaction_files *files_transaction;
1640 struct odb_transaction *transaction;
1641
1642 transaction = odb_transaction_begin(odb);
1640 - ret = index_blob_packfile_transaction((struct odb_transaction_files *)odb->transaction,
1641 - oid, fd,
1643 + files_transaction = container_of(odb->transaction,
1644 + struct odb_transaction_files,
1645 + base);
1646 + ret = index_blob_packfile_transaction(files_transaction, oid, fd,
1647 xsize_t(st->st_size),
1648 path, flags);
1649 odb_transaction_commit(transaction);
@@ -1992,7 +1997,8 @@ out:
1997
1998 static void odb_transaction_files_commit(struct odb_transaction *base)
1999 {
1995 - struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
2000 + struct odb_transaction_files *transaction =
2001 + container_of(base, struct odb_transaction_files, base);
2002
2003 flush_loose_object_transaction(transaction);
2004 flush_packfile_transaction(transaction);
@@ -2047,7 +2053,8 @@ struct odb_loose_read_stream {
2053
2054 static ssize_t read_istream_loose(struct odb_read_stream *_st, char *buf, size_t sz)
2055 {
2050 - struct odb_loose_read_stream *st = (struct odb_loose_read_stream *)_st;
2056 + struct odb_loose_read_stream *st =
2057 + container_of(_st, struct odb_loose_read_stream, base);
2058 size_t total_read = 0;
2059
2060 switch (st->z_state) {
@@ -2093,7 +2100,9 @@ static ssize_t read_istream_loose(struct odb_read_stream *_st, char *buf, size_t
2100
2101 static int close_istream_loose(struct odb_read_stream *_st)
2102 {
2096 - struct odb_loose_read_stream *st = (struct odb_loose_read_stream *)_st;
2103 + struct odb_loose_read_stream *st =
2104 + container_of(_st, struct odb_loose_read_stream, base);
2105 +
2106 if (st->z_state == ODB_LOOSE_READ_STREAM_INUSE)
2107 git_inflate_end(&st->z);
2108 munmap(st->mapped, st->mapsize);