bin: Port a few commands (diff,remote,static-delta) to new style
authorColin Walters <walters@verbum.org>
Wed, 15 Nov 2017 23:04:31 +0000 (18:04 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 15 Nov 2017 23:31:26 +0000 (23:31 +0000)
No functional changes, not prep for anything, just keeping up some momentum.

Closes: #1344
Approved by: jlebon

src/ostree/ot-admin-builtin-diff.c
src/ostree/ot-builtin-remote.c
src/ostree/ot-builtin-static-delta.c

index fe0c5365d31420d9fec5548c51ae310c9d5f2217..d33fd8a2852bfc6e38ad35e960ba5ec4b5bbe402 100644 (file)
@@ -43,29 +43,20 @@ static GOptionEntry options[] = {
 gboolean
 ot_admin_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
 {
-  g_autoptr(GOptionContext) context = NULL;
-  g_autoptr(OstreeSysroot) sysroot = NULL;
-  gboolean ret = FALSE;
-  g_autoptr(OstreeDeployment) deployment = NULL;
-  g_autoptr(GFile) deployment_dir = NULL;
-  g_autoptr(GPtrArray) modified = NULL;
-  g_autoptr(GPtrArray) removed = NULL;
-  g_autoptr(GPtrArray) added = NULL;
-  g_autoptr(GFile) orig_etc_path = NULL;
-  g_autoptr(GFile) new_etc_path = NULL;
-
-  context = g_option_context_new ("");
-
+  g_autoptr(GOptionContext) context = g_option_context_new ("");
   g_option_context_add_main_entries (context, options, NULL);
 
+  g_autoptr(OstreeSysroot) sysroot = NULL;
   if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
                                           OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
                                           invocation, &sysroot, cancellable, error))
-    goto out;
+    return FALSE;
 
   if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname,
                                                      cancellable, error))
-    goto out;
+    return FALSE;
+
+  g_autoptr(OstreeDeployment) deployment = NULL;
   if (opt_osname != NULL)
     {
       deployment = ostree_sysroot_get_merge_deployment (sysroot, opt_osname);
@@ -73,28 +64,24 @@ ot_admin_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocatio
         {
           g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                        "No deployment for OS '%s'", opt_osname);
-          goto out;
+          return FALSE;
         }
     }
   else
     deployment = g_object_ref (ostree_sysroot_get_booted_deployment (sysroot));
 
-  deployment_dir = ostree_sysroot_get_deployment_directory (sysroot, deployment);
-
-  orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc");
-  new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc");
-  
-  modified = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_diff_item_unref);
-  removed = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
-  added = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+  g_autoptr(GFile) deployment_dir = ostree_sysroot_get_deployment_directory (sysroot, deployment);
+  g_autoptr(GFile) orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc");
+  g_autoptr(GFile) new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc");
+  g_autoptr(GPtrArray) modified = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_diff_item_unref);
+  g_autoptr(GPtrArray) removed = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+  g_autoptr(GPtrArray) added = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
   if (!ostree_diff_dirs (OSTREE_DIFF_FLAGS_IGNORE_XATTRS,
                          orig_etc_path, new_etc_path, modified, removed, added,
                          cancellable, error))
-    goto out;
+    return FALSE;
 
   ostree_diff_print (orig_etc_path, new_etc_path, modified, removed, added);
 
-  ret = TRUE;
- out:
-  return ret;
+  return TRUE;
 }
index 0be878cc6f7fc78792498ed05d7777f3eeca966a..dfb07d039b87e5daa10ddbf8d125cc78fc5f2021 100644 (file)
@@ -86,12 +86,8 @@ remote_option_context_new_with_commands (void)
 gboolean
 ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
 {
-  OstreeCommand *subcommand;
   const char *subcommand_name = NULL;
-  g_autofree char *prgname = NULL;
-  gboolean ret = FALSE;
-  int in, out;
-
+  int in,out;
   for (in = 1, out = 1; in < argc; in++, out++)
     {
       /* The non-option is the command, take it out of the arguments */
@@ -115,7 +111,7 @@ ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocatio
 
   argc = out;
 
-  subcommand = remote_subcommands;
+  OstreeCommand *subcommand = remote_subcommands;
   while (subcommand->name)
     {
       if (g_strcmp0 (subcommand_name, subcommand->name) == 0)
@@ -150,18 +146,15 @@ ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocatio
       help = g_option_context_get_help (context, FALSE, NULL);
       g_printerr ("%s", help);
 
-      goto out;
+      return FALSE;
     }
 
-  prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
+  g_autofree char *prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
   g_set_prgname (prgname);
 
   OstreeCommandInvocation sub_invocation = { .command = subcommand };
   if (!subcommand->fn (argc, argv, &sub_invocation, cancellable, error))
-    goto out;
-
-  ret = TRUE;
+    return FALSE;
 
- out:
-  return ret;
+  return TRUE;
 }
index d053500a2384ad9fce0e24c986e8283454f6f696..d91acd20e3fa97f5ba20e8849157d0bfc2cc262e 100644 (file)
@@ -149,77 +149,63 @@ ot_static_delta_builtin_list (int argc, char **argv, OstreeCommandInvocation *in
 static gboolean
 ot_static_delta_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
 {
-  gboolean ret = FALSE;
-  g_autoptr(GOptionContext) context = NULL;
-  g_autoptr(OstreeRepo) repo = NULL;
-  const char *delta_id = NULL;
 
-  context = g_option_context_new ("");
+  g_autoptr(GOptionContext) context = g_option_context_new ("");
 
+  g_autoptr(OstreeRepo) repo = NULL;
   if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error))
-    goto out;
+    return FALSE;
 
   if (argc < 3)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "DELTA must be specified");
