From ba5fc5cbccdde7131a39368a9d444d2f25a10db7 Mon Sep 17 00:00:00 2001 From: Colin Walters <walters@verbum.org> Date: Thu, 30 May 2013 18:32:46 -0400 Subject: [PATCH] Fold ostree-pull into main binary The rationale for the separation was always kind of weak; I want to refactor the command line argument parsing, and it was complicating things. --- Makefile-ostree.am | 12 ++++------ src/ostree/main.c | 42 +-------------------------------- src/ostree/ostree-pull.c | 15 ++---------- src/ostree/ot-admin-functions.c | 2 +- src/ostree/ot-builtins.h | 1 + 5 files changed, 10 insertions(+), 62 deletions(-) diff --git a/Makefile-ostree.am b/Makefile-ostree.am index 6c850710..7825db9b 100644 --- a/Makefile-ostree.am +++ b/Makefile-ostree.am @@ -70,15 +70,13 @@ ostree_CFLAGS = $(ostree_bin_shared_cflags) $(OT_INTERNAL_GIO_UNIX_CFLAGS) ostree_LDADD = $(ostree_bin_shared_ldadd) $(OT_INTERNAL_GIO_UNIX_LIBS) if USE_LIBSOUP -bin_PROGRAMS += ostree-pull -ostree_pull_SOURCES = src/ostree/ot-main.h \ - src/ostree/ot-main.c \ - src/ostree/ostree-fetcher.h \ +ostree_SOURCES += src/ostree/ostree-fetcher.h \ src/ostree/ostree-fetcher.c \ - src/ostree/ostree-pull.c + src/ostree/ostree-pull.c \ + $(NULL) -ostree_pull_CFLAGS = $(ostree_bin_shared_cflags) $(OT_INTERNAL_SOUP_CFLAGS) -ostree_pull_LDADD = $(ostree_bin_shared_ldadd) $(OT_INTERNAL_SOUP_LIBS) +ostree_CFLAGS += $(OT_INTERNAL_SOUP_CFLAGS) +ostree_LDADD += $(OT_INTERNAL_SOUP_LIBS) endif MANPAGES += doc/ostree.1 diff --git a/src/ostree/main.c b/src/ostree/main.c index 8e322411..ff716d0d 100644 --- a/src/ostree/main.c +++ b/src/ostree/main.c @@ -43,7 +43,7 @@ static OstreeCommand commands[] = { { "log", ostree_builtin_log, 0 }, { "ls", ostree_builtin_ls, 0 }, { "prune", ostree_builtin_prune, 0 }, - { "pull", NULL, 0 }, + { "pull", ostree_builtin_pull, 0 }, { "pull-local", ostree_builtin_pull_local, 0 }, { "remote", ostree_builtin_remote, 0 }, { "rev-parse", ostree_builtin_rev_parse, 0 }, @@ -52,40 +52,6 @@ static OstreeCommand commands[] = { { NULL } }; -static int -exec_external (int argc, - char **argv, - GError **error) -{ - gchar *command; - gchar *tmp; - int errn; - - command = g_strdup_printf ("ostree-%s", argv[1]); - - tmp = argv[1]; - argv[1] = command; - - execvp (command, argv + 1); - - errn = errno; - argv[1] = tmp; - g_free (command); - - if (errn == ENOENT) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "Unknown command: '%s'", argv[1]); - } - else - { - g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errn), - "Failed to execute command: %s", g_strerror (errn)); - } - - return 1; -} - int main (int argc, char **argv) @@ -94,12 +60,6 @@ main (int argc, int ret; ret = ostree_run (argc, argv, commands, &error); - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) - { - g_clear_error (&error); - ret = exec_external (argc, argv, &error); - } - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) ostree_usage (argv, commands, TRUE); diff --git a/src/ostree/ostree-pull.c b/src/ostree/ostree-pull.c index 057f09fd..20a025e3 100644 --- a/src/ostree/ostree-pull.c +++ b/src/ostree/ostree-pull.c @@ -70,6 +70,7 @@ #include "ostree.h" #include "ot-main.h" +#include "ot-builtins.h" #include "ostree-fetcher.h" @@ -1170,7 +1171,7 @@ load_remote_repo_config (OtPullData *pull_data, return ret; } -static gboolean +gboolean ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error) { GOptionContext *context; @@ -1469,15 +1470,3 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error) soup_uri_free (summary_uri); return ret; } - -static OstreeCommand commands[] = { - { "pull", ostree_builtin_pull, 0 }, - { NULL } -}; - -int -main (int argc, - char **argv) -{ - return ostree_main (argc, argv, commands); -} diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c index 736c230d..28eb0778 100644 --- a/src/ostree/ot-admin-functions.c +++ b/src/ostree/ot-admin-functions.c @@ -482,7 +482,7 @@ ot_admin_pull (GFile *ostree_dir, return gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir), GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT, cancellable, error, - "ostree", "pull", repo_arg, osname, NULL); + "ostree", repo_arg, "pull", osname, NULL); } void diff --git a/src/ostree/ot-builtins.h b/src/ostree/ot-builtins.h index b3d446ea..0562e82d 100644 --- a/src/ostree/ot-builtins.h +++ b/src/ostree/ot-builtins.h @@ -35,6 +35,7 @@ gboolean ostree_builtin_checksum (int argc, char **argv, GFile *repo_path, GErro gboolean ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_diff (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_init (int argc, char **argv, GFile *repo_path, GError **error); +gboolean ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_log (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_ls (int argc, char **argv, GFile *repo_path, GError **error);