summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-11-19 22:36:58 -0500
committerDan Davison <dandavison7@gmail.com>2021-11-21 12:27:51 -0500
commit7a64fa5a26314c05c811d7c1276388a4963fa0bd (patch)
tree93ff93311268e67c7d7d0ee785ea796f7f02c4bc
parentdf58ef0c68252a2d5be26ef6aba486e9b0696b35 (diff)
Support custom styles in delta gitconfig
-rw-r--r--src/parse_styles.rs35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/parse_styles.rs b/src/parse_styles.rs
index d87e0585..538b333a 100644
--- a/src/parse_styles.rs
+++ b/src/parse_styles.rs
@@ -2,7 +2,6 @@ use std::collections::{HashMap, HashSet};
use crate::cli;
use crate::color;
-#[cfg(not(test))]
use crate::fatal;
use crate::git_config::GitConfigEntry;
use crate::style::{self, Style};
@@ -47,10 +46,13 @@ pub fn parse_styles(opt: &cli::Opt) -> HashMap<String, Style> {
_ => *style::GIT_DEFAULT_PLUS_STYLE,
}),
);
- resolve_style_references(styles)
+ resolve_style_references(styles, opt)
}
-fn resolve_style_references(edges: HashMap<&str, StyleReference>) -> HashMap<String, Style> {
+fn resolve_style_references(
+ edges: HashMap<&str, StyleReference>,
+ opt: &cli::Opt,
+) -> HashMap<String, Style> {
let mut resolved_styles = HashMap::new();
for starting_node in edges.keys() {
@@ -69,12 +71,27 @@ fn resolve_style_references(edges: HashMap<&str, StyleReference>) -> HashMap<Str
.map(|(a, b)| (a.to_string(), *b))
.collect();
}
- match &edges[&node] {
- StyleReference::Style(style) => {
+ match &edges.get(&node) {
+ Some(StyleReference::Reference(child_node)) => node = child_node,
+ Some(StyleReference::Style(style)) => {
resolved_styles.extend(visited.iter().map(|node| (node.to_string(), *style)));
break;
}
- StyleReference::Reference(child_node) => node = child_node,
+ None => {
+ if let Some(git_config) = &opt.git_config {
+ match git_config.get::<String>(&format!("delta.{}", node)) {
+ Some(s) => {
+ let style = Style::from_git_str(&s);
+ resolved_styles
+ .extend(visited.iter().map(|node| (node.to_string(), style)));
+ break;
+ }
+ _ => fatal(format!("Style not found: {}", node)),
+ }
+ } else {
+ fatal(format!("Style not found: {}", node));
+ }
+ }
}
}
}
@@ -347,6 +364,12 @@ fn style_from_str_with_handling_of_special_decoration_attributes_and_respecting_
#[cfg(test)]
mod tests {
use super::*;
+ use crate::tests::integration_test_utils;
+
+ fn resolve_style_references(edges: HashMap<&str, StyleReference>) -> HashMap<String, Style> {
+ let opt = integration_test_utils::make_options_from_args(&[]);
+ super::resolve_style_references(edges, &opt)
+ }
#[test]
fn test_resolve_style_references_1() {