-      goto out;
+      return FALSE;
     }
 
-  delta_id = argv[2];
+  const char *delta_id = argv[2];
 
   if (!ostree_cmd__private__ ()->ostree_static_delta_dump (repo, delta_id, cancellable, error))
-    goto out;
-      
-  ret = TRUE;
- out:
-  return ret;
+    return FALSE;
+
+  return TRUE;
 }
 
 static gboolean
 ot_static_delta_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
 {
-  gboolean ret = FALSE;
-  g_autoptr(GOptionContext) context = NULL;
-  g_autoptr(OstreeRepo) repo = NULL;
-  const char *delta_id = NULL;
-
-  context = g_option_context_new ("");
+  g_autoptr(GOptionContext) context = g_option_context_new ("");
 
+  g_autoptr(OstreeRepo) repo = NULL;
   if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error))
-    goto out;
+    return FALSE;
 
   if (argc < 3)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "DELTA must be specified");
-      goto out;
+      return FALSE;
     }
 
-  delta_id = argv[2];
+  const char *delta_id = argv[2];
 
   if (!ostree_cmd__private__ ()->ostree_static_delta_delete (repo, delta_id, cancellable, error))
-    goto out;
+    return FALSE;
 
-  ret = TRUE;
- out:
-  return ret;
+  return TRUE;
 }
 
 
 static gboolean
 ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
 {
-  gboolean ret = FALSE;
-  g_autoptr(GOptionContext) context = NULL;
+  g_autoptr(GOptionContext) context = g_option_context_new ("[TO]");
   g_autoptr(OstreeRepo) repo = NULL;
-
-  context = g_option_context_new ("[TO]");
   if (!ostree_option_context_parse (context, generate_options, &argc, &argv, invocation, &repo, cancellable, error))
-    goto out;
+    return FALSE;
 
   if (!ostree_ensure_repo_writable (repo, error))
-    goto out;
+    return FALSE;
 
   if (argc >= 3 && opt_to_rev == NULL)
     opt_to_rev = argv[2];
@@ -228,7 +214,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "TO revision must be specified");
-      goto out;
+      return FALSE;
     }
   else
     {
@@ -247,7 +233,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
             {
               g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                    "Cannot specify both --empty and --from=REV");
-              goto out;
+              return FALSE;
             }
           from_source = NULL;
         }
@@ -264,25 +250,24 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
       if (from_source)
         {
           if (!ostree_repo_resolve_rev (repo, from_source, FALSE, &from_resolved, error))
-            goto out;
+            return FALSE;
         }
       if (!ostree_repo_resolve_rev (repo, opt_to_rev, FALSE, &to_resolved, error))
-        goto out;
+        return FALSE;
 
       if (opt_if_not_exists)
         {
           gboolean does_exist;
           g_autofree char *delta_id = from_resolved ? g_strconcat (from_resolved, "-", to_resolved, NULL) : g_strdup (to_resolved);
           if (!ostree_cmd__private__ ()->ostree_static_delta_query_exists (repo, delta_id, &does_exist, cancellable, error))
-            goto out;
+            return FALSE;
           if (does_exist)
             {
               g_print ("Delta %s already exists.\n", delta_id);
-              ret = TRUE;
-              goto out;
+              return TRUE;
             }
         }
-      
+
       if (opt_endianness)
         {
           if (strcmp (opt_endianness, "l") == 0)
@@ -293,12 +278,12 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
             {
               g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "Invalid endianness '%s'", opt_endianness);
-              goto out;
+              return FALSE;
             }
         }
       else
         endianness = G_BYTE_ORDER;
-          
+
       if (opt_swap_endianness)
         {
           switch (endianness)
@@ -346,54 +331,47 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
                                                 from_resolved, to_resolved, NULL,
                                                 params,
                                                 cancellable, error))
-          goto out;
+          return FALSE;
       }
 
     }
 
-  ret = TRUE;
- out:
-  return ret;
+  return TRUE;
 }
 
 static gboolean
 ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
 {
-  gboolean ret = FALSE;
-  const char *patharg;
-  g_autoptr(GFile) path = NULL;
   g_autoptr(GOptionContext) context = NULL;
   g_autoptr(OstreeRepo) repo = NULL;
 
   context = g_option_context_new ("");
   if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, invocation, &repo, cancellable, error))
-    goto out;
+    return FALSE;
 
   if (!ostree_ensure_repo_writable (repo, error))
-    goto out;
+    return FALSE;
 
   if (argc < 3)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "PATH must be specified");
-      goto out;
+      return FALSE;
     }
 
-  patharg = argv[2];
-  path = g_file_new_for_path (patharg);
+  const char *patharg = argv[2];
+  g_autoptr(GFile) path = g_file_new_for_path (patharg);
 
   if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
-    goto out;
+    return FALSE;
 
   if (!ostree_repo_static_delta_execute_offline (repo, path, FALSE, cancellable, error))
-    goto out;
+    return FALSE;
 
   if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
-    goto out;
+    return FALSE;
 
-  ret = TRUE;
- out:
-  return ret;
+  return TRUE;
 }
 
 gboolean