From 8f5e9ec7e00fbbc34da1eccf0c734710a2bf8f10 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 14 Oct 2020 03:38:25 +0200 Subject: [PATCH] Add timeout parameter to update_cached_repo(). --- src/git.cpp | 5 ++--- src/git.hpp | 12 +++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/git.cpp b/src/git.cpp index c9f5c05..ffc6ef9 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -48,7 +48,6 @@ using std::runtime_error; using std::string; using std::string_view; using std::to_string; -using std::uint64_t; using std::uint8_t; using std::this_thread::sleep_for; @@ -218,10 +217,10 @@ string get_branch_name() return "web-" + to_string(id); } -void update_cached_repo() +void update_cached_repo(const uint8_t timeout) { bool lock_created{false}; - for (uint8_t counter{0}; counter < 20; ++counter) + for (uint8_t counter{0}; counter < timeout; ++counter) { if ((lock_created = files::create_lockfile())) { diff --git a/src/git.hpp b/src/git.hpp index 081ef87..af5ab05 100644 --- a/src/git.hpp +++ b/src/git.hpp @@ -28,7 +28,7 @@ namespace FediBlock::git { using std::string; -using std::uint64_t; +using std::uint8_t; /*! * @brief Initialize libgit and _repo_dir. @@ -75,8 +75,14 @@ void push(); // Get the name of the branch we use. string get_branch_name(); -// If cached repo exist, pull. If not, clone. -void update_cached_repo(); +/*! + * @brief If cached repo exist, pull --force. If not, clone. + * + * @param timeout Try to create lockfile for this many seconds. Default is 20. + * + * @since 0.1.0 + */ +void update_cached_repo(uint8_t timeout = 20); } // namespace FediBlock::git