From b42b0adc6962f48288531cb1370d1ebd88f84afa Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 26 Apr 2022 19:30:01 -0400 Subject: [PATCH] Add a `repo()` accessor to `TransactionGuard` I want to write APIs that *require* the caller to have set up an ostree transaction. It's natural to require passing a guard to do so. But then we want an accessor for the repo. --- src/repo.rs | 6 ++++++ tests/util/mod.rs | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/repo.rs b/src/repo.rs index 35a1524..5d34f98 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -72,6 +72,12 @@ pub struct TransactionGuard<'a> { } impl<'a> TransactionGuard<'a> { + /// Returns a reference to the repository. + pub fn repo(&self) -> &Repo { + // SAFETY: This is only set to None in `commit`, which consumes self + self.repo.unwrap() + } + /// Commit this transaction. pub fn commit>( mut self, diff --git a/tests/util/mod.rs b/tests/util/mod.rs index 472bf45..28cca92 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -67,7 +67,8 @@ pub fn commit(repo: &ostree::Repo, mtree: &ostree::MutableTree, ref_: &str) -> G let txn = repo .auto_transaction(NONE_CANCELLABLE) .expect("prepare transaction"); - let repo_file = repo + let repo_file = txn + .repo() .write_mtree(mtree, NONE_CANCELLABLE) .expect("write mtree") .downcast::()