diff options
-rw-r--r-- | src/config.rs | 12 | ||||
-rw-r--r-- | src/stack.rs | 24 |
2 files changed, 20 insertions, 16 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..f88167c --- /dev/null +++ b/src/config.rs @@ -0,0 +1,12 @@ +pub const MAX_STACK_CONFIG_NAME: &str = "absorb.maxStack"; +pub const MAX_STACK: usize = 10; + +pub fn max_stack(repo: &git2::Repository) -> usize { + match repo + .config() + .and_then(|config| config.get_i64(MAX_STACK_CONFIG_NAME)) + { + Ok(max_stack) if max_stack > 0 => max_stack as usize, + _ => MAX_STACK, + } +} diff --git a/src/stack.rs b/src/stack.rs index 47b00dd..503a467 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -2,18 +2,7 @@ use anyhow::{anyhow, Result}; use std::collections::HashMap; -pub const MAX_STACK_CONFIG_NAME: &str = "absorb.maxStack"; -pub const MAX_STACK: usize = 10; - -fn max_stack(repo: &git2::Repository) -> usize { - match repo - .config() - .and_then(|config| config.get_i64(MAX_STACK_CONFIG_NAME)) - { - Ok(max_stack) if max_stack > 0 => max_stack as usize, - _ => MAX_STACK, - } -} +use crate::config; pub fn working_stack<'repo>( repo: &'repo git2::Repository, @@ -87,7 +76,7 @@ pub fn working_stack<'repo>( break; } } - if ret.len() == max_stack(repo) && user_provided_base.is_none() { + if ret.len() == config::max_stack(repo) && user_provided_base.is_none() { warn!(logger, "stack limit reached, use --base or configure absorb.maxStack to override"; "limit" => ret.len()); break; @@ -230,14 +219,17 @@ mod tests { #[test] fn test_stack_stops_at_configured_limit() { let (_dir, repo) = init_repo(); - let commits = empty_commit_chain(&repo, "HEAD", &[], MAX_STACK + 2); + let commits = empty_commit_chain(&repo, "HEAD", &[], config::MAX_STACK + 2); repo.config() .unwrap() - .set_i64(MAX_STACK_CONFIG_NAME, (MAX_STACK + 1) as i64) + .set_i64( + config::MAX_STACK_CONFIG_NAME, + (config::MAX_STACK + 1) as i64, + ) .unwrap(); assert_stack_matches_chain( - MAX_STACK + 1, + config::MAX_STACK + 1, &working_stack(&repo, None, false, &empty_slog()).unwrap(), &commits, ); |