@@ -5,6 +5,7 @@ pub struct RepoConfig {
55 pub protected_branches : Option < Vec < String > > ,
66 pub protect_commit_count : Option < usize > ,
77 pub protect_commit_age : Option < std:: time:: Duration > ,
8+ pub auto_base_commit_count : Option < usize > ,
89 pub stack : Option < Stack > ,
910 pub push_remote : Option < String > ,
1011 pub pull_remote : Option < String > ,
@@ -20,6 +21,7 @@ pub struct RepoConfig {
2021static PROTECTED_STACK_FIELD : & str = "stack.protected-branch" ;
2122static PROTECT_COMMIT_COUNT : & str = "stack.protect-commit-count" ;
2223static PROTECT_COMMIT_AGE : & str = "stack.protect-commit-age" ;
24+ static AUTO_BASE_COMMIT_COUNT : & str = "stack.auto-base-commit-count" ;
2325static STACK_FIELD : & str = "stack.stack" ;
2426static PUSH_REMOTE_FIELD : & str = "stack.push-remote" ;
2527static PULL_REMOTE_FIELD : & str = "stack.pull-remote" ;
@@ -34,6 +36,7 @@ static DEFAULT_PROTECTED_BRANCHES: [&str; 4] = ["main", "master", "dev", "stable
3436static DEFAULT_PROTECT_COMMIT_COUNT : usize = 50 ;
3537static DEFAULT_PROTECT_COMMIT_AGE : std:: time:: Duration =
3638 std:: time:: Duration :: from_secs ( 60 * 60 * 24 * 14 ) ;
39+ static DEFAULT_AUTO_BASE_COMMIT_COUNT : usize = 500 ;
3740const DEFAULT_CAPACITY : usize = 30 ;
3841
3942impl RepoConfig {
@@ -132,6 +135,10 @@ impl RepoConfig {
132135 {
133136 config. protect_commit_age = Some ( value) ;
134137 }
138+ } else if key == AUTO_BASE_COMMIT_COUNT {
139+ if let Some ( value) = value. as_ref ( ) . and_then ( |v| FromStr :: from_str ( v) . ok ( ) ) {
140+ config. auto_base_commit_count = Some ( value) ;
141+ }
135142 } else if key == STACK_FIELD {
136143 if let Some ( value) = value. as_ref ( ) . and_then ( |v| FromStr :: from_str ( v) . ok ( ) ) {
137144 config. stack = Some ( value) ;
@@ -190,6 +197,7 @@ impl RepoConfig {
190197 let mut conf = Self :: default ( ) ;
191198 conf. protect_commit_count = Some ( conf. protect_commit_count ( ) . unwrap_or ( 0 ) ) ;
192199 conf. protect_commit_age = Some ( conf. protect_commit_age ( ) ) ;
200+ conf. auto_base_commit_count = Some ( conf. auto_base_commit_count ( ) . unwrap_or ( 0 ) ) ;
193201 conf. stack = Some ( conf. stack ( ) ) ;
194202 conf. push_remote = Some ( conf. push_remote ( ) . to_owned ( ) ) ;
195203 conf. pull_remote = Some ( conf. pull_remote ( ) . to_owned ( ) ) ;
@@ -240,6 +248,11 @@ impl RepoConfig {
240248 . ok ( )
241249 . and_then ( |s| humantime:: parse_duration ( & s) . ok ( ) ) ;
242250
251+ let auto_base_commit_count = config
252+ . get_i64 ( AUTO_BASE_COMMIT_COUNT )
253+ . ok ( )
254+ . map ( |i| i. max ( 0 ) as usize ) ;
255+
243256 let push_remote = config
244257 . get_string ( PUSH_REMOTE_FIELD )
245258 . ok ( )
@@ -279,6 +292,7 @@ impl RepoConfig {
279292 protected_branches,
280293 protect_commit_count,
281294 protect_commit_age,
295+ auto_base_commit_count,
282296 push_remote,
283297 pull_remote,
284298 stack,
@@ -320,6 +334,7 @@ impl RepoConfig {
320334 }
321335 self . protect_commit_count = other. protect_commit_count . or ( self . protect_commit_count ) ;
322336 self . protect_commit_age = other. protect_commit_age . or ( self . protect_commit_age ) ;
337+ self . auto_base_commit_count = other. auto_base_commit_count . or ( self . auto_base_commit_count ) ;
323338 self . push_remote = other. push_remote . or ( self . push_remote ) ;
324339 self . pull_remote = other. pull_remote . or ( self . pull_remote ) ;
325340 self . stack = other. stack . or ( self . stack ) ;
@@ -349,6 +364,13 @@ impl RepoConfig {
349364 . unwrap_or ( DEFAULT_PROTECT_COMMIT_AGE )
350365 }
351366
367+ pub fn auto_base_commit_count ( & self ) -> Option < usize > {
368+ let auto_base_commit_count = self
369+ . auto_base_commit_count
370+ . unwrap_or ( DEFAULT_AUTO_BASE_COMMIT_COUNT ) ;
371+ ( auto_base_commit_count != 0 ) . then ( || auto_base_commit_count)
372+ }
373+
352374 pub fn push_remote ( & self ) -> & str {
353375 self . push_remote . as_deref ( ) . unwrap_or ( "origin" )
354376 }
@@ -412,6 +434,12 @@ impl std::fmt::Display for RepoConfig {
412434 PROTECT_COMMIT_AGE . split_once( '.' ) . unwrap( ) . 1 ,
413435 humantime:: format_duration( self . protect_commit_age( ) )
414436 ) ?;
437+ writeln ! (
438+ f,
439+ "\t {}={}" ,
440+ AUTO_BASE_COMMIT_COUNT . split_once( '.' ) . unwrap( ) . 1 ,
441+ self . auto_base_commit_count( ) . unwrap_or( 0 )
442+ ) ?;
415443 writeln ! (
416444 f,
417445 "\t {}={}" ,
0 commit comments