[ostree] main: Code cleanup by passing OstreeRepo * directly to builtins



commit edfa76fad5d2fc92d753c3317333200d552b99e9
Author: Colin Walters <walters verbum org>
Date:   Sun Aug 25 15:11:05 2013 -0400

    main: Code cleanup by passing OstreeRepo * directly to builtins
    
    It turns out every builtin (with one special exception) that takes a
    repo argument did the same thing; let's just centralize it.  The
    special exception was "ostree init --repo=foo" where foo is expected
    to *not* actually be a repo.  In that case, simply skip the
    ostree_repo_check() invocation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706762

 src/libostree/ostree-repo.c           |   35 ++++++++++++++++++++-
 src/libostree/ostree-repo.h           |    2 +
 src/ostree/main.c                     |    2 +-
 src/ostree/ot-builtin-admin.c         |    2 +-
 src/ostree/ot-builtin-cat.c           |    7 +---
 src/ostree/ot-builtin-checkout.c      |    7 +---
 src/ostree/ot-builtin-checksum.c      |    2 +-
 src/ostree/ot-builtin-commit.c        |    7 +---
 src/ostree/ot-builtin-config.c        |    7 +---
 src/ostree/ot-builtin-diff.c          |    7 +---
 src/ostree/ot-builtin-fsck.c          |    7 +---
 src/ostree/ot-builtin-init.c          |    7 ++--
 src/ostree/ot-builtin-log.c           |    7 +---
 src/ostree/ot-builtin-ls.c            |    7 +---
 src/ostree/ot-builtin-prune.c         |    7 +---
 src/ostree/ot-builtin-pull-local.c    |    6 +--
 src/ostree/ot-builtin-pull.c          |    7 +---
 src/ostree/ot-builtin-refs.c          |    7 +---
 src/ostree/ot-builtin-remote.c        |    7 +---
 src/ostree/ot-builtin-reset.c         |    7 +---
 src/ostree/ot-builtin-rev-parse.c     |    7 +---
 src/ostree/ot-builtin-show.c          |    7 +---
 src/ostree/ot-builtin-trivial-httpd.c |    2 +-
 src/ostree/ot-builtin-write-refs.c    |    7 +---
 src/ostree/ot-builtins.h              |    4 +-
 src/ostree/ot-main.c                  |   56 +++++++++++++++++---------------
 src/ostree/ot-main.h                  |    7 ++--
 27 files changed, 98 insertions(+), 139 deletions(-)
---
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index d88a388..51c833d 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -207,11 +207,44 @@ ostree_repo_init (OstreeRepo *self)
   g_mutex_init (&self->txn_stats_lock);
 }
 
+/**
+ * ostree_repo_new:
+ * @path: Path to a repository
+ *
+ * Returns: (transfer full): An accessor object for an OSTree repository located at @path
+ */
 OstreeRepo*
 ostree_repo_new (GFile *path)
 {
   return g_object_new (OSTREE_TYPE_REPO, "path", path, NULL);
 }
