diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 398f6abd..c3bc8368 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -368,8 +368,6 @@ write_object (OstreeRepo *self, gsize unpacked_size = 0; gboolean indexable = FALSE; - g_return_val_if_fail (self->in_transaction, FALSE); - if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; @@ -930,6 +928,31 @@ ostree_repo_transaction_set_ref (OstreeRepo *self, g_hash_table_replace (self->txn_refs, refspec, g_strdup (checksum)); } +/** + * ostree_repo_set_ref_immediate: + * @self: An #OstreeRepo + * @remote: (allow-none): A remote for the ref + * @ref: The ref to write + * @checksum: The checksum to point it to + * @cancellable: GCancellable + * @error: GError + * + * This is like ostree_repo_transaction_set_ref(), except it may be + * invoked outside of a transaction. This is presently safe for the + * case where we're creating or overwriting an existing ref. + */ +gboolean +ostree_repo_set_ref_immediate (OstreeRepo *self, + const char *remote, + const char *ref, + const char *checksum, + GCancellable *cancellable, + GError **error) +{ + return _ostree_repo_write_ref (self, remote, ref, checksum, + cancellable, error); +} + /** * ostree_repo_commit_transaction: * @self: An #OstreeRepo diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index b12e116a..379460ab 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -122,6 +122,14 @@ _ostree_repo_update_refs (OstreeRepo *self, GCancellable *cancellable, GError **error); +gboolean +_ostree_repo_write_ref (OstreeRepo *self, + const char *remote, + const char *ref, + const char *rev, + GCancellable *cancellable, + GError **error); + OstreeRepoFile * _ostree_repo_file_new_for_commit (OstreeRepo *repo, const char *commit, diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c index ba3bedb7..64ae96f7 100644 --- a/src/libostree/ostree-repo-refs.c +++ b/src/libostree/ostree-repo-refs.c @@ -570,21 +570,17 @@ ostree_repo_list_refs (OstreeRepo *self, return ret; } -static gboolean -write_refspec (OstreeRepo *self, - const char *refspec, - const char *rev, - GCancellable *cancellable, - GError **error) +gboolean +_ostree_repo_write_ref (OstreeRepo *self, + const char *remote, + const char *ref, + const char *rev, + GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; - gs_free char *remote = NULL; - gs_free char *name = NULL; gs_unref_object GFile *dir = NULL; - if (!ostree_parse_refspec (refspec, &remote, &name, error)) - goto out; - if (remote == NULL) dir = g_object_ref (self->local_heads_dir); else @@ -600,7 +596,7 @@ write_refspec (OstreeRepo *self, if (rev == NULL) { - gs_unref_object GFile *child = g_file_resolve_relative_path (dir, name); + gs_unref_object GFile *child = g_file_resolve_relative_path (dir, ref); if (g_file_query_exists (child, cancellable)) { @@ -610,7 +606,7 @@ write_refspec (OstreeRepo *self, } else { - if (!write_checksum_file (dir, name, rev, cancellable, error)) + if (!write_checksum_file (dir, ref, rev, cancellable, error)) goto out; } @@ -634,8 +630,14 @@ _ostree_repo_update_refs (OstreeRepo *self, { const char *refspec = key; const char *rev = value; + gs_free char *remote = NULL; + gs_free char *ref = NULL; - if (!write_refspec (self, refspec, rev, cancellable, error)) + if (!ostree_parse_refspec (refspec, &remote, &ref, error)) + goto out; + + if (!_ostree_repo_write_ref (self, remote, ref, rev, + cancellable, error)) goto out; } diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 0ff114b3..562e6c18 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -133,6 +133,13 @@ void ostree_repo_transaction_set_ref (OstreeRepo *self, const char *ref, const char *checksum); +gboolean ostree_repo_set_ref_immediate (OstreeRepo *self, + const char *remote, + const char *ref, + const char *checksum, + GCancellable *cancellable, + GError **error); + gboolean ostree_repo_has_object (OstreeRepo *self, OstreeObjectType objtype, const char *checksum, diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c index 3fbe571f..9c291fba 100644 --- a/src/ostree/ot-builtin-refs.c +++ b/src/ostree/ot-builtin-refs.c @@ -67,18 +67,20 @@ ostree_builtin_refs (int argc, char **argv, OstreeRepo *repo, GCancellable *canc } else { - if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error)) - goto out; - g_hash_table_iter_init (&hashiter, refs); while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue)) { const char *refspec = hashkey; - ostree_repo_transaction_set_refspec (repo, refspec, NULL); - } + gs_free char *remote = NULL; + gs_free char *ref = NULL; - if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error)) - goto out; + if (!ostree_parse_refspec (refspec, &remote, &ref, error)) + goto out; + + if (!ostree_repo_set_ref_immediate (repo, remote, ref, NULL, + cancellable, error)) + goto out; + } } ret = TRUE;