summaryrefslogtreecommitdiff
path: root/src/ostree/ot-admin-builtin-set-origin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ostree/ot-admin-builtin-set-origin.c')
-rw-r--r--src/ostree/ot-admin-builtin-set-origin.c68
1 files changed, 35 insertions, 33 deletions
diff --git a/src/ostree/ot-admin-builtin-set-origin.c b/src/ostree/ot-admin-builtin-set-origin.c
index 91184cd6..84772cce 100644
--- a/src/ostree/ot-admin-builtin-set-origin.c
+++ b/src/ostree/ot-admin-builtin-set-origin.c
@@ -19,42 +19,44 @@
#include "config.h"
-#include "ot-main.h"
+#include "ostree.h"
#include "ot-admin-builtins.h"
#include "ot-admin-functions.h"
-#include "ostree.h"
+#include "ot-main.h"
#include "otutil.h"
-#include <unistd.h>
-#include <stdlib.h>
#include <glib/gi18n.h>
+#include <stdlib.h>
+#include <unistd.h>
static int opt_index = -1;
static char **opt_set;
-static GOptionEntry options[] = {
- { "set", 's', 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, "Set config option KEY=VALUE for remote", "KEY=VALUE" },
- { "index", 0, 0, G_OPTION_ARG_INT, &opt_index, "Operate on the deployment INDEX, starting from zero", "INDEX" },
- { NULL }
-};
+static GOptionEntry options[]
+ = { { "set", 's', 0, G_OPTION_ARG_STRING_ARRAY, &opt_set,
+ "Set config option KEY=VALUE for remote", "KEY=VALUE" },
+ { "index", 0, 0, G_OPTION_ARG_INT, &opt_index,
+ "Operate on the deployment INDEX, starting from zero", "INDEX" },
+ { NULL } };
gboolean
-ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
+ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *invocation,
+ GCancellable *cancellable, GError **error)
{
gboolean ret = FALSE;
- g_autoptr(GOptionContext) context = NULL;
+ g_autoptr (GOptionContext) context = NULL;
const char *remotename = NULL;
const char *url = NULL;
const char *branch = NULL;
- g_autoptr(OstreeRepo) repo = NULL;
- g_autoptr(OstreeSysroot) sysroot = NULL;
- g_autoptr(OstreeDeployment) target_deployment = NULL;
+ g_autoptr (OstreeRepo) repo = NULL;
+ g_autoptr (OstreeSysroot) sysroot = NULL;
+ g_autoptr (OstreeDeployment) target_deployment = NULL;
context = g_option_context_new ("REMOTENAME URL [BRANCH]");
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
- OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
- invocation, &sysroot, cancellable, error))
+ OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot,
+ cancellable, error))
goto out;
if (argc < 3)
@@ -86,10 +88,10 @@ ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *inv
goto out;
}
- { char **iter;
- g_autoptr(GVariantBuilder) optbuilder =
- g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
- g_autoptr(GVariant) remote_options = NULL;
+ {
+ char **iter;
+ g_autoptr (GVariantBuilder) optbuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+ g_autoptr (GVariant) remote_options = NULL;
for (iter = opt_set; iter && *iter; iter++)
{
@@ -100,21 +102,19 @@ ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *inv
if (!ot_parse_keyvalue (keyvalue, &subkey, &subvalue, error))
goto out;
- g_variant_builder_add (optbuilder, "{s@v}",
- subkey, g_variant_new_variant (g_variant_new_string (subvalue)));
+ g_variant_builder_add (optbuilder, "{s@v}", subkey,
+ g_variant_new_variant (g_variant_new_string (subvalue)));
}
remote_options = g_variant_ref_sink (g_variant_builder_end (optbuilder));
- if (!ostree_repo_remote_change (repo, NULL,
- OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS,
- remotename, url,
- remote_options,
- cancellable, error))
+ if (!ostree_repo_remote_change (repo, NULL, OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS,
+ remotename, url, remote_options, cancellable, error))
goto out;
}
- { GKeyFile *old_origin = ostree_deployment_get_origin (target_deployment);
+ {
+ GKeyFile *old_origin = ostree_deployment_get_origin (target_deployment);
g_autofree char *origin_refspec = g_key_file_get_string (old_origin, "origin", "refspec", NULL);
g_autofree char *origin_remote = NULL;
g_autofree char *origin_ref = NULL;
@@ -122,18 +122,20 @@ ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *inv
if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error))
goto out;
- { g_autofree char *new_refspec = g_strconcat (remotename, ":", branch ? branch : origin_ref, NULL);
- g_autoptr(GKeyFile) new_origin = NULL;
+ {
+ g_autofree char *new_refspec
+ = g_strconcat (remotename, ":", branch ? branch : origin_ref, NULL);
+ g_autoptr (GKeyFile) new_origin = NULL;
new_origin = ostree_sysroot_origin_new_from_refspec (sysroot, new_refspec);
- if (!ostree_sysroot_write_origin_file (sysroot, target_deployment, new_origin,
- cancellable, error))
+ if (!ostree_sysroot_write_origin_file (sysroot, target_deployment, new_origin, cancellable,
+ error))
goto out;
}
}
ret = TRUE;
- out:
+out:
return ret;
}