core: Support actually adding metadata to commits

This commit is contained in:
Colin Walters 2011-11-04 12:32:08 -04:00
parent 889f454cb1
commit d2cb5fb49a
3 changed files with 51 additions and 3 deletions

View File

@ -1611,7 +1611,7 @@ commit_parsed_tree (OstreeRepo *self,
now = g_date_time_new_now_utc ();
commit = g_variant_new ("(u@a{sv}ssstss)",
GUINT32_TO_BE (OSTREE_COMMIT_VERSION),
create_empty_gvariant_dict (),
metadata ? metadata : create_empty_gvariant_dict (),
parent ? parent : "",
subject, body ? body : "",
GUINT64_TO_BE (g_date_time_to_unix (now)),

View File

@ -32,6 +32,8 @@ static gboolean separator_null;
static int from_fd = -1;
static gboolean from_stdin;
static char *from_file;
static char *metadata_text_path;
static char *metadata_bin_path;
static char *subject;
static char *body;
static char *parent;
@ -42,6 +44,8 @@ static char **removals;
static GOptionEntry options[] = {
{ "subject", 's', 0, G_OPTION_ARG_STRING, &subject, "One line subject", "subject" },
{ "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" },
{ "branch", 'b', 0, G_OPTION_ARG_STRING, &branch, "Branch", "branch" },
{ "parent", 'p', 0, G_OPTION_ARG_STRING, &parent, "Parent commit", "commit" },
{ "from-fd", 0, 0, G_OPTION_ARG_INT, &from_fd, "Read new tree files from fd", "file descriptor" },
@ -199,6 +203,8 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
GChecksum *commit_checksum = NULL;
char **iter;
char separator;
GVariant *metadata = NULL;
GMappedFile *metadata_mappedf = NULL;
context = g_option_context_new ("[DIR] - Commit a new revision");
g_option_context_add_main_entries (context, options, NULL);
@ -223,6 +229,33 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
goto out;
}
if (metadata_text_path || metadata_bin_path)
{
metadata_mappedf = g_mapped_file_new (metadata_text_path ? metadata_text_path : metadata_bin_path, FALSE, error);
if (!metadata_mappedf)
goto out;
if (metadata_text_path)
{
metadata = g_variant_parse (G_VARIANT_TYPE ("a{sv}"),
g_mapped_file_get_contents (metadata_mappedf),
g_mapped_file_get_contents (metadata_mappedf) + g_mapped_file_get_length (metadata_mappedf),
NULL, error);
if (!metadata)
goto out;
}
else if (metadata_bin_path)
{
metadata = g_variant_new_from_data (G_VARIANT_TYPE ("a{sv}"),
g_mapped_file_get_contents (metadata_mappedf),
g_mapped_file_get_length (metadata_mappedf),
FALSE,
(GDestroyNotify) g_mapped_file_unref,
metadata_mappedf);
}
else
g_assert_not_reached ();
}
repo = ostree_repo_new (repo_path);
if (!ostree_repo_check (repo, error))
goto out;
@ -264,7 +297,7 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
for (iter = removals; *iter; iter++)
g_ptr_array_add (removals_array, *iter);
if (!ostree_repo_commit (repo, branch, parent, subject, body, NULL,
if (!ostree_repo_commit (repo, branch, parent, subject, body, metadata,
dir, additions_array,
removals_array,
&commit_checksum,
@ -332,6 +365,8 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
g_print ("%s\n", g_checksum_get_string (commit_checksum));
out:
g_free (dir);
if (metadata_mappedf)
g_mapped_file_unref (metadata_mappedf);
if (context)
g_option_context_free (context);
g_clear_object (&repo);

View File

@ -20,7 +20,7 @@
set -e
echo "1..10"
echo "1..12"
. libtest.sh
@ -93,3 +93,16 @@ assert_file_has_content yet/another/tree/green 'leaf'
assert_file_has_content four '4'
echo "ok cwd contents"
cd ${test_tmpdir}/checkout-test2-4
echo afile > oh-look-a-file
cat > ostree-commit-metadata <<EOF
{'origin': <'http://example.com'>, 'buildid': <@u 42>}
EOF
$OSTREE commit -b test2 -s "Metadata test" --metadata-variant-text=./ostree-commit-metadata --add=oh-look-a-file
rm ostree-commit-metadata
echo "ok metadata commit"
$OSTREE show test2 > ${test_tmpdir}/show
assert_file_has_content ${test_tmpdir}/show 'example.com'
assert_file_has_content ${test_tmpdir}/show 'buildid'
echo "ok metadata content"