From 579d9ea972af7c11bda63cab346c2fdae55f8b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Mon, 17 Jul 2023 10:45:13 +0200 Subject: [PATCH] refactor: started work on generic macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is to help make series operations more generic. This refactor has been needed for a while, and I'm very excited to finally start working on it, but this is just the bare minimum, we still need to handle on a repo type basis. But also, yes, this starts the slow crawl towards generic repos intead of hardcoded functions for each repo type (links, gitrepo) etc Signed-off-by: Christina Sørensen --- src/git.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/git.rs b/src/git.rs index 0721e07..52a51bd 100644 --- a/src/git.rs +++ b/src/git.rs @@ -304,6 +304,30 @@ impl GitRepo { } } +macro_rules! run_series { + ($conf:ident, $closures:ident) => { + for category in $conf.categories.values() { + for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() { + for instruction in &$closures { + let f = &instruction.closure; + let op = instruction.operation; + if !settings::QUIET.load(std::sync::atomic::Ordering::Relaxed) { + let mut sp = + Spinner::new(Spinners::Dots10, format!("{}: {}", repo.name, op)); + if f(repo) { + sp.stop_and_persist(success_str(), format!("{}: {}", repo.name, op)); + } else { + sp.stop_and_persist(failure_str(), format!("{}: {}", repo.name, op)); + } + } else { + f(repo); + } + } + } + } + }; +} + impl Config { /// Loads the configuration toml from a path in to the Config struct. pub fn new(path: &String) -> Self { @@ -602,7 +626,8 @@ impl Config { closure: Box::new(GitRepo::push), }, ]; - self.all_on_all(series); + //self.all_on_all(series); + run_series!(self, series); } /// Tries to pull, add all, commit with msg "quick commit", and push all /// repositories, skips if fail.