summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKipras Melnikovas <kipras@kipras.org>2024-02-23 04:26:53 +0200
committerKipras Melnikovas <kipras@kipras.org>2024-02-23 05:23:30 +0200
commit468d93b293eee9ff889b9b147a37b001d280ee36 (patch)
tree1b646ceb88431600b7d629a1405c45580dca7d8f
parent656261484570534ac4ce8d373bfea8c32b8910d1 (diff)
refactor git-config utils into config.rs
-rw-r--r--src/config.rs12
-rw-r--r--src/stack.rs24
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,
);