+
+/**
+ * ostree_repo_new_default:
+ *
+ * If the current working directory appears to be an OSTree
+ * repository, create a new #OstreeRepo object for accessing it.
+ * Otherwise, use the default system repository located at
+ * /ostree/repo.
+ *
+ * Returns: (transfer full): An accessor object for an OSTree repository located at /ostree/repo
+ */
+OstreeRepo*
+ostree_repo_new_default (void)
+{
+  if (g_file_test ("objects", G_FILE_TEST_IS_DIR)
+      && g_file_test ("config", G_FILE_TEST_IS_REGULAR))
+    {
+      gs_unref_object GFile *cwd = g_file_new_for_path (".");
+      return ostree_repo_new (cwd);
+    }
+  else
+    {
+      gs_unref_object GFile *default_repo_path = g_file_new_for_path ("/ostree/repo");
+      return ostree_repo_new (default_repo_path);
+    }
+}
+
 /**
  * ostree_repo_get_config:
  * @self:
@@ -326,7 +359,7 @@ ostree_repo_check (OstreeRepo *self, GError **error)
 
   if (!g_file_test (gs_file_get_path_cached (self->objects_dir), G_FILE_TEST_IS_DIR))
     {
-      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
                    "Couldn't find objects directory '%s'",
                    gs_file_get_path_cached (self->objects_dir));
       goto out;
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 9562f30..73637c1 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -37,6 +37,8 @@ GType ostree_repo_get_type (void);
 
 OstreeRepo* ostree_repo_new (GFile *path);
 
+OstreeRepo* ostree_repo_new_default (void);
+
 gboolean      ostree_repo_check (OstreeRepo  *self, GError **error);
 
 GFile *       ostree_repo_get_path (OstreeRepo  *self);
diff --git a/src/ostree/main.c b/src/ostree/main.c
index ae0e3ce..b7d4024 100644
--- a/src/ostree/main.c
+++ b/src/ostree/main.c
@@ -39,7 +39,7 @@ static OstreeCommand commands[] = {
   { "checksum", ostree_builtin_checksum, OSTREE_BUILTIN_FLAG_NO_REPO },
   { "diff", ostree_builtin_diff, 0 },
   { "fsck", ostree_builtin_fsck, 0 },
-  { "init", ostree_builtin_init, 0 },
+  { "init", ostree_builtin_init, OSTREE_BUILTIN_FLAG_NO_CHECK },
   { "log", ostree_builtin_log, 0 },
   { "ls", ostree_builtin_ls, 0 },
   { "refs", ostree_builtin_refs, 0 },
diff --git a/src/ostree/ot-builtin-admin.c b/src/ostree/ot-builtin-admin.c
index 16d633e..e6ea3e9 100644
--- a/src/ostree/ot-builtin-admin.c
+++ b/src/ostree/ot-builtin-admin.c
@@ -50,7 +50,7 @@ static OstreeAdminCommand admin_subcommands[] = {
 };
 
 gboolean
-ostree_builtin_admin (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_admin (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   gboolean ret = FALSE;
   const char *opt_sysroot = "/";
diff --git a/src/ostree/ot-builtin-cat.c b/src/ostree/ot-builtin-cat.c
index eac3a28..b95ea27 100644
--- a/src/ostree/ot-builtin-cat.c
+++ b/src/ostree/ot-builtin-cat.c
@@ -55,13 +55,12 @@ cat_one_file (GFile         *f,
 }
 
 gboolean
-ostree_builtin_cat (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_cat (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
   int i;
   const char *rev;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_unref_object GOutputStream *stdout_stream = NULL;
   gs_unref_object GFile *root = NULL;
   gs_unref_object GFile *f = NULL;
@@ -72,10 +71,6 @@ ostree_builtin_cat (int argc, char **argv, GFile *repo_path, GCancellable *cance
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc <= 2)
     {
       ot_util_usage_error (context, "An COMMIT and at least one PATH argument are required", error);
diff --git a/src/ostree/ot-builtin-checkout.c b/src/ostree/ot-builtin-checkout.c
index 136df30..2bf26e2 100644
--- a/src/ostree/ot-builtin-checkout.c
+++ b/src/ostree/ot-builtin-checkout.c
@@ -171,13 +171,12 @@ process_many_checkouts (OstreeRepo         *repo,
 }
 
 gboolean
-ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_checkout (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
   const char *commit;
   const char *destination;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_free char *existing_commit = NULL;
   gs_free char *resolved_commit = NULL;
   gs_free char *tmp_destination = NULL;
@@ -192,10 +191,6 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GCancellable *
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc < 2)
     {
       gchar *help = g_option_context_get_help (context, TRUE, NULL);
diff --git a/src/ostree/ot-builtin-checksum.c b/src/ostree/ot-builtin-checksum.c
index cb61932..c210c50 100644
--- a/src/ostree/ot-builtin-checksum.c
+++ b/src/ostree/ot-builtin-checksum.c
@@ -56,7 +56,7 @@ on_checksum_received (GObject    *obj,
 }
 
 gboolean
-ostree_builtin_checksum (int argc, char **argv, GFile *repo_path_path, GCancellable *cancellable, GError 
**error)
+ostree_builtin_checksum (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 6fffc39..7558ef4 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -135,7 +135,7 @@ commit_filter (OstreeRepo         *self,
 }
 
 gboolean
-ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_commit (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
@@ -146,7 +146,6 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *ca
   guint content_total = 0;
   guint content_written = 0;
   guint64 content_bytes_written = 0;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_unref_object GFile *arg = NULL;
   gs_free char *parent = NULL;
   gs_free char *commit_checksum = NULL;
@@ -173,10 +172,6 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GCancellable *ca
         goto out;
     }
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (!opt_branch)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
diff --git a/src/ostree/ot-builtin-config.c b/src/ostree/ot-builtin-config.c
index 17707ee..56ddf86 100644
--- a/src/ostree/ot-builtin-config.c
+++ b/src/ostree/ot-builtin-config.c
@@ -52,14 +52,13 @@ split_key_string (const char   *k,
 }
 
 gboolean
-ostree_builtin_config (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_config (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context = NULL;
   gboolean ret = FALSE;
   const char *op;
   const char *section_key;
   const char *value;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_free char *section = NULL;
   gs_free char *key = NULL;
   GKeyFile *config = NULL;
@@ -70,10 +69,6 @@ ostree_builtin_config (int argc, char **argv, GFile *repo_path, GCancellable *ca
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc < 2)
     {
       ot_util_usage_error (context, "OPERATION must be specified", error);
diff --git a/src/ostree/ot-builtin-diff.c b/src/ostree/ot-builtin-diff.c
index 7abe071..7bd772c 100644
--- a/src/ostree/ot-builtin-diff.c
+++ b/src/ostree/ot-builtin-diff.c
@@ -115,13 +115,12 @@ object_set_total_size (OstreeRepo    *repo,
 }
 
 gboolean
-ostree_builtin_diff (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_diff (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   gboolean ret = FALSE;
   GOptionContext *context;
   const char *src;
   const char *target;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_free char *src_prev = NULL;
   gs_unref_object GFile *srcf = NULL;
   gs_unref_object GFile *targetf = NULL;
@@ -135,10 +134,6 @@ ostree_builtin_diff (int argc, char **argv, GFile *repo_path, GCancellable *canc
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc < 2)
     {
       gchar *help = g_option_context_get_help (context, TRUE, NULL);
diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c
index f7c7b33..77720da 100644
--- a/src/ostree/ot-builtin-fsck.c
+++ b/src/ostree/ot-builtin-fsck.c
@@ -234,14 +234,13 @@ fsck_reachable_objects_from_commits (OstreeRepo            *repo,
 }
 
 gboolean
-ostree_builtin_fsck (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_fsck (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   gboolean ret = FALSE;
   GOptionContext *context;
   GHashTableIter hash_iter;
   gpointer key, value;
   gboolean found_corruption = FALSE;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_unref_hashtable GHashTable *objects = NULL;
   gs_unref_hashtable GHashTable *commits = NULL;
 
@@ -251,10 +250,6 @@ ostree_builtin_fsck (int argc, char **argv, GFile *repo_path, GCancellable *canc
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (!opt_quiet)
     g_print ("Enumerating objects...\n");
 
diff --git a/src/ostree/ot-builtin-init.c b/src/ostree/ot-builtin-init.c
index 01421ae..acfa928 100644
--- a/src/ostree/ot-builtin-init.c
+++ b/src/ostree/ot-builtin-init.c
@@ -38,14 +38,14 @@ static GOptionEntry options[] = {
 
 
 gboolean
-ostree_builtin_init (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_init (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context = NULL;
   gboolean ret = FALSE;
   const char *mode_str = "bare";
+  GFile *repo_path = NULL;
   gs_unref_object GFile *child = NULL;
   gs_unref_object GFile *grandchild = NULL;
-  gs_unref_object OstreeRepo *repo = NULL;
   GString *config_data = NULL;
 
   context = g_option_context_new ("- Initialize a new empty repository");
@@ -54,6 +54,8 @@ ostree_builtin_init (int argc, char **argv, GFile *repo_path, GCancellable *canc
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
+  repo_path = ostree_repo_get_path (repo);
+
   child = g_file_get_child (repo_path, "config");
 
   config_data = g_string_new (DEFAULT_CONFIG_CONTENTS);
@@ -112,7 +114,6 @@ ostree_builtin_init (int argc, char **argv, GFile *repo_path, GCancellable *canc
   if (!g_file_make_directory (child, NULL, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
   if (!ostree_repo_check (repo, error))
     goto out;
 
diff --git a/src/ostree/ot-builtin-log.c b/src/ostree/ot-builtin-log.c
index a79fcca..0ab134c 100644
--- a/src/ostree/ot-builtin-log.c
+++ b/src/ostree/ot-builtin-log.c
@@ -62,14 +62,13 @@ out:
 gboolean
 ostree_builtin_log (int           argc,
                     char        **argv,
-                    GFile        *repo_path,
+                    OstreeRepo   *repo,
                     GCancellable *cancellable,
                     GError      **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
   const char *rev;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_free char *checksum = NULL;
   OstreeDumpFlags flags = OSTREE_DUMP_NONE;
 
@@ -79,10 +78,6 @@ ostree_builtin_log (int           argc,
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (opt_raw)
     flags |= OSTREE_DUMP_RAW;
 
diff --git a/src/ostree/ot-builtin-ls.c b/src/ostree/ot-builtin-ls.c
index 6d8423e..105edfb 100644
--- a/src/ostree/ot-builtin-ls.c
+++ b/src/ostree/ot-builtin-ls.c
@@ -239,11 +239,10 @@ print_one_argument (OstreeRepo   *repo,
 }
 
 gboolean
-ostree_builtin_ls (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_ls (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
-  gs_unref_object OstreeRepo *repo = NULL;
   const char *rev;
   int i;
   gs_unref_object GFile *root = NULL;
@@ -256,10 +255,6 @@ ostree_builtin_ls (int argc, char **argv, GFile *repo_path, GCancellable *cancel
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc <= 1)
     {
       ot_util_usage_error (context, "An COMMIT argument is required", error);
diff --git a/src/ostree/ot-builtin-prune.c b/src/ostree/ot-builtin-prune.c
index 6e2f074..c61e41e 100644
--- a/src/ostree/ot-builtin-prune.c
+++ b/src/ostree/ot-builtin-prune.c
@@ -38,11 +38,10 @@ static GOptionEntry options[] = {
 };
 
 gboolean
-ostree_builtin_prune (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_prune (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   gboolean ret = FALSE;
   GOptionContext *context;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_free char *formatted_freed_size = NULL;
   OstreeRepoPruneFlags pruneflags = 0;
   gint n_objects_total;
@@ -55,10 +54,6 @@ ostree_builtin_prune (int argc, char **argv, GFile *repo_path, GCancellable *can
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (opt_refs_only)
     pruneflags |= OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY;
   if (opt_no_prune)
diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c
index 23319cf..a2e6755 100644
--- a/src/ostree/ot-builtin-pull-local.c
+++ b/src/ostree/ot-builtin-pull-local.c
@@ -154,7 +154,7 @@ idle_print_status (gpointer user_data)
 }
 
 gboolean
-ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError 
**error)
+ostree_builtin_pull_local (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError 
**error)
 {
   gboolean ret = FALSE;
   GOptionContext *context;
@@ -182,9 +182,7 @@ ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GCancellable
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  data->dest_repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (data->dest_repo, error))
-    goto out;
+  data->dest_repo = g_object_ref (repo);
 
   if (argc < 2)
     {
diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c
index 797778d..630301e 100644
--- a/src/ostree/ot-builtin-pull.c
+++ b/src/ostree/ot-builtin-pull.c
@@ -31,13 +31,12 @@ static GOptionEntry options[] = {
 };
 
 gboolean
-ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_pull (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
   const char *remote;
   OstreeRepoPullFlags pullflags = 0;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_unref_ptrarray GPtrArray *refs_to_fetch = NULL;
 
   context = g_option_context_new ("REMOTE [BRANCH...] - Download data from remote repository");
@@ -46,10 +45,6 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GCancellable *canc
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc < 2)
     {
       ot_util_usage_error (context, "REMOTE must be specified", error);
diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c
index 972afe3..99a9333 100644
--- a/src/ostree/ot-builtin-refs.c
+++ b/src/ostree/ot-builtin-refs.c
@@ -34,12 +34,11 @@ static GOptionEntry options[] = {
 };
 
 gboolean
-ostree_builtin_refs (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_refs (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   gboolean ret = FALSE;
   GOptionContext *context;
   const char *refspec_prefix = NULL;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_unref_hashtable GHashTable *refs = NULL;
   GHashTableIter hashiter;
   gpointer hashkey, hashvalue;
@@ -50,10 +49,6 @@ ostree_builtin_refs (int argc, char **argv, GFile *repo_path, GCancellable *canc
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc >= 2)
     refspec_prefix = argv[1];
 
diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c
index 76a63a3..98a8b4b 100644
--- a/src/ostree/ot-builtin-remote.c
+++ b/src/ostree/ot-builtin-remote.c
@@ -41,13 +41,12 @@ usage_error (GOptionContext *context, const char *message, GError **error)
 }
 
 gboolean
-ostree_builtin_remote (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
   const char *op;
   guint i;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_unref_ptrarray GPtrArray *branches = NULL;
   GKeyFile *config = NULL;
 
@@ -57,10 +56,6 @@ ostree_builtin_remote (int argc, char **argv, GFile *repo_path, GCancellable *ca
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc < 2)
     {
       usage_error (context, "OPERATION must be specified", error);
diff --git a/src/ostree/ot-builtin-reset.c b/src/ostree/ot-builtin-reset.c
index 44e0450..b307f35 100644
--- a/src/ostree/ot-builtin-reset.c
+++ b/src/ostree/ot-builtin-reset.c
@@ -83,7 +83,7 @@ out:
 gboolean
 ostree_builtin_reset (int           argc,
                       char        **argv,
-                      GFile        *repo_path,
+                      OstreeRepo   *repo,
                       GCancellable *cancellable,
                       GError      **error)
 {
@@ -91,7 +91,6 @@ ostree_builtin_reset (int           argc,
   gboolean ret = FALSE;
   const char *ref;
   const char *target = NULL;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_free gchar *current = NULL;
   gs_free gchar *checksum = NULL;
 
@@ -101,10 +100,6 @@ ostree_builtin_reset (int           argc,
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc <= 2)
     {
       ot_util_usage_error (context, "A ref and commit argument is required", error);
diff --git a/src/ostree/ot-builtin-rev-parse.c b/src/ostree/ot-builtin-rev-parse.c
index a1349a6..ffd5c78 100644
--- a/src/ostree/ot-builtin-rev-parse.c
+++ b/src/ostree/ot-builtin-rev-parse.c
@@ -31,13 +31,12 @@ static GOptionEntry options[] = {
 };
 
 gboolean
-ostree_builtin_rev_parse (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_rev_parse (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
   const char *rev = "master";
   int i;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_free char *resolved_rev = NULL;
   gs_unref_variant GVariant *variant = NULL;
   gs_free char *formatted_variant = NULL;
@@ -48,10 +47,6 @@ ostree_builtin_rev_parse (int argc, char **argv, GFile *repo_path, GCancellable
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc < 2)
     {
       ot_util_usage_error (context, "REV must be specified", error);
diff --git a/src/ostree/ot-builtin-show.c b/src/ostree/ot-builtin-show.c
index 91d2b43..b7f2138 100644
--- a/src/ostree/ot-builtin-show.c
+++ b/src/ostree/ot-builtin-show.c
@@ -178,12 +178,11 @@ print_if_found (OstreeRepo        *repo,
 }
 
 gboolean
-ostree_builtin_show (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error)
+ostree_builtin_show (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
   const char *rev;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_free char *resolved_rev = NULL;
 
   context = g_option_context_new ("OBJECT - Output a metadata object");
@@ -192,10 +191,6 @@ ostree_builtin_show (int argc, char **argv, GFile *repo_path, GCancellable *canc
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   if (argc <= 1)
     {
       ot_util_usage_error (context, "An object argument is required", error);
diff --git a/src/ostree/ot-builtin-trivial-httpd.c b/src/ostree/ot-builtin-trivial-httpd.c
index 9607f4d..60e2ac8 100644
--- a/src/ostree/ot-builtin-trivial-httpd.c
+++ b/src/ostree/ot-builtin-trivial-httpd.c
@@ -279,7 +279,7 @@ on_dir_changed (GFileMonitor  *mon,
 }
 
 gboolean
-ostree_builtin_trivial_httpd (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError 
**error)
+ostree_builtin_trivial_httpd (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError 
**error)
 {
   gboolean ret = FALSE;
   GOptionContext *context;
diff --git a/src/ostree/ot-builtin-write-refs.c b/src/ostree/ot-builtin-write-refs.c
index b744d42..48b3da7 100644
--- a/src/ostree/ot-builtin-write-refs.c
+++ b/src/ostree/ot-builtin-write-refs.c
@@ -34,13 +34,12 @@ static GOptionEntry options[] = {
 };
 
 gboolean
-ostree_builtin_write_refs (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError 
**error)
+ostree_builtin_write_refs (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError 
**error)
 {
   GOptionContext *context;
   gboolean ret = FALSE;
   GError *temp_error = NULL;
   gsize len;
-  gs_unref_object OstreeRepo *repo = NULL;
   gs_unref_object GInputStream *instream = NULL;
   gs_unref_object GDataInputStream *datastream = NULL;
   gs_free char *line = NULL;
@@ -51,10 +50,6 @@ ostree_builtin_write_refs (int argc, char **argv, GFile *repo_path, GCancellable
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  repo = ostree_repo_new (repo_path);
-  if (!ostree_repo_check (repo, error))
-    goto out;
-
   instream = (GInputStream*)g_unix_input_stream_new (0, FALSE);
   datastream = g_data_input_stream_new (instream);
 
diff --git a/src/ostree/ot-builtins.h b/src/ostree/ot-builtins.h
index 2231150..cbd7847 100644
--- a/src/ostree/ot-builtins.h
+++ b/src/ostree/ot-builtins.h
@@ -22,11 +22,11 @@
 
 #pragma once
 
-#include <gio/gio.h>
+#include "ostree.h"
 
 G_BEGIN_DECLS
 
-#define BUILTINPROTO(name) gboolean ostree_builtin_ ## name (int argc, char **argv, GFile *repo_path, 
GCancellable *cancellable, GError **error)
+#define BUILTINPROTO(name) gboolean ostree_builtin_ ## name (int argc, char **argv, OstreeRepo *repo, 
GCancellable *cancellable, GError **error)
 
 BUILTINPROTO(admin);
 BUILTINPROTO(cat);
diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c
index 6f751c7..9e1b4fa 100644
--- a/src/ostree/ot-main.c
+++ b/src/ostree/ot-main.c
@@ -26,6 +26,7 @@
 
 #include <string.h>
 
+#include "ostree.h"
 #include "ot-main.h"
 #include "otutil.h"
 #include "libgsystem.h"
@@ -77,10 +78,9 @@ ostree_run (int    argc,
   OstreeCommand *command;
   GError *error = NULL;
   GCancellable *cancellable = NULL;
+  gs_unref_object OstreeRepo *repo = NULL;
   const char *cmd = NULL;
-  const char *repo = NULL;
-  const char *host_repo_path = "/ostree/repo";
-  GFile *repo_file = NULL;
+  const char *repo_arg = NULL;
   gboolean want_help = FALSE;
   gboolean skip;
   int in, out, i;
@@ -128,13 +128,13 @@ ostree_run (int    argc,
             }
           else if (g_str_equal (argv[in], "--repo") && in + 1 < argc)
             {
-              repo = argv[in + 1];
+              repo_arg = argv[in + 1];
               skip = TRUE;
               in++;
             }
           else if (g_str_has_prefix (argv[in], "--repo="))
             {
-              repo = argv[in] + 7;
+              repo_arg = argv[in] + 7;
               skip = TRUE;
             }
           else if (g_str_equal (argv[in], "--verbose"))
@@ -219,38 +219,42 @@ ostree_run (int    argc,
 
   g_set_prgname (g_strdup_printf ("ostree %s", cmd));
 
-  if (repo == NULL && !want_help &&
+  if (repo_arg == NULL && !want_help &&
       !(command->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
     {
-      if (g_file_test ("objects", G_FILE_TEST_IS_DIR)
-          && g_file_test ("config", G_FILE_TEST_IS_REGULAR))
+      GError *temp_error = NULL;
+      repo = ostree_repo_new_default ();
+      if (!ostree_repo_check (repo, &temp_error))
         {
-          g_debug ("Assuming repo is in current directory");
-          repo = ".";
-        }
-      else if (g_file_test (host_repo_path, G_FILE_TEST_EXISTS))
-        {
-          g_debug ("Assuming repo is at: %s", host_repo_path);
-          repo = host_repo_path;
+          if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+            {
+              g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                                   "Command requires a --repo argument");
+              g_error_free (temp_error);
+              ostree_usage (argv, commands, TRUE);
+            }
+          else
+            {
+              g_propagate_error (&error, temp_error);
+            }
+          goto out;
         }
-      else
+    }
+  else if (repo_arg)
+    {
+      gs_unref_object GFile *repo_file = g_file_new_for_path (repo_arg);
+      repo = ostree_repo_new (repo_file);
+      if (!(command->flags & OSTREE_BUILTIN_FLAG_NO_CHECK))
         {
-          g_debug ("Could not automatically determine --repo");
-          g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                               "Command requires a --repo argument");
-          ostree_usage (argv, commands, TRUE);
-          goto out;
+          if (!ostree_repo_check (repo, &error))
+            goto out;
         }
     }
-
-  if (repo)
-    repo_file = g_file_new_for_path (repo);
   
-  if (!command->fn (argc, argv, repo_file, cancellable, &error))
+  if (!command->fn (argc, argv, repo, cancellable, &error))
     goto out;
 
  out:
-  g_clear_object (&repo_file);
   if (error)
     {
       g_propagate_error (res_error, error);
diff --git a/src/ostree/ot-main.h b/src/ostree/ot-main.h
index 41adee4..f137186 100644
--- a/src/ostree/ot-main.h
+++ b/src/ostree/ot-main.h
@@ -22,16 +22,17 @@
 
 #pragma once
 
-#include <gio/gio.h>
+#include "ostree.h"
 
 typedef enum {
   OSTREE_BUILTIN_FLAG_NONE = 0,
-  OSTREE_BUILTIN_FLAG_NO_REPO = 1,
+  OSTREE_BUILTIN_FLAG_NO_REPO = 1 << 0,
+  OSTREE_BUILTIN_FLAG_NO_CHECK = 1 << 1
 } OstreeBuiltinFlags;
 
 typedef struct {
   const char *name;
-  gboolean (*fn) (int argc, char **argv, GFile *repo_path, GCancellable *cancellable, GError **error);
+  gboolean (*fn) (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error);
   int flags; /* OstreeBuiltinFlags */
 } OstreeCommand;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]