From 40ed11827573f03f3c4548d69efaddd9598b1ec6 Mon Sep 17 00:00:00 2001 From: Wess Cope Date: Thu, 4 Jan 2018 13:40:27 -0500 Subject: [PATCH] Removing libgit2, and just download list --- CMakeLists.txt | 4 +- src/env/env.h | 3 +- src/git/git.h | 6 --- src/git/repo/repo.cpp | 75 ------------------------------------- src/git/repo/repo.h | 37 ------------------ src/templates/templates.cpp | 34 +++++++++-------- 6 files changed, 20 insertions(+), 139 deletions(-) delete mode 100644 src/git/git.h delete mode 100644 src/git/repo/repo.cpp delete mode 100644 src/git/repo/repo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ddf8a4c..5f8ca37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,6 @@ add_subdirectory(libs) FIND_PACKAGE(LibArchive REQUIRED) FIND_PACKAGE(CURL REQUIRED) -FIND_PACKAGE(Libgit2 REQUIRED) FIND_PACKAGE(YamlCpp REQUIRED) FIND_PACKAGE(Threads REQUIRED) @@ -83,7 +82,6 @@ include_directories( ${CURL_INCLUDE_DIRS} ${LibArchive_INCLUDE_DIRS} ${YAMLCPP_INCLUDE_DIR} - ${LIBGIT2_INCLUDE_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/libs/yaml-cpp ${CMAKE_SOURCE_DIR}/libs/yaml-cpp/include @@ -96,7 +94,7 @@ include_directories( ) add_executable(skafos ${SOURCES}) -target_link_libraries(skafos docopt json11 sse yaml-cpp ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${LIBGIT2_LIBRARIES} ${LibArchive_LIBRARIES} ${YAMLCPP_LIBRARY}) +target_link_libraries(skafos docopt json11 sse yaml-cpp ${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES} ${LibArchive_LIBRARIES} ${YAMLCPP_LIBRARY}) install(TARGETS skafos RUNTIME DESTINATION bin) diff --git a/src/env/env.h b/src/env/env.h index 4bae783..639c920 100644 --- a/src/env/env.h +++ b/src/env/env.h @@ -4,7 +4,6 @@ #include "common.h" #include "file/file.h" #include "request/request.h" -#include "git/git.h" #include "auth/auth.h" #include "templates/templates.h" @@ -14,7 +13,7 @@ const std::string METIS_API_TOKEN = "METIS_API_TOKEN"; const std::string METIS_AUTH_TOKEN = "METIS_OAUTH"; const std::string METIS_CREDENTIALS = "credentials.json"; -const std::string METIS_TEMPLATE_REPO = "https://github.com/MetisMachine/templates.list"; +const std::string METIS_TEMPLATE_REPO = "https://github.com/MetisMachine/templates.list/archive/master.zip"; const std::string METIS_TEMPLATE_DIR = "templates"; const std::string METIS_CACHE_DIR = ".cache"; diff --git a/src/git/git.h b/src/git/git.h deleted file mode 100644 index add6640..0000000 --- a/src/git/git.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __CLI_GIT__ -#define __CLI_GIT__ - -#include "repo/repo.h" - -#endif diff --git a/src/git/repo/repo.cpp b/src/git/repo/repo.cpp deleted file mode 100644 index 8442487..0000000 --- a/src/git/repo/repo.cpp +++ /dev/null @@ -1,75 +0,0 @@ - - -#include "repo.h" - -using namespace std; - -namespace Git { - void Repo::print_progress(const progress_data *pd) { - } - - int Repo::sideband_progress(const char *str, int len, void *payload) { - (void)payload; // unused, callback wants it anyways. - return 0; - } - - int Repo::fetch_progress(const git_transfer_progress *stats, void *payload) { - progress_data *pd = (progress_data*)payload; - pd->fetch_progress = *stats; - - print_progress(pd); - return 0; - } - - void Repo::checkout_progress(const char *path, size_t cur, size_t tot, void *payload) { - progress_data *pd = (progress_data*)payload; - pd->completed_steps = cur; - pd->total_steps = tot; - pd->path = path; - - print_progress(pd); - } - - int Repo::clone(string url, string path) { - git_libgit2_init(); - - progress_data pd = {{0}}; - git_repository *repo = NULL; - git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; - git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; - - checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; - checkout_opts.progress_cb = checkout_progress; - checkout_opts.progress_payload = &pd; - clone_opts.checkout_opts = checkout_opts; - clone_opts.fetch_opts.callbacks.sideband_progress = sideband_progress; - clone_opts.fetch_opts.callbacks.transfer_progress = &fetch_progress; - clone_opts.fetch_opts.callbacks.payload = &pd; - - const char *c_url = url.c_str(); - const char *c_path = path.c_str(); - int error = git_clone(&repo, c_url, c_path, &clone_opts); - - if (error != 0) { - const git_error *err = giterr_last(); - - if (err) { - console::error( - "Error " + - to_string(err->klass) + - ": " + - err->message + - " (" + url + " :: " + path + ")" - ); - } else { - console::error("Error " + to_string(error) + ": no detailed information."); - } - } else if (repo) { - git_repository_free(repo); - } - - git_repository_state_cleanup(repo); - git_libgit2_shutdown(); - return error; - } -} diff --git a/src/git/repo/repo.h b/src/git/repo/repo.h deleted file mode 100644 index 62d46e4..0000000 --- a/src/git/repo/repo.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __CLI_REPO__ -#define __CLI_REPO__ - -#include "common.h" -#include -#include - -#ifndef PRIuZ -/* Define the printf format specifer to use for size_t output */ -#if defined(_MSC_VER) || defined(__MINGW32__) -# define PRIuZ "Iu" -#else -# define PRIuZ "zu" -#endif -#endif - -namespace Git { - typedef struct progress_data { - git_transfer_progress fetch_progress; - size_t completed_steps; - size_t total_steps; - const char *path; - } progress_data; - - class Repo { - private: - static void print_progress(const progress_data *pd); - static int sideband_progress(const char *str, int len, void *payload); - static int fetch_progress(const git_transfer_progress *stats, void *payload); - static void checkout_progress(const char *path, size_t cur, size_t tot, void *payload); - public: - static int clone(std::string url, std::string path); - }; - -} - -#endif diff --git a/src/templates/templates.cpp b/src/templates/templates.cpp index 536855c..e0bc411 100644 --- a/src/templates/templates.cpp +++ b/src/templates/templates.cpp @@ -1,7 +1,6 @@ #include "templates.h" #include "yaml-cpp/yaml.h" #include "env/env.h" -#include "git/git.h" #include "file/file.h" #include @@ -11,16 +10,29 @@ const string TEMPLATE_HEAD = "head"; void Template::update() { VERIFY_AUTH(); + // START_LOADING("Updating project templates.."); - START_LOADING("Updating project templates.."); + console::info("Updating templates..."); if(FileManager::dir_exists(ENV_PATHS.templates)) { - pull(); - } else { - clone(); + FileManager::delete_dir(ENV_PATHS.templates); } - END_LOADING(); + FileManager::create_path(0755, ENV_PATHS.templates); + + string tpl_path = ENV_PATHS.env + "/template_list.zip"; + + console::info( + "Download from: " + + METIS_TEMPLATE_REPO + + " to: " + + tpl_path + ); + + Request::download(METIS_TEMPLATE_REPO, tpl_path); + + + // END_LOADING(); } void Template::search(string name) { @@ -92,16 +104,6 @@ list Template::all() { return tpl_list; } -int Template::clone() { - return Git::Repo::clone(METIS_TEMPLATE_REPO, ENV_PATHS.templates); -} - -int Template::pull() { - FileManager::delete_dir(ENV_PATHS.templates); - - return clone(); -} - TemplateDetails Template::parse_template(std::string path) { TemplateDetails details;