From 25fe57605277afc1f98439a5419a808d9759e7b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Sun, 2 Jul 2023 09:49:38 +0200 Subject: [PATCH] fix!: fixed quick, fast messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed quick fast messages by "leaking" the memory for the input effectively makiing it static. This feel extremely hacky, and should never be used in a loop. Consider this temporary until I find a better way, and or smart enough people to tell me it's not as bad as I feel it is. ...Sorry Djikstra. Signed-off-by: Christina Sørensen --- doc/roadmap.org | 6 ++++-- src/git.rs | 10 +++------- src/main.rs | 22 +++++++++++++++++----- src/test/test.yaml | 34 +++++++++++++++++----------------- src/utils/strings.rs | 7 +++++-- 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/doc/roadmap.org b/doc/roadmap.org index 14f3c2e..5f9a02c 100644 --- a/doc/roadmap.org +++ b/doc/roadmap.org @@ -1,12 +1,14 @@ #+title: Roadmap -* Roadmap +* Roadmap [0%] [0/4] - [ ] Custom operation sequences - [ ] Generic repositories - [ ] Version pinning - [ ] libgit2 (maybe) -* 0.1.0 +* 0.1.0 [0%] [0/5] - [-] No functionality regressions + - [X] commit works in quick, fast + - [-] commit with edit works - [ ] Repo Flags Finished - [ ] Category Flags Finished - [ ] Optional Fields diff --git a/src/git.rs b/src/git.rs index 6d137a7..ad5e15a 100644 --- a/src/git.rs +++ b/src/git.rs @@ -437,8 +437,6 @@ impl Config { } /// Tries to pull, add all, commit with msg "quick commit", and push all /// repositories, skips if fail. - /// - /// FIXME currently msg isn't used pub fn quick(&self, msg: &'static str) { debug!("exectuting quick"); let series: Vec = vec![ @@ -453,7 +451,7 @@ impl Config { SeriesItem { operation: "commit", closure: Box::new(move |repo: &GitRepo| repo.commit_with_msg(msg)), - }, // FIXME doesn't take msg + }, SeriesItem { operation: "push", closure: Box::new(move |repo: &GitRepo| repo.push()), @@ -463,9 +461,7 @@ impl Config { } /// Tries to pull, add all, commit with msg "quick commit", and push all /// repositories, skips if fail. - /// - /// FIXME currently msg isn't used - pub fn fast(&self, msg: &str) { + pub fn fast(&self, msg: &'static str) { debug!("exectuting fast"); let series: Vec = vec![ SeriesItem { @@ -479,7 +475,7 @@ impl Config { SeriesItem { operation: "commit", closure: Box::new(move |repo: &GitRepo| repo.commit()), - }, // FIXME doesn't take msg + }, SeriesItem { operation: "push", closure: Box::new(move |repo: &GitRepo| repo.push()), diff --git a/src/main.rs b/src/main.rs index 82014f3..68d6816 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ mod utils; use cli::{Args, Commands}; use git::Config; -use utils::strings::QUICK_COMMIT; +use utils::strings::{FAST_COMMIT, QUICK_COMMIT}; use clap::Parser; @@ -56,7 +56,7 @@ use log::{debug, error, info, trace, warn}; /// to the relavant operations. fn main() { pretty_env_logger::init(); - let args = Args::parse(); + let mut args = Args::parse(); let config = Config::new(&args.config); match &args { args if args.license => println!("{}", utils::strings::INTERACTIVE_LICENSE), @@ -64,15 +64,27 @@ fn main() { args if args.code_of_conduct => unimplemented!(), _ => (), } - match &args.command { + match &mut args.command { Some(Commands::Link { msg: _ }) => { config.link_all(); } Some(Commands::Quick { msg }) => { - config.quick(QUICK_COMMIT); + let s = Box::leak( + msg.as_mut() + .get_or_insert(&mut QUICK_COMMIT.to_string()) + .clone() + .into_boxed_str(), + ); + config.quick(s); } Some(Commands::Fast { msg }) => { - config.fast(msg.as_ref().get_or_insert(&"gg: fast commit".to_string())); + let s = Box::leak( + msg.as_mut() + .get_or_insert(&mut FAST_COMMIT.to_string()) + .clone() + .into_boxed_str(), + ); + config.fast(s); } Some(Commands::Clone { msg: _ }) => { config.clone_all(); diff --git a/src/test/test.yaml b/src/test/test.yaml index 6f7679f..ca79c57 100644 --- a/src/test/test.yaml +++ b/src/test/test.yaml @@ -1,4 +1,21 @@ categories: + utils: + flags: [] + repos: + li: + name: li + path: /home/ces/org/src/git/ + url: git@github.com:cafkafk/li.git + flags: + - Clone + - Push + gg: + name: gg + path: /home/ces/.dots/ + url: git@github.com:cafkafk/gg.git + flags: + - Clone + - Push config: flags: [] repos: @@ -16,23 +33,6 @@ categories: flags: - Clone - Push - utils: - flags: [] - repos: - gg: - name: gg - path: /home/ces/.dots/ - url: git@github.com:cafkafk/gg.git - flags: - - Clone - - Push - li: - name: li - path: /home/ces/org/src/git/ - url: git@github.com:cafkafk/li.git - flags: - - Clone - - Push links: - name: gg rx: /home/ces/.config/gg diff --git a/src/utils/strings.rs b/src/utils/strings.rs index 1df5fd1..75d7bba 100644 --- a/src/utils/strings.rs +++ b/src/utils/strings.rs @@ -46,5 +46,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. "; -/// Contains the message for quick commit subcommit -pub const QUICK_COMMIT: &'static str = "git: quick commit"; +/// Contains the message for quick commit subcommand +pub const QUICK_COMMIT: &str = "git: quick commit"; + +/// Contains the message for fast commit subcommand +pub const FAST_COMMIT: &str = "git: fast commit";