From 1aad7247983c76de7d10790b2aba6f6d26c75438 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Mon, 11 Nov 2024 03:50:45 +0800 Subject: [PATCH] repo: remove `MutableRepo::rebase_descendants_return_map` This function is merely a simple wrapper around `MutableRepo::rebase_descendants_with_options_return_map`. --- lib/src/repo.rs | 22 +-------------------- lib/src/rewrite.rs | 3 ++- lib/tests/test_commit_builder.rs | 6 +++--- lib/tests/test_mut_repo.rs | 6 +++--- lib/tests/test_rewrite.rs | 34 ++++++++++++++++---------------- 5 files changed, 26 insertions(+), 45 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index f10063537a..6ea7dbbd09 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -1289,10 +1289,6 @@ impl MutableRepo { /// tell this case apart since the change ids of the key and the value /// will not match. The parent will inherit the descendants and the /// bookmarks of the abandoned commit. - /// - /// This function is similar to - /// [`MutableRepo::rebase_descendants_return_map`], but allows for - /// rebase behavior to be customized via [`RebaseOptions`]. pub fn rebase_descendants_with_options_return_map( &mut self, settings: &UserSettings, @@ -1321,28 +1317,12 @@ impl MutableRepo { /// /// The descendants of the commits registered in `self.parent_mappings` will /// be recursively rebased onto the new version of their parents. - /// Returns a map of newly rebased commit ID to original commit ID. + /// Returns the number of rebased descendants. /// /// All rebased descendant commits will be preserved even if they were /// emptied following the rebase operation. To customize the rebase /// behavior, use /// [`MutableRepo::rebase_descendants_with_options_return_map`]. - pub fn rebase_descendants_return_map( - &mut self, - settings: &UserSettings, - ) -> BackendResult> { - self.rebase_descendants_with_options_return_map(settings, Default::default()) - } - - /// Rebase descendants of the rewritten commits. - /// - /// The descendants of the commits registered in `self.parent_mappings` will - /// be recursively rebased onto the new version of their parents. - /// Returns the number of rebased descendants. - /// - /// All rebased descendant commits will be preserved even if they were - /// emptied following the rebase operation. To customize the rebase - /// behavior, use [`MutableRepo::rebase_descendants_return_map`]. pub fn rebase_descendants(&mut self, settings: &UserSettings) -> BackendResult { let roots = self.parent_mapping.keys().cloned().collect_vec(); let mut num_rebased = 0; diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 40cd210840..75932c4491 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -919,7 +919,8 @@ where // rewritten sources. Otherwise it will likely already have the content // changes we're moving, so applying them will have no effect and the // changes will disappear. - let rebase_map = repo.rebase_descendants_return_map(settings)?; + let rebase_map = + repo.rebase_descendants_with_options_return_map(settings, Default::default())?; let rebased_destination_id = rebase_map.get(destination.id()).unwrap().clone(); rewritten_destination = repo.store().get_commit(&rebased_destination_id)?; } diff --git a/lib/tests/test_commit_builder.rs b/lib/tests/test_commit_builder.rs index f408042236..72922081c7 100644 --- a/lib/tests/test_commit_builder.rs +++ b/lib/tests/test_commit_builder.rs @@ -352,7 +352,7 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) { .unwrap(); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert_eq!(rebase_map.len(), 0); @@ -365,7 +365,7 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) { .unwrap(); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit3, &[commit4.id()]); assert_eq!(rebase_map.len(), 1); @@ -379,7 +379,7 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) { .unwrap(); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert!(rebase_map.is_empty()); } diff --git a/lib/tests/test_mut_repo.rs b/lib/tests/test_mut_repo.rs index 5c53556376..0673c19f95 100644 --- a/lib/tests/test_mut_repo.rs +++ b/lib/tests/test_mut_repo.rs @@ -556,7 +556,7 @@ fn test_rebase_descendants_simple() { mut_repo.record_abandoned_commit(commit4.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); // Commit 3 got rebased onto commit 2's replacement, i.e. commit 6 assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit3, &[commit6.id()]); @@ -567,7 +567,7 @@ fn test_rebase_descendants_simple() { // No more descendants to rebase if we try again. let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert_eq!(rebase_map.len(), 0); } @@ -601,7 +601,7 @@ fn test_rebase_descendants_divergent_rewrite() { // commit 4 or commit 5 let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert!(rebase_map.is_empty()); } diff --git a/lib/tests/test_rewrite.rs b/lib/tests/test_rewrite.rs index c785634e82..7348b5e75c 100644 --- a/lib/tests/test_rewrite.rs +++ b/lib/tests/test_rewrite.rs @@ -101,7 +101,7 @@ fn test_rebase_descendants_sideways() { .set_rewritten_commit(commit_b.id().clone(), commit_f.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert_eq!(rebase_map.len(), 3); let new_commit_c = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c, &[commit_f.id()]); @@ -155,7 +155,7 @@ fn test_rebase_descendants_forward() { .set_rewritten_commit(commit_b.id().clone(), commit_f.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_d = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_d, &[(commit_f.id())]); @@ -216,7 +216,7 @@ fn test_rebase_descendants_reorder() { .set_rewritten_commit(commit_g.id().clone(), commit_h.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_i = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_i, &[commit_h.id()]); assert_eq!(rebase_map.len(), 1); @@ -252,7 +252,7 @@ fn test_rebase_descendants_backward() { .set_rewritten_commit(commit_c.id().clone(), commit_b.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_d = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_d, &[commit_b.id()]); assert_eq!(rebase_map.len(), 1); @@ -294,7 +294,7 @@ fn test_rebase_descendants_chain_becomes_bookmarky() { .set_rewritten_commit(commit_c.id().clone(), commit_f.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_f = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_f, &[commit_e.id()]); let new_commit_d = @@ -338,7 +338,7 @@ fn test_rebase_descendants_internal_merge() { .set_rewritten_commit(commit_b.id().clone(), commit_f.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_c = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c, &[commit_f.id()]); let new_commit_d = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_d, &[commit_f.id()]); @@ -386,7 +386,7 @@ fn test_rebase_descendants_external_merge() { .set_rewritten_commit(commit_c.id().clone(), commit_f.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_e = assert_rebased_onto( tx.repo_mut(), @@ -430,7 +430,7 @@ fn test_rebase_descendants_abandon() { tx.repo_mut().record_abandoned_commit(commit_e.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_c = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c, &[commit_a.id()]); let new_commit_d = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_d, &[commit_a.id()]); @@ -468,7 +468,7 @@ fn test_rebase_descendants_abandon_no_descendants() { tx.repo_mut().record_abandoned_commit(commit_c.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert_eq!(rebase_map.len(), 0); @@ -507,7 +507,7 @@ fn test_rebase_descendants_abandon_and_replace() { tx.repo_mut().record_abandoned_commit(commit_c.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_d = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_d, &[commit_e.id()]); assert_eq!(rebase_map.len(), 1); @@ -633,7 +633,7 @@ fn test_rebase_descendants_abandon_widen_merge() { tx.repo_mut().record_abandoned_commit(commit_e.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_f = assert_rebased_onto( tx.repo_mut(), @@ -678,7 +678,7 @@ fn test_rebase_descendants_multiple_sideways() { .set_rewritten_commit(commit_d.id().clone(), commit_f.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_c = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c, &[commit_f.id()]); let new_commit_e = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_e, &[commit_f.id()]); @@ -800,7 +800,7 @@ fn test_rebase_descendants_divergent_rewrite() { .set_rewritten_commit(commit_f.id().clone(), commit_f2.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let new_commit_c = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c, &[commit_b2.id()]); @@ -851,7 +851,7 @@ fn test_rebase_descendants_repeated() { .unwrap(); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let commit_c2 = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c, &[commit_b2.id()]); assert_eq!(rebase_map.len(), 1); @@ -866,7 +866,7 @@ fn test_rebase_descendants_repeated() { // We made no more changes, so nothing should be rebased. let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert_eq!(rebase_map.len(), 0); @@ -879,7 +879,7 @@ fn test_rebase_descendants_repeated() { .unwrap(); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); let commit_c3 = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c2, &[commit_b3.id()]); assert_eq!(rebase_map.len(), 1); @@ -945,7 +945,7 @@ fn test_rebase_descendants_contents() { .set_rewritten_commit(commit_b.id().clone(), commit_d.id().clone()); let rebase_map = tx .repo_mut() - .rebase_descendants_return_map(&settings) + .rebase_descendants_with_options_return_map(&settings, Default::default()) .unwrap(); assert_eq!(rebase_map.len(), 1); let new_commit_c = repo