Merge pull request #2756 from alexlarsson/delta-ignore-refs

Add support for build-update-repo --static-delta-ignore-ref=PATTERN
This commit is contained in:
Alexander Larsson
2019-03-12 15:03:55 +01:00
committed by GitHub
2 changed files with 71 additions and 14 deletions

View File

@@ -50,6 +50,7 @@ static gboolean opt_no_update_appstream;
static gboolean opt_no_update_summary;
static gint opt_prune_depth = -1;
static gint opt_static_delta_jobs;
static char **opt_static_delta_ignore_refs;
static GOptionEntry options[] = {
{ "redirect-url", 0, 0, G_OPTION_ARG_STRING, &opt_redirect_url, N_("Redirect this repo to a new URL"), N_("URL") },
@@ -64,6 +65,7 @@ static GOptionEntry options[] = {
{ "no-update-summary", 0, 0, G_OPTION_ARG_NONE, &opt_no_update_summary, N_("Don't update the summary"), NULL },
{ "no-update-appstream", 0, 0, G_OPTION_ARG_NONE, &opt_no_update_appstream, N_("Don't update the appstream branch"), NULL },
{ "static-delta-jobs", 0, 0, G_OPTION_ARG_INT, &opt_static_delta_jobs, N_("Max parallel jobs when creating deltas (default: NUMCPUs)"), N_("NUM-JOBS") },
{ "static-delta-ignore-ref", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_static_delta_ignore_refs, N_("Don't create deltas matching refs"), N_("PATTERN") },
{ "prune", 0, 0, G_OPTION_ARG_NONE, &opt_prune, N_("Prune unused objects"), NULL },
{ "prune-depth", 0, 0, G_OPTION_ARG_INT, &opt_prune_depth, N_("Only traverse DEPTH parents for each commit (default: -1=infinite)"), N_("DEPTH") },
{ "generate-static-delta-from", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_generate_delta_from, NULL, NULL },
@@ -227,14 +229,14 @@ delta_generation_done (GObject *source_object,
}
static gboolean
spawn_delete_generation (GMainContext *context,
int *n_spawned_delta_generate,
OstreeRepo *repo,
GVariant *params,
const char *ref,
const char *from,
const char *to,
GError **error)
spawn_delta_generation (GMainContext *context,
int *n_spawned_delta_generate,
OstreeRepo *repo,
GVariant *params,
const char *ref,
const char *from,
const char *to,
GError **error)
{
g_autoptr(GSubprocessLauncher) launcher = g_subprocess_launcher_new (0);
g_autoptr(GSubprocess) subprocess = NULL;
@@ -296,6 +298,7 @@ generate_all_deltas (OstreeRepo *repo,
g_autoptr(GVariant) params = NULL;
int n_spawned_delta_generate = 0;
g_autoptr(GMainContextPopDefault) context = NULL;
g_autoptr(GPtrArray) ignore_patterns = g_ptr_array_new_with_free_func ((GDestroyNotify)g_pattern_spec_free);
g_print ("Generating static deltas\n");
@@ -323,6 +326,13 @@ generate_all_deltas (OstreeRepo *repo,
context = flatpak_main_context_new_default ();
if (opt_static_delta_ignore_refs != NULL)
{
for (i = 0; opt_static_delta_ignore_refs[i] != NULL; i++)
g_ptr_array_add (ignore_patterns,
g_pattern_spec_new (opt_static_delta_ignore_refs[i]));
}
g_hash_table_iter_init (&iter, all_refs);
while (g_hash_table_iter_next (&iter, &key, &value))
{
@@ -332,6 +342,44 @@ generate_all_deltas (OstreeRepo *repo,
g_autoptr(GVariant) parent_variant = NULL;
g_autofree char *parent_commit = NULL;
g_autofree char *grandparent_commit = NULL;
gboolean ignore_ref = FALSE;
if (g_str_has_prefix (ref, "app/") || g_str_has_prefix (ref, "runtime/"))
{
g_auto(GStrv) parts = g_strsplit (ref, "/", 4);
for (i = 0; i < ignore_patterns->len; i++)
{
GPatternSpec *pattern = g_ptr_array_index(ignore_patterns, i);
if (g_pattern_match_string (pattern, parts[1]))
{
ignore_ref = TRUE;
break;
}
}
}
else if (g_str_has_prefix (ref, "appstream/"))
{
/* Old appstream branch deltas poorly, and most users handle the new format */
ignore_ref = TRUE;
}
else if (g_str_has_prefix (ref, "appstream2/"))
{
/* Always delta this */
ignore_ref = FALSE;
}
else
{
/* Ignore unknown ref types */
ignore_ref = FALSE;
}
if (ignore_ref)
{
g_debug ("Ignoring deltas for ref %s", ref);
continue;
}
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit,
&variant, NULL))
@@ -343,9 +391,9 @@ generate_all_deltas (OstreeRepo *repo,
/* From empty */
if (!g_hash_table_contains (all_deltas_hash, commit))
{
if (!spawn_delete_generation (context, &n_spawned_delta_generate, repo, params,
ref, NULL, commit,
error))
if (!spawn_delta_generation (context, &n_spawned_delta_generate, repo, params,
ref, NULL, commit,
error))
return FALSE;
}
@@ -369,9 +417,9 @@ generate_all_deltas (OstreeRepo *repo,
if (!g_hash_table_contains (all_deltas_hash, from_parent))
{
if (!spawn_delete_generation (context, &n_spawned_delta_generate, repo, params,
ref, parent_commit, commit,
error))
if (!spawn_delta_generation (context, &n_spawned_delta_generate, repo, params,
ref, parent_commit, commit,
error))
return FALSE;
}

View File

@@ -162,6 +162,15 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--static-delta-ignore-ref=PATTERN</option></term>
<listitem><para>
Don't generate deltas for runtime or application id matching this pattern. For instance,
--static-delta-ignore-ref=*.Sources means there will not be any deltas for source refs.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--prune</option></term>