prune: Retain the tip of each ref even with date pruning

I hit an error with [CAHC](https://wiki.centos.org/SpecialInterestGroup/Atomic/Devel)
where we were doing time-based pruning.  `ostree summary -u` started failing,
and it took me a bit to realize it was because we were pruning
even the tip of old branches, which I was not at all expecting,
and I don't think users will too.

Perhaps in the future we could add some sort of --prune-ref-tips or
something if people wanted it, but I doubt it.

Closes: #445
Approved by: jlebon
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2016-08-09 15:12:35 +00:00
1 parent 056cc0543f
commit fd9536bb19
2 files changed
+31 -5

No files matched your search

+20
View File
@@ -84,6 +84,8 @@ delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *can
static gboolean
prune_commits_keep_younger_than_date (OstreeRepo *repo, const char *date, GCancellable *cancellable, GError **error)
{
g_autoptr(GHashTable) refs = NULL;
g_autoptr(GHashTable) ref_heads = g_hash_table_new (g_str_hash, g_str_equal);
g_autoptr(GHashTable) objects = NULL;
GHashTableIter hash_iter;
gpointer key, value;
@@ -100,6 +102,21 @@ prune_commits_keep_younger_than_date (OstreeRepo *repo, const char *date, GCance
if (!ot_enable_tombstone_commits (repo, error))
goto out;
if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error))
goto out;
/* We used to prune the HEAD of a given ref by default, but that's
* broken for a few reasons. One is that people may use branches as
* tags. Second is that if we do it, we should be deleting the ref
* too, otherwise e.g. `summary -u` breaks trying to load it, etc.
*/
g_hash_table_iter_init (&hash_iter, refs);
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{
/* Value is lifecycle bound to refs */
g_hash_table_add (ref_heads, (char*)value);
}
if (!ostree_repo_list_objects (repo, OSTREE_REPO_LIST_OBJECTS_ALL, &objects,
cancellable, error))
goto out;
@@ -119,6 +136,9 @@ prune_commits_keep_younger_than_date (OstreeRepo *repo, const char *date, GCance
if (objtype != OSTREE_OBJECT_TYPE_COMMIT)
continue;
if (g_hash_table_contains (ref_heads, checksum))
continue;
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum,
&commit, error))
goto out;