diff --git a/man/ostree.repo-config.xml b/man/ostree.repo-config.xml index 0d39f41e..6149248f 100644 --- a/man/ostree.repo-config.xml +++ b/man/ostree.repo-config.xml @@ -93,6 +93,16 @@ Boston, MA 02111-1307, USA. to false. + + change-update-summary + Boolean value controlling whether or not to + automatically update the summary file after any ref is added, + removed, or updated. This covers a superset of the cases covered by + commit-update-summary, with the exception of orphan commits which + shouldn't affect the summary anyway. Defaults to false. + + + fsync Boolean value controlling whether or not to diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 632e396c..12ee6888 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -2202,6 +2202,12 @@ ostree_repo_commit_transaction (OstreeRepo *self, return FALSE; g_clear_pointer (&self->txn.collection_refs, g_hash_table_destroy); + /* Update the summary if change-update-summary is set, because doing so was + * delayed for each ref change during the transaction. + */ + if (!_ostree_repo_maybe_regenerate_summary (self, cancellable, error)) + return FALSE; + self->in_transaction = FALSE; if (!ot_ensure_unlinked_at (self->repo_dir_fd, "transaction", 0)) diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index 0a447634..4e504326 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -437,6 +437,11 @@ _ostree_repo_get_remote_inherited (OstreeRepo *self, const char *name, GError **error); +gboolean +_ostree_repo_maybe_regenerate_summary (OstreeRepo *self, + GCancellable *cancellable, + GError **error); + /* Locking APIs are currently private. * See https://github.com/ostreedev/ostree/pull/1555 */ diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c index 2600cb7c..83d11c1b 100644 --- a/src/libostree/ostree-repo-refs.c +++ b/src/libostree/ostree-repo-refs.c @@ -1144,6 +1144,11 @@ _ostree_repo_write_ref (OstreeRepo *self, if (!_ostree_repo_update_mtime (self, error)) return FALSE; + /* Update the summary after updating the mtime so the summary doesn't look + * out of date */ + if (!self->in_transaction && !_ostree_repo_maybe_regenerate_summary (self, cancellable, error)) + return FALSE; + return TRUE; } diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 7acd0940..10f87dba 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -5386,7 +5386,8 @@ summary_add_ref_entry (OstreeRepo *self, * will aid clients in working out when to check for updates. * * It is regenerated automatically after a commit if - * `core/commit-update-summary` is set. + * `core/commit-update-summary` is set, and automatically after any ref is + * added, removed, or updated if `core/change-update-summary` is set. * * If the `core/collection-id` key is set in the configuration, it will be * included as %OSTREE_SUMMARY_COLLECTION_ID in the summary file. Refs that @@ -5592,6 +5593,28 @@ ostree_repo_regenerate_summary (OstreeRepo *self, return TRUE; } +/* Regenerate the summary if `core/change-update-summary` is set */ +gboolean +_ostree_repo_maybe_regenerate_summary (OstreeRepo *self, + GCancellable *cancellable, + GError **error) +{ + gboolean update_summary; + + if (!ot_keyfile_get_boolean_with_default (self->config, "core", + "change-update-summary", FALSE, + &update_summary, error)) + return FALSE; + + if (update_summary && !ostree_repo_regenerate_summary (self, + NULL, + cancellable, + error)) + return FALSE; + + return TRUE; +} + gboolean _ostree_repo_is_locked_tmpdir (const char *filename) { diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index c2f78700..ded6522f 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -752,8 +752,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (!skip_commit) { - gboolean update_summary; guint64 timestamp; + gboolean change_update_summary; if (!opt_no_bindings) { @@ -824,21 +824,32 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error)) goto out; - /* The default for this option is FALSE, even for archive repos, - * because ostree supports multiple processes committing to the same - * repo (but different refs) concurrently, and in fact gnome-continuous - * actually does this. In that context it's best to update the summary - * explicitly instead of automatically here. */ if (!ot_keyfile_get_boolean_with_default (ostree_repo_get_config (repo), "core", - "commit-update-summary", FALSE, - &update_summary, error)) + "change-update-summary", FALSE, + &change_update_summary, error)) goto out; - if (update_summary && !ostree_repo_regenerate_summary (repo, - NULL, - cancellable, - error)) - goto out; + /* No need to update it again if we did for each ref change */ + if (opt_orphan || !change_update_summary) + { + gboolean commit_update_summary; + + /* The default for this option is FALSE, even for archive repos, + * because ostree supports multiple processes committing to the same + * repo (but different refs) concurrently, and in fact gnome-continuous + * actually does this. In that context it's best to update the summary + * explicitly instead of automatically here. */ + if (!ot_keyfile_get_boolean_with_default (ostree_repo_get_config (repo), "core", + "commit-update-summary", FALSE, + &commit_update_summary, error)) + goto out; + + if (commit_update_summary && !ostree_repo_regenerate_summary (repo, + NULL, + cancellable, + error)) + goto out; + } } else { diff --git a/tests/test-auto-summary.sh b/tests/test-auto-summary.sh index b12f1593..5811fcde 100755 --- a/tests/test-auto-summary.sh +++ b/tests/test-auto-summary.sh @@ -29,6 +29,7 @@ echo "1..4" setup_test_repository "bare" echo "ok setup" +# Check that without commit-update-summary set, creating a commit doesn't update the summary mkdir test echo hello > test/a @@ -47,6 +48,7 @@ echo "ok commit 2" assert_streq "$OLD_MD5" "$(md5sum repo/summary)" +# Check that with commit-update-summary set, creating a commit updates the summary $OSTREE --repo=repo config set core.commit-update-summary true echo hello3 > test/a @@ -56,7 +58,46 @@ echo "ok commit 3" assert_not_streq "$OLD_MD5" "$(md5sum repo/summary)" +$OSTREE --repo=repo config set core.commit-update-summary false + # Check that summary --update deletes the .sig file touch repo/summary.sig $OSTREE summary --update assert_not_has_file repo/summary.sig + +# Check that without change-update-summary set, adding, changing, or deleting a ref doesn't update the summary +$OSTREE summary --update +OLD_MD5=$(md5sum repo/summary) +$OSTREE commit -b test2 -s "A commit" test + +assert_streq "$OLD_MD5" "$(md5sum repo/summary)" + +$OSTREE reset test test^ + +assert_streq "$OLD_MD5" "$(md5sum repo/summary)" + +$OSTREE refs --delete test + +assert_streq "$OLD_MD5" "$(md5sum repo/summary)" + +# Check that with change-update-summary set, adding, changing, or deleting a ref updates the summary +$OSTREE --repo=repo config set core.change-update-summary true + +$OSTREE summary --update +OLD_MD5=$(md5sum repo/summary) +echo hello > test/a +$OSTREE commit -b test -s "A commit" test +echo hello2 > test/a +$OSTREE commit -b test -s "Another commit" test + +assert_not_streq "$OLD_MD5" "$(md5sum repo/summary)" + +OLD_MD5=$(md5sum repo/summary) +$OSTREE reset test test^ + +assert_not_streq "$OLD_MD5" "$(md5sum repo/summary)" + +OLD_MD5=$(md5sum repo/summary) +$OSTREE refs --delete test + +assert_not_streq "$OLD_MD5" "$(md5sum repo/summary)"