]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: split `struct odb_transaction` into separate header
authorJustin Tobler <jltobler@gmail.com>
Thu, 14 May 2026 18:37:34 +0000 (13:37 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 May 2026 19:44:39 +0000 (04:44 +0900)
The current ODB transaction interface is colocated with other ODB
interfaces in "odb.{c,h}". Subsequent commits will expand `struct
odb_transaction` to support write operations on the transaction
directly. To keep things organized and prevent "odb.{c,h}" from becoming
more unwieldy, split out `struct odb_transaction` into a separate
header.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
12 files changed:
Makefile
builtin/add.c
builtin/unpack-objects.c
builtin/update-index.c
cache-tree.c
meson.build
object-file.c
odb.c
odb.h
odb/transaction.c [new file with mode: 0644]
odb/transaction.h [new file with mode: 0644]
read-cache.c

index dbf00220541ce15c23d63d4092ee1a49200ffb06..6342db13e53232561888bf85b24d422af7dcf9ae 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1219,6 +1219,7 @@ LIB_OBJS += odb.o
 LIB_OBJS += odb/source.o
 LIB_OBJS += odb/source-files.o
 LIB_OBJS += odb/streaming.o
+LIB_OBJS += odb/transaction.o
 LIB_OBJS += oid-array.o
 LIB_OBJS += oidmap.o
 LIB_OBJS += oidset.o
index 7737ab878bfceb926cd762eba745053c25bbe2c4..c859f665199efa91897472e6eab7e8d7ae983fc6 100644 (file)
@@ -16,6 +16,7 @@
 #include "run-command.h"
 #include "object-file.h"
 #include "odb.h"
+#include "odb/transaction.h"
 #include "parse-options.h"
 #include "path.h"
 #include "preload-index.h"
index 6fc64e9e4b8d5af9586a445198eb244afb870911..bc9b1e047e2e4ecdbb0f626e4f53d057d794d473 100644 (file)
@@ -9,6 +9,7 @@
 #include "hex.h"
 #include "object-file.h"
 #include "odb.h"
+#include "odb/transaction.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
index 8a5907767bf297eefcb0c6de5441cabd567536fd..bcc43852ef47aa7116112d236b658cb569ae24fe 100644 (file)
@@ -19,6 +19,7 @@
 #include "tree-walk.h"
 #include "object-file.h"
 #include "odb.h"
+#include "odb/transaction.h"
 #include "refs.h"
 #include "resolve-undo.h"
 #include "parse-options.h"
index 60bcc07c3b83579688c01e35c7b35b42902d597e..f056869cfdbcf1e67d0a79f6e04d9bee473b2c3b 100644 (file)
@@ -10,6 +10,7 @@
 #include "cache-tree.h"
 #include "object-file.h"
 #include "odb.h"
+#include "odb/transaction.h"
 #include "read-cache-ll.h"
 #include "replace-object.h"
 #include "repository.h"
index 8309942d184847ea6434bae30e81dbbbf175192d..6dc23b3af2f387bf3a559a7a9002ae6f259ec580 100644 (file)
@@ -405,6 +405,7 @@ libgit_sources = [
   'odb/source.c',
   'odb/source-files.c',
   'odb/streaming.c',
+  'odb/transaction.c',
   'oid-array.c',
   'oidmap.c',
   'oidset.c',
index f0b029ff0b2cb0b085de1578af6739a00304ba50..bfbb632cf8b971c3e5c761de8b5f15f03d4e544f 100644 (file)
@@ -21,6 +21,7 @@
 #include "object-file.h"
 #include "odb.h"
 #include "odb/streaming.h"
+#include "odb/transaction.h"
 #include "oidtree.h"
 #include "pack.h"
 #include "packfile.h"
diff --git a/odb.c b/odb.c
index 350e23f3c0798d35bbb1f378b23d45ca6bcfa2bc..8c3cbc1b53e11de7be2cf65db1a4509648c47334 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -1069,28 +1069,3 @@ void odb_reprepare(struct object_database *o)
 
        obj_read_unlock();
 }
-
-struct odb_transaction *odb_transaction_begin(struct object_database *odb)
-{
-       if (odb->transaction)
-               return NULL;
-
-       odb->transaction = odb_transaction_files_begin(odb->sources);
-
-       return odb->transaction;
-}
-
-void odb_transaction_commit(struct odb_transaction *transaction)
-{
-       if (!transaction)
-               return;
-
-       /*
-        * Ensure the transaction ending matches the pending transaction.
-        */
-       ASSERT(transaction == transaction->source->odb->transaction);
-
-       transaction->commit(transaction);
-       transaction->source->odb->transaction = NULL;
-       free(transaction);
-}
diff --git a/odb.h b/odb.h
index 9aee260105ae5473ecc955b6f2d7102685bed190..ec5367b13ed8bc2b4e3654535bb096afdc75a433 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -35,24 +35,6 @@ struct packed_git;
 struct packfile_store;
 struct cached_object_entry;
 
-/*
- * A transaction may be started for an object database prior to writing new
- * objects via odb_transaction_begin(). These objects are not committed until
- * odb_transaction_commit() is invoked. Only a single transaction may be pending
- * at a time.
- *
- * Each ODB source is expected to implement its own transaction handling.
- */
-struct odb_transaction;
-typedef void (*odb_transaction_commit_fn)(struct odb_transaction *transaction);
-struct odb_transaction {
-       /* The ODB source the transaction is opened against. */
-       struct odb_source *source;
-
-       /* The ODB source specific callback invoked to commit a transaction. */
-       odb_transaction_commit_fn commit;
-};
-
 /*
  * The object database encapsulates access to objects in a repository. It
  * manages one or more sources that store the actual objects which are
@@ -154,19 +136,6 @@ void odb_close(struct object_database *o);
  */
 void odb_reprepare(struct object_database *o);
 
-/*
- * Starts an ODB transaction. Subsequent objects are written to the transaction
- * and not committed until odb_transaction_commit() is invoked on the
- * transaction. If the ODB already has a pending transaction, NULL is returned.
- */
-struct odb_transaction *odb_transaction_begin(struct object_database *odb);
-
-/*
- * Commits an ODB transaction making the written objects visible. If the
- * specified transaction is NULL, the function is a no-op.
- */
-void odb_transaction_commit(struct odb_transaction *transaction);
-
 /*
  * Find source by its object directory path. Returns a `NULL` pointer in case
  * the source could not be found.
diff --git a/odb/transaction.c b/odb/transaction.c
new file mode 100644 (file)
index 0000000..9bf3f34
--- /dev/null
@@ -0,0 +1,28 @@
+#include "git-compat-util.h"
+#include "object-file.h"
+#include "odb/transaction.h"
+
+struct odb_transaction *odb_transaction_begin(struct object_database *odb)
+{
+       if (odb->transaction)
+               return NULL;
+
+       odb->transaction = odb_transaction_files_begin(odb->sources);
+
+       return odb->transaction;
+}
+
+void odb_transaction_commit(struct odb_transaction *transaction)
+{
+       if (!transaction)
+               return;
+
+       /*
+        * Ensure the transaction ending matches the pending transaction.
+        */
+       ASSERT(transaction == transaction->source->odb->transaction);
+
+       transaction->commit(transaction);
+       transaction->source->odb->transaction = NULL;
+       free(transaction);
+}
diff --git a/odb/transaction.h b/odb/transaction.h
new file mode 100644 (file)
index 0000000..a56e392
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef ODB_TRANSACTION_H
+#define ODB_TRANSACTION_H
+
+#include "odb.h"
+#include "odb/source.h"
+
+/*
+ * A transaction may be started for an object database prior to writing new
+ * objects via odb_transaction_begin(). These objects are not committed until
+ * odb_transaction_commit() is invoked. Only a single transaction may be pending
+ * at a time.
+ *
+ * Each ODB source is expected to implement its own transaction handling.
+ */
+struct odb_transaction;
+typedef void (*odb_transaction_commit_fn)(struct odb_transaction *transaction);
+struct odb_transaction {
+       /* The ODB source the transaction is opened against. */
+       struct odb_source *source;
+
+       /* The ODB source specific callback invoked to commit a transaction. */
+       odb_transaction_commit_fn commit;
+};
+
+/*
+ * Starts an ODB transaction. Subsequent objects are written to the transaction
+ * and not committed until odb_transaction_commit() is invoked on the
+ * transaction. If the ODB already has a pending transaction, NULL is returned.
+ */
+struct odb_transaction *odb_transaction_begin(struct object_database *odb);
+
+/*
+ * Commits an ODB transaction making the written objects visible. If the
+ * specified transaction is NULL, the function is a no-op.
+ */
+void odb_transaction_commit(struct odb_transaction *transaction);
+
+#endif
index 5049f9baca9c5ec5e6f7c87319fb95ea3daea3f8..8147c7e94a8b8e448119ca90f7758004ae3e54ce 100644 (file)
@@ -20,6 +20,7 @@
 #include "dir.h"
 #include "object-file.h"
 #include "odb.h"
+#include "odb/transaction.h"
 #include "oid-array.h"
 #include "tree.h"
 #include "commit.h"