[ostree] core: Add --add-metadata-string option for commit
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: Add --add-metadata-string option for commit
- Date: Fri, 23 Dec 2011 17:11:01 +0000 (UTC)
commit 1687f3efa89c806ce459132a4a322c2e0dbeb7c4
Author: Colin Walters <walters verbum org>
Date: Fri Dec 23 07:14:48 2011 -0500
core: Add --add-metadata-string option for commit
A convenience function for the common case of slapping a string into
the metadata.
src/ostree/ot-builtin-commit.c | 36 ++++++++++++++++++++++++++++++++++++
tests/t0000-basic.sh | 7 ++++++-
2 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 8e525ef..329c82a 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -35,6 +35,7 @@ static char *subject;
static char *body;
static char *parent;
static char *branch;
+static char **metadata_strings;
static gboolean skip_if_unchanged;
static gboolean tar_autocreate_parents;
static char **trees;
@@ -46,6 +47,7 @@ static GOptionEntry options[] = {
{ "body", 'm', 0, G_OPTION_ARG_STRING, &body, "Full description", "body" },
{ "metadata-variant-text", 0, 0, G_OPTION_ARG_FILENAME, &metadata_text_path, "File containing g_variant_print() output", "path" },
{ "metadata-variant", 0, 0, G_OPTION_ARG_FILENAME, &metadata_bin_path, "File containing serialized variant, in host endianness", "path" },
+ { "add-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &metadata_strings, "Append given key and value (in string format) to metadata", "KEY=VALUE" },
{ "branch", 'b', 0, G_OPTION_ARG_STRING, &branch, "Branch", "branch" },
{ "parent", 'p', 0, G_OPTION_ARG_STRING, &parent, "Parent commit", "commit" },
{ "tree", 0, 0, G_OPTION_ARG_STRING_ARRAY, &trees, "Overlay the given argument as a tree", "NAME" },
@@ -74,6 +76,8 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
GCancellable *cancellable = NULL;
OstreeMutableTree *mtree = NULL;
char *tree_type = NULL;
+ GVariantBuilder metadata_builder;
+ gboolean metadata_builder_initialized = FALSE;
gboolean skip_commit = FALSE;
context = g_option_context_new ("[ARG] - Commit a new revision");
@@ -105,6 +109,36 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
else
g_assert_not_reached ();
}
+ else if (metadata_strings)
+ {
+ char **iter;
+
+ metadata_builder_initialized = TRUE;
+ g_variant_builder_init (&metadata_builder, G_VARIANT_TYPE ("a{sv}"));
+
+ for (iter = metadata_strings; *iter; iter++)
+ {
+ const char *s;
+ const char *eq;
+ char *key;
+
+ s = *iter;
+
+ eq = strchr (s, '=');
+ if (!eq)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Missing '=' in KEY=VALUE metadata '%s'", s);
+ goto out;
+ }
+
+ key = g_strndup (s, eq - s);
+ g_variant_builder_add (&metadata_builder, "{sv}", key,
+ g_variant_new_string (eq + 1));
+ }
+ metadata = g_variant_builder_end (&metadata_builder);
+ metadata_builder_initialized = FALSE;
+ }
repo = ostree_repo_new (repo_path);
if (!ostree_repo_check (repo, error))
@@ -253,6 +287,8 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
ret = TRUE;
out:
+ if (metadata_builder_initialized)
+ g_variant_builder_clear (&metadata_builder);
g_clear_object (&arg);
g_clear_object (&mtree);
g_free (contents_checksum);
diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh
index 9176d8f..4f4c4ec 100755
--- a/tests/t0000-basic.sh
+++ b/tests/t0000-basic.sh
@@ -19,7 +19,7 @@
set -e
-echo "1..21"
+echo "1..22"
. libtest.sh
@@ -164,3 +164,8 @@ new_rev=$($OSTREE rev-parse test2)
assert_streq "${old_rev}" "${new_rev}"
echo "ok commit --skip-if-unchanged"
+$OSTREE commit -b test2 -s "Metadata string" --add-metadata-string=FOO=BAR --add-metadata-string=KITTENS=CUTE --tree=ref=test2
+$OSTREE show test2 > test2-commit-text
+assert_file_has_content test2-commit-text "FOO=.*BAR"
+assert_file_has_content test2-commit-text "KITTENS=.*CUTE"
+echo "ok metadata commit with strings"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]