find-remotes: Minor fixes to --finders code
authorMatthew Leeds <matthew.leeds@endlessm.com>
Sat, 13 Jan 2018 00:32:09 +0000 (16:32 -0800)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 16 Jan 2018 14:15:10 +0000 (14:15 +0000)
This introduces no functional changes, only cleanups.

Closes: #1414
Approved by: jlebon

src/ostree/ot-builtin-find-remotes.c

index 3df84a4f0008dbe6942e9072bf6a7d30bb654ba6..67dbdaa65d9407ff5c79be3667eeb87693198dfa 100644 (file)
@@ -37,8 +37,8 @@ static gboolean opt_pull = FALSE;
 static GOptionEntry options[] =
   {
     { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL },
-    { "finders", 0, 0, G_OPTION_ARG_STRING, &opt_finders, "Use the specified comma separated list of finders (e.g. config,lan,mount)", "FINDERS" },
     { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
+    { "finders", 0, 0, G_OPTION_ARG_STRING, &opt_finders, "Use the specified comma separated list of finders (e.g. config,lan,mount)", "FINDERS" },
     { "pull", 0, 0, G_OPTION_ARG_NONE, &opt_pull, "Pull the updates after finding them", NULL },
     { NULL }
   };
@@ -119,7 +119,7 @@ collection_ref_free0 (OstreeCollectionRef *ref)
 }
 
 static gboolean
-validate_finders_list (char           **finders,
+validate_finders_list (const char     **finders,
                        GOptionContext  *context,
                        GError         **error)
 {
@@ -139,10 +139,10 @@ validate_finders_list (char           **finders,
       return FALSE;
     }
 
-  for (char **iter = finders; iter && *iter; iter++)
+  for (const char **iter = finders; iter && *iter; iter++)
     {
       gboolean is_valid_finder = FALSE;
-      for (int i = 0; i < 3; i++)
+      for (unsigned int i = 0; i < G_N_ELEMENTS (valid_finders); i++)
         {
           if (valid_finders[i].already_used == TRUE)
             continue;
@@ -234,11 +234,11 @@ ostree_builtin_find_remotes (int            argc,
       g_auto(GStrv) finders_strings = NULL;
 
       finders_strings = g_strsplit (opt_finders, ",", 0);
-      if (!validate_finders_list (finders_strings, context, error))
+      if (!validate_finders_list ((const char **)finders_strings, context, error))
         return FALSE;
 
-      finders = g_ptr_array_new ();
-      for (char **iter =finders_strings; iter && *iter; iter++)
+      finders = g_ptr_array_new_with_free_func (NULL);
+      for (const char **iter = (const char **)finders_strings; iter && *iter; iter++)
         {
           if (g_strcmp0 (*iter, "config") == 0)
             {