repo: Add auto_transaction and TransactionGuard

This gives auto-cancelling semantics on `Drop`, plus a nicer
`.commit()` method on the transaction.

Matches the currently private `_OstreeRepoAutoTransaction` in the C
library.
This commit is contained in:
Colin Walters committed 2022-05-06 12:53:57 -04:00
1 parent 69950574f7
commit f8852ca945
2 files changed
+43 -4

No files matched your search

+3 -3
View File
@@ -42,7 +42,8 @@ pub fn create_mtree(repo: &ostree::Repo) -> ostree::MutableTree {
}
pub fn commit(repo: &ostree::Repo, mtree: &ostree::MutableTree, ref_: &str) -> GString {
repo.prepare_transaction(NONE_CANCELLABLE)
let txn = repo
.auto_transaction(NONE_CANCELLABLE)
.expect("prepare transaction");
let repo_file = repo
.write_mtree(mtree, NONE_CANCELLABLE)
@@ -60,8 +61,7 @@ pub fn commit(repo: &ostree::Repo, mtree: &ostree::MutableTree, ref_: &str) -> G
)
.expect("write commit");
repo.transaction_set_ref(None, ref_, checksum.as_str().into());
repo.commit_transaction(NONE_CANCELLABLE)
.expect("commit transaction");
txn.commit(NONE_CANCELLABLE).expect("commit transaction");
checksum
}