[ostree/wip/delta2] delta: Change static-delta to have multiple subcommands
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/delta2] delta: Change static-delta to have multiple subcommands
- Date: Tue, 6 May 2014 16:06:02 +0000 (UTC)
commit fb3daeffbbb9786c833503b166460d4f46c1deba
Author: Colin Walters <walters verbum org>
Date: Mon May 5 09:09:31 2014 -0400
delta: Change static-delta to have multiple subcommands
src/ostree/ot-builtin-static-delta.c | 285 +++++++++++++++++++++++-----------
tests/pull-test.sh | 6 +-
tests/test-delta.sh | 8 +-
3 files changed, 201 insertions(+), 98 deletions(-)
---
diff --git a/src/ostree/ot-builtin-static-delta.c b/src/ostree/ot-builtin-static-delta.c
index 6422fdf..1cba667 100644
--- a/src/ostree/ot-builtin-static-delta.c
+++ b/src/ostree/ot-builtin-static-delta.c
@@ -22,134 +22,166 @@
#include "ot-builtins.h"
#include "ostree.h"
+#include "ot-main.h"
#include "otutil.h"
static char *opt_from_rev;
static char *opt_to_rev;
-static char *opt_apply;
static char **opt_key_ids;
static char *opt_gpg_homedir;
static char *opt_max_usize;
-static GOptionEntry options[] = {
+#define BUILTINPROTO(name) static gboolean ot_static_delta_builtin_ ## name (int argc, char **argv,
OstreeRepo *repo, GCancellable *cancellable, GError **error)
+
+BUILTINPROTO(list);
+BUILTINPROTO(generate);
+BUILTINPROTO(apply_offline);
+
+#undef BUILTINPROTO
+
+static OstreeCommand static_delta_subcommands[] = {
+ { "list", ot_static_delta_builtin_list },
+ { "generate", ot_static_delta_builtin_generate },
+ { "apply-offline", ot_static_delta_builtin_apply_offline },
+ { NULL, NULL }
+};
+
+static GOptionEntry generate_options[] = {
{ "from", 0, 0, G_OPTION_ARG_STRING, &opt_from_rev, "Create delta from revision REV", "REV" },
{ "to", 0, 0, G_OPTION_ARG_STRING, &opt_to_rev, "Create delta to revision REV", "REV" },
- { "apply", 0, 0, G_OPTION_ARG_FILENAME, &opt_apply, "Apply delta from PATH", "PATH" },
{ "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "GPG Key ID to sign the delta with",
"key-id"},
{ "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, "GPG Homedir to use when looking for
keyrings", "homedir"},
{ "max-usize", 'u', 0, G_OPTION_ARG_STRING, &opt_max_usize, "Maximum uncompressed size in megabytes",
NULL},
{ NULL }
};
-gboolean
-ostree_builtin_static_delta (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError
**error)
+static void
+static_delta_usage (char **argv,
+ gboolean is_error)
+{
+ OstreeCommand *command = static_delta_subcommands;
+ void (*print_func) (const gchar *format, ...);
+
+ if (is_error)
+ print_func = g_printerr;
+ else
+ print_func = g_print;
+
+ print_func ("usage: %s --repo=PATH static-delta\n",
+ argv[0]);
+ print_func ("Builtin commands:\n");
+
+ while (command->name)
+ {
+ print_func (" %s\n", command->name);
+ command++;
+ }
+}
+
+static gboolean
+ot_static_delta_builtin_list (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError
**error)
{
gboolean ret = FALSE;
- GOptionContext *context;
gs_unref_ptrarray GPtrArray *delta_names = NULL;
+ guint i;
- context = g_option_context_new ("Manage static delta files");
- g_option_context_add_main_entries (context, options, NULL);
-
- if (!g_option_context_parse (context, &argc, &argv, error))
+ if (!ostree_repo_list_static_delta_names (repo, &delta_names, cancellable, error))
goto out;
-
- if (opt_apply)
+
+ if (delta_names->len == 0)
+ {
+ g_print ("(No static deltas)\n");
+ }
+ else
{
- gs_unref_object GFile *path = g_file_new_for_path (opt_apply);
+ for (i = 0; i < delta_names->len; i++)
+ {
+ g_print ("%s\n", (char*)delta_names->pdata[i]);
+ }
+ }
- if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
- goto out;
+ ret = TRUE;
+ out:
+ return ret;
+}
- if (!ostree_repo_static_delta_execute_offline (repo, path, TRUE, cancellable, error))
- goto out;
+static gboolean
+ot_static_delta_builtin_generate (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError
**error)
+{
+ gboolean ret = FALSE;
+ GOptionContext *context;
- if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
- goto out;
+ context = g_option_context_new ("Generate static delta files");
+ g_option_context_add_main_entries (context, generate_options, NULL);
+
+ if (!g_option_context_parse (context, &argc, &argv, error))
+ goto out;
+
+ if (argc >= 2 && opt_to_rev == NULL)
+ opt_to_rev = argv[1];
+
+ if (argc < 2 && opt_to_rev == NULL)
+ {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "TO revision must be specified");
+ goto out;
}
else
{
- if (argc >= 2 && opt_to_rev == NULL)
- opt_to_rev = argv[1];
+ const char *from_source;
+ gs_free char *from_resolved = NULL;
+ gs_free char *to_resolved = NULL;
+ gs_free char *from_parent_str = NULL;
+ gs_unref_variant_builder GVariantBuilder *parambuilder = NULL;
- if (argc < 2 && opt_to_rev == NULL)
+ g_assert (opt_to_rev);
+
+ if (opt_from_rev == NULL)
{
- guint i;
- if (!ostree_repo_list_static_delta_names (repo, &delta_names, cancellable, error))
- goto out;
-
- if (delta_names->len == 0)
- {
- g_print ("(No static deltas)\n");
- }
- else
- {
- for (i = 0; i < delta_names->len; i++)
- {
- g_print ("%s\n", (char*)delta_names->pdata[i]);
- }
- }
+ from_parent_str = g_strconcat (opt_to_rev, "^", NULL);
+ from_source = from_parent_str;
}
- else if (opt_to_rev != NULL)
+ else
{
- const char *from_source;
- gs_free char *from_resolved = NULL;
- gs_free char *to_resolved = NULL;
- gs_free char *from_parent_str = NULL;
- gs_unref_variant_builder GVariantBuilder *parambuilder = NULL;
+ from_source = opt_from_rev;
+ }
- if (opt_from_rev == NULL)
- {
- from_parent_str = g_strconcat (opt_to_rev, "^", NULL);
- from_source = from_parent_str;
- }
- else
- {
- from_source = opt_from_rev;
- }
+ if (!ostree_repo_resolve_rev (repo, from_source, FALSE, &from_resolved, error))
+ goto out;
+ if (!ostree_repo_resolve_rev (repo, opt_to_rev, FALSE, &to_resolved, error))
+ goto out;
+
+ parambuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+ if (opt_max_usize)
+ g_variant_builder_add (parambuilder, "{sv}",
+ "max-usize", g_variant_new_uint32 (g_ascii_strtoull (opt_max_usize, NULL,
10)));
- if (!ostree_repo_resolve_rev (repo, from_source, FALSE, &from_resolved, error))
- goto out;
- if (!ostree_repo_resolve_rev (repo, opt_to_rev, FALSE, &to_resolved, error))
- goto out;
-
- parambuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
- if (opt_max_usize)
- g_variant_builder_add (parambuilder, "{sv}",
- "max-usize", g_variant_new_uint32 (g_ascii_strtoull (opt_max_usize, NULL,
10)));
-
- g_print ("Generating static delta:\n");
- g_print (" From: %s\n", from_resolved);
- g_print (" To: %s\n", to_resolved);
- if (!ostree_repo_static_delta_generate (repo, OSTREE_STATIC_DELTA_GENERATE_OPT_MAJOR,
- from_resolved, to_resolved, NULL,
- g_variant_builder_end (parambuilder),
- cancellable, error))
- goto out;
-
- if (opt_key_ids)
+ g_print ("Generating static delta:\n");
+ g_print (" From: %s\n", from_resolved);
+ g_print (" To: %s\n", to_resolved);
+ if (!ostree_repo_static_delta_generate (repo, OSTREE_STATIC_DELTA_GENERATE_OPT_MAJOR,
+ from_resolved, to_resolved, NULL,
+ g_variant_builder_end (parambuilder),
+ cancellable, error))
+ goto out;
+
+ if (opt_key_ids)
+ {
+ char **iter;
+
+ for (iter = opt_key_ids; iter && *iter; iter++)
{
- char **iter;
-
- for (iter = opt_key_ids; iter && *iter; iter++)
- {
- const char *keyid = *iter;
-
- if (!ostree_repo_sign_delta (repo,
- from_resolved, to_resolved,
- keyid,
- opt_gpg_homedir,
- cancellable,
- error))
- goto out;
- }
+ const char *keyid = *iter;
+
+ if (!ostree_repo_sign_delta (repo,
+ from_resolved, to_resolved,
+ keyid,
+ opt_gpg_homedir,
+ cancellable,
+ error))
+ goto out;
}
}
- else
- {
- ot_util_usage_error (context, "--from=REV must be specified", error);
- goto out;
- }
}
ret = TRUE;
@@ -158,3 +190,74 @@ ostree_builtin_static_delta (int argc, char **argv, OstreeRepo *repo, GCancellab
g_option_context_free (context);
return ret;
}
+
+static gboolean
+ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable,
GError **error)
+{
+ gboolean ret = FALSE;
+ const char *patharg;
+ gs_unref_object GFile *path = NULL;
+
+ if (argc < 2)
+ {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "PATH must be specified");
+ goto out;
+ }
+
+ patharg = argv[1];
+ path = g_file_new_for_path (patharg);
+
+ if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
+ goto out;
+
+ if (!ostree_repo_static_delta_execute_offline (repo, path, TRUE, cancellable, error))
+ goto out;
+
+ if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
+ goto out;
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
+gboolean
+ostree_builtin_static_delta (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError
**error)
+{
+ gboolean ret = FALSE;
+ OstreeCommand *command;
+ const char *cmdname;
+
+ if (argc < 2)
+ {
+ static_delta_usage (argv, TRUE);
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "No command specified");
+ goto out;
+ }
+
+ cmdname = argv[1];
+ command = static_delta_subcommands;
+ while (command->name)
+ {
+ if (g_strcmp0 (cmdname, command->name) == 0)
+ break;
+ command++;
+ }
+
+ if (!command->fn)
+ {
+ gs_free char *msg = g_strdup_printf ("Unknown command '%s'", cmdname);
+ static_delta_usage (argv, TRUE);
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, msg);
+ goto out;
+ }
+
+ if (!command->fn (argc-1, argv+1, repo, cancellable, error))
+ goto out;
+
+ ret = TRUE;
+ out:
+ return ret;
+}
diff --git a/tests/pull-test.sh b/tests/pull-test.sh
index 3829e4c..b88b2c2 100755
--- a/tests/pull-test.sh
+++ b/tests/pull-test.sh
@@ -60,7 +60,7 @@ ${CMD_PREFIX} ostree --repo=repo pull origin main
${CMD_PREFIX} ostree --repo=repo fsck
# Generate a delta from old to current, even though we aren't going to
# use it.
-ostree --repo=ostree-srv/gnomerepo static-delta main
+ostree --repo=ostree-srv/gnomerepo static-delta generate main
rm main-files -rf
ostree --repo=ostree-srv/gnomerepo checkout main main-files
@@ -72,7 +72,7 @@ ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main -s 'static delt
cd ..
rm main-files -rf
# Generate delta that we'll use
-ostree --repo=ostree-srv/gnomerepo static-delta main
+ostree --repo=ostree-srv/gnomerepo static-delta generate main
cd ${test_tmpdir}
${CMD_PREFIX} ostree --repo=repo pull origin main
@@ -97,7 +97,7 @@ echo "further modified file for static deltas" > baz/cow
ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main -s '2nd static delta test'
cd ..
rm main-files -rf
-ostree --repo=ostree-srv/gnomerepo static-delta main
+ostree --repo=ostree-srv/gnomerepo static-delta generate main
cd ${test_tmpdir}
${CMD_PREFIX} ostree --repo=repo pull origin main
diff --git a/tests/test-delta.sh b/tests/test-delta.sh
index c5de5b4..69716e5 100755
--- a/tests/test-delta.sh
+++ b/tests/test-delta.sh
@@ -57,18 +57,18 @@ function permuteDirectory() {
permuteDirectory 1 files
ostree --repo=repo commit -b test -s test --tree=dir=files
-ostree static-delta --repo=repo
+ostree static-delta --repo=repo list
origrev=$(ostree --repo=repo rev-parse test^)
newrev=$(ostree --repo=repo rev-parse test)
-ostree static-delta --repo=repo --from=${origrev} --to=${newrev}
+ostree --repo=repo static-delta generate --from=${origrev} --to=${newrev}
-assert_has_dir repo/deltas/${origrev}-${newrev}
+assert_has_dir repo/deltas/$(echo ${origrev} | dd bs=1 count=2 2>/dev/null)/$(echo ${origrev} | dd bs=1
skip=2 2>/dev/null)-${newrev}
mkdir repo2
ostree --repo=repo2 init --mode=archive-z2
ostree --repo=repo2 pull-local repo ${origrev}
-ostree --repo=repo2 static-delta --apply=repo/deltas/${origrev}-${newrev}
+ostree --repo=repo2 static-delta apply-offline repo/deltas/${origrev}-${newrev}
ostree --repo=repo2 fsck
ostree --repo=repo2 show ${newrev}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]