git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
| 1 | #include "git-compat-util.h" |
| 2 | #include "gettext.h" |
| 3 | #include "odb/source.h" |
| 4 | #include "odb/transaction.h" |
| 5 | |
| 6 | int odb_transaction_begin(struct object_database *odb, |
| 7 | struct odb_transaction **out, |
| 8 | enum odb_transaction_flags flags) |
| 9 | { |
| 10 | int ret; |
| 11 | |
| 12 | if (odb->transaction) |
| 13 | return error(_("object database transaction already pending")); |
| 14 | |
| 15 | ret = odb_source_begin_transaction(odb->source, out, flags); |
| 16 | if (!ret) |
| 17 | odb->transaction = *out; |
| 18 | |
| 19 | return ret; |
| 20 | } |
| 21 | |
| 22 | int odb_transaction_commit(struct odb_transaction *transaction) |
| 23 | { |
| 24 | int ret; |
| 25 | |
| 26 | if (!transaction) |
| 27 | return 0; |
| 28 | |
| 29 | /* |
| 30 | * Ensure the transaction ending matches the pending transaction. |
| 31 | */ |
| 32 | ASSERT(transaction == transaction->source->odb->transaction); |
| 33 | |
| 34 | ret = transaction->commit(transaction); |
| 35 | transaction->source->odb->transaction = NULL; |
| 36 | |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | int odb_transaction_finalize(struct odb_transaction *transaction) |
| 41 | { |
| 42 | int ret = 0; |
| 43 | |
| 44 | if (!transaction) |
| 45 | return 0; |
| 46 | |
| 47 | if (transaction->finalize) |
| 48 | ret = transaction->finalize(transaction); |
| 49 | |
| 50 | free(transaction); |
| 51 | |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | int odb_transaction_write_object_stream(struct odb_transaction *transaction, |
| 56 | struct odb_stream *stream, |
| 57 | struct object_id *oid) |
| 58 | { |
| 59 | return transaction->write_object_stream(transaction, stream, oid); |
| 60 | } |
| 61 | |
| 62 | int odb_transaction_write_pack(struct odb_transaction *transaction, int pack_fd, |
| 63 | struct strbuf *err_msg, |
| 64 | const struct odb_transaction_write_pack_opts *opts) |
| 65 | { |
| 66 | return transaction->write_pack(transaction, pack_fd, err_msg, opts); |
| 67 | } |
| 68 | |
| 69 | int odb_transaction_env(struct odb_transaction *transaction, struct strvec *env) |
| 70 | { |
| 71 | if (!transaction) |
| 72 | return 0; |
| 73 | |
| 74 | return transaction->env(transaction, env); |
| 75 | } |