fix!: fixed quick, fast messages

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 <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-07-02 09:49:38 +02:00
parent df08a1ca2f
commit 25fe576052
Signed by: cafkafk
GPG key ID: CDDC792F655251ED
5 changed files with 46 additions and 33 deletions

View file

@ -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

View file

@ -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<SeriesItem> = 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<SeriesItem> = 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()),

View file

@ -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();

View file

@ -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

View file

@ -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";