Skip to content

Commit d429ab4

Browse files
jltoblergitster
authored andcommitted
odb: split struct odb_transaction into separate header
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>
1 parent 270e10a commit d429ab4

File tree

12 files changed

+74
-56
lines changed

12 files changed

+74
-56
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,7 @@ LIB_OBJS += odb.o
12191219
LIB_OBJS += odb/source.o
12201220
LIB_OBJS += odb/source-files.o
12211221
LIB_OBJS += odb/streaming.o
1222+
LIB_OBJS += odb/transaction.o
12221223
LIB_OBJS += oid-array.o
12231224
LIB_OBJS += oidmap.o
12241225
LIB_OBJS += oidset.o

builtin/add.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "run-command.h"
1717
#include "object-file.h"
1818
#include "odb.h"
19+
#include "odb/transaction.h"
1920
#include "parse-options.h"
2021
#include "path.h"
2122
#include "preload-index.h"

builtin/unpack-objects.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "hex.h"
1010
#include "object-file.h"
1111
#include "odb.h"
12+
#include "odb/transaction.h"
1213
#include "object.h"
1314
#include "delta.h"
1415
#include "pack.h"

builtin/update-index.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "tree-walk.h"
2020
#include "object-file.h"
2121
#include "odb.h"
22+
#include "odb/transaction.h"
2223
#include "refs.h"
2324
#include "resolve-undo.h"
2425
#include "parse-options.h"

cache-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "cache-tree.h"
1111
#include "object-file.h"
1212
#include "odb.h"
13+
#include "odb/transaction.h"
1314
#include "read-cache-ll.h"
1415
#include "replace-object.h"
1516
#include "repository.h"

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ libgit_sources = [
405405
'odb/source.c',
406406
'odb/source-files.c',
407407
'odb/streaming.c',
408+
'odb/transaction.c',
408409
'oid-array.c',
409410
'oidmap.c',
410411
'oidset.c',

object-file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "object-file.h"
2222
#include "odb.h"
2323
#include "odb/streaming.h"
24+
#include "odb/transaction.h"
2425
#include "oidtree.h"
2526
#include "pack.h"
2627
#include "packfile.h"

odb.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,28 +1069,3 @@ void odb_reprepare(struct object_database *o)
10691069

10701070
obj_read_unlock();
10711071
}
1072-
1073-
struct odb_transaction *odb_transaction_begin(struct object_database *odb)
1074-
{
1075-
if (odb->transaction)
1076-
return NULL;
1077-
1078-
odb->transaction = odb_transaction_files_begin(odb->sources);
1079-
1080-
return odb->transaction;
1081-
}
1082-
1083-
void odb_transaction_commit(struct odb_transaction *transaction)
1084-
{
1085-
if (!transaction)
1086-
return;
1087-
1088-
/*
1089-
* Ensure the transaction ending matches the pending transaction.
1090-
*/
1091-
ASSERT(transaction == transaction->source->odb->transaction);
1092-
1093-
transaction->commit(transaction);
1094-
transaction->source->odb->transaction = NULL;
1095-
free(transaction);
1096-
}

odb.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,6 @@ struct packed_git;
3535
struct packfile_store;
3636
struct cached_object_entry;
3737

38-
/*
39-
* A transaction may be started for an object database prior to writing new
40-
* objects via odb_transaction_begin(). These objects are not committed until
41-
* odb_transaction_commit() is invoked. Only a single transaction may be pending
42-
* at a time.
43-
*
44-
* Each ODB source is expected to implement its own transaction handling.
45-
*/
46-
struct odb_transaction;
47-
typedef void (*odb_transaction_commit_fn)(struct odb_transaction *transaction);
48-
struct odb_transaction {
49-
/* The ODB source the transaction is opened against. */
50-
struct odb_source *source;
51-
52-
/* The ODB source specific callback invoked to commit a transaction. */
53-
odb_transaction_commit_fn commit;
54-
};
55-
5638
/*
5739
* The object database encapsulates access to objects in a repository. It
5840
* manages one or more sources that store the actual objects which are
@@ -154,19 +136,6 @@ void odb_close(struct object_database *o);
154136
*/
155137
void odb_reprepare(struct object_database *o);
156138

157-
/*
158-
* Starts an ODB transaction. Subsequent objects are written to the transaction
159-
* and not committed until odb_transaction_commit() is invoked on the
160-
* transaction. If the ODB already has a pending transaction, NULL is returned.
161-
*/
162-
struct odb_transaction *odb_transaction_begin(struct object_database *odb);
163-
164-
/*
165-
* Commits an ODB transaction making the written objects visible. If the
166-
* specified transaction is NULL, the function is a no-op.
167-
*/
168-
void odb_transaction_commit(struct odb_transaction *transaction);
169-
170139
/*
171140
* Find source by its object directory path. Returns a `NULL` pointer in case
172141
* the source could not be found.

odb/transaction.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "git-compat-util.h"
2+
#include "object-file.h"
3+
#include "odb/transaction.h"
4+
5+
struct odb_transaction *odb_transaction_begin(struct object_database *odb)
6+
{
7+
if (odb->transaction)
8+
return NULL;
9+
10+
odb->transaction = odb_transaction_files_begin(odb->sources);
11+
12+
return odb->transaction;
13+
}
14+
15+
void odb_transaction_commit(struct odb_transaction *transaction)
16+
{
17+
if (!transaction)
18+
return;
19+
20+
/*
21+
* Ensure the transaction ending matches the pending transaction.
22+
*/
23+
ASSERT(transaction == transaction->source->odb->transaction);
24+
25+
transaction->commit(transaction);
26+
transaction->source->odb->transaction = NULL;
27+
free(transaction);
28+
}

0 commit comments

Comments
 (0)