repo: Factor out _ostree_repo_auto_transaction_new()
authorSimon McVittie <smcv@collabora.com>
Sat, 30 Apr 2022 11:20:11 +0000 (12:20 +0100)
committerSimon McVittie <smcv@collabora.com>
Sat, 30 Apr 2022 11:20:11 +0000 (12:20 +0100)
This will allow the direct allocation in
ostree_repo_prepare_transaction() to be replaced with a call to this
function, avoiding breaking encapsulation.

Signed-off-by: Simon McVittie <smcv@collabora.com>
src/libostree/ostree-repo-private.h
src/libostree/ostree-repo.c

index 988c2179af3927447b95f34dae16d7d5cdb8b380..96253e777816162a67a0eed65fec542acfdd4348 100644 (file)
@@ -554,4 +554,8 @@ GType _ostree_repo_auto_transaction_get_type (void);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoAutoTransaction, _ostree_repo_auto_transaction_unref);
 
+/* Internal function to break a circular dependency:
+ * should not be made into public API, even if the rest is */
+OstreeRepoAutoTransaction *_ostree_repo_auto_transaction_new (OstreeRepo *repo);
+
 G_END_DECLS
index 54438b78de6d1ce8effb3b3cd9b71f16af13f7de..ad071c1703e039ea1b80266a17c265165a79b748 100644 (file)
@@ -710,6 +710,32 @@ ostree_repo_auto_lock_cleanup (OstreeRepoAutoLock *auto_lock)
     }
 }
 
+/**
+ * _ostree_repo_auto_transaction_new:
+ * @repo: (not nullable): an #OsreeRepo object
+ * @cancellable: Cancellable
+ * @error: a #GError
+ *
+ * Return a guard for a transaction in @repo.
+ *
+ * Do not call this function outside the OstreeRepo transaction implementation.
+ * Use _ostree_repo_auto_transaction_start() instead.
+ *
+ * Returns: (transfer full): an #OstreeRepoAutoTransaction guard on success,
+ * %NULL otherwise.
+ */
+OstreeRepoAutoTransaction *
+_ostree_repo_auto_transaction_new (OstreeRepo *repo)
+{
+  g_assert (repo != NULL);
+
+  OstreeRepoAutoTransaction *txn = g_malloc(sizeof(OstreeRepoAutoTransaction));
+  txn->atomic_refcount = 1;
+  txn->repo = g_object_ref (repo);
+
+  return g_steal_pointer (&txn);
+}
+
 /**
  * _ostree_repo_auto_transaction_start:
  * @repo: (not nullable): an #OsreeRepo object
@@ -731,11 +757,7 @@ _ostree_repo_auto_transaction_start (OstreeRepo     *repo,
   if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
     return NULL;
 
-  OstreeRepoAutoTransaction *txn = g_malloc(sizeof(OstreeRepoAutoTransaction));
-  txn->atomic_refcount = 1;
-  txn->repo = g_object_ref (repo);
-
-  return g_steal_pointer (&txn);
+  return _ostree_repo_auto_transaction_new (repo);
 }
 
 /**