From 55d64756467c0d166c9f8ad1bcf33df4650c351e Mon Sep 17 00:00:00 2001 From: Karl Heitmann Date: Thu, 15 Jun 2023 23:58:23 -0400 Subject: [PATCH 1/3] Uses git-graph.toml to parse commits message format --- src/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 90af35d..dc30698 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,11 @@ use std::time::Instant; const REPO_CONFIG_FILE: &str = "git-graph.toml"; +#[derive(serde_derive::Serialize, serde_derive::Deserialize)] +pub struct CommitFormatToml { + pub format: String, +} + fn main() { std::process::exit(match from_args() { Ok(_) => 0, @@ -289,7 +294,19 @@ fn from_args() -> Result<(), String> { )?; let format = match matches.get_one::("format") { - None => CommitFormat::OneLine, + None => { + let mut config_path = std::path::PathBuf::from(repository.path()); + config_path.push(REPO_CONFIG_FILE); + if config_path.exists() { + let commit_format_toml: CommitFormatToml = toml::from_str( + &std::fs::read_to_string(config_path).map_err(|err| err.to_string())?, + ) + .map_err(|err| err.to_string()).unwrap(); + CommitFormat::from_str(&commit_format_toml.format)? + } else { + CommitFormat::OneLine + } + }, Some(str) => CommitFormat::from_str(str)?, }; From ad439a45a5c9f81a14185627f40a8d92e68a1600 Mon Sep 17 00:00:00 2001 From: Karl Heitmann Date: Fri, 16 Jun 2023 00:25:12 -0400 Subject: [PATCH 2/3] Wraps in Option attributes to prevent to crash if some are missing --- src/config.rs | 10 +++++++--- src/main.rs | 7 +++++-- src/settings.rs | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index fced474..fa595cc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -60,7 +60,7 @@ pub fn get_model_name(repository: &Repository, file_name: &str) -> Result