mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 10:07:28 +00:00
rewrite: pass RebaseOptions by reference
Since we've removed DescendantRebaser, it no longer makes sense to pass options by value. This patch also replaces Default::default() for clarity.
This commit is contained in:
parent
dbb9e7e9f9
commit
e3efb0d614
6 changed files with 36 additions and 33 deletions
|
@ -272,7 +272,7 @@ pub(crate) fn cmd_rebase(
|
|||
&mut workspace_command,
|
||||
&args.branch,
|
||||
&args.destination,
|
||||
rebase_options,
|
||||
&rebase_options,
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -349,7 +349,7 @@ fn rebase_branch(
|
|||
workspace_command: &mut WorkspaceCommandHelper,
|
||||
branch: &[RevisionArg],
|
||||
rebase_destination: &RebaseDestinationArgs,
|
||||
rebase_options: RebaseOptions,
|
||||
rebase_options: &RebaseOptions,
|
||||
) -> Result<(), CommandError> {
|
||||
let branch_commits: Vec<_> = if branch.is_empty() {
|
||||
vec![workspace_command.resolve_single_rev(ui, &RevisionArg::AT)?]
|
||||
|
@ -387,7 +387,7 @@ fn rebase_branch(
|
|||
&new_parent_ids,
|
||||
&new_children,
|
||||
root_commits,
|
||||
&rebase_options,
|
||||
rebase_options,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1262,14 +1262,14 @@ impl MutableRepo {
|
|||
/// bookmarks of the abandoned commit.
|
||||
pub fn rebase_descendants_with_options_return_map(
|
||||
&mut self,
|
||||
options: RebaseOptions,
|
||||
options: &RebaseOptions,
|
||||
) -> BackendResult<HashMap<CommitId, CommitId>> {
|
||||
let mut rebased: HashMap<CommitId, CommitId> = HashMap::new();
|
||||
let roots = self.parent_mapping.keys().cloned().collect_vec();
|
||||
self.transform_descendants(roots, |rewriter| {
|
||||
if rewriter.parents_changed() {
|
||||
let old_commit_id = rewriter.old_commit().id().clone();
|
||||
let rebased_commit: RebasedCommit = rebase_commit_with_options(rewriter, &options)?;
|
||||
let rebased_commit: RebasedCommit = rebase_commit_with_options(rewriter, options)?;
|
||||
let new_commit_id = match rebased_commit {
|
||||
RebasedCommit::Rewritten(new_commit) => new_commit.id().clone(),
|
||||
RebasedCommit::Abandoned { parent_id } => parent_id,
|
||||
|
|
|
@ -1105,7 +1105,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_with_options_return_map(Default::default())?;
|
||||
let rebase_map =
|
||||
repo.rebase_descendants_with_options_return_map(&RebaseOptions::default())?;
|
||||
let rebased_destination_id = rebase_map.get(destination.id()).unwrap().clone();
|
||||
rewritten_destination = repo.store().get_commit(&rebased_destination_id)?;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ use jj_lib::merged_tree::MergedTree;
|
|||
use jj_lib::repo::Repo;
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
use jj_lib::repo_path::RepoPathBuf;
|
||||
use jj_lib::rewrite::RebaseOptions;
|
||||
use jj_lib::settings::UserSettings;
|
||||
use pollster::FutureExt as _;
|
||||
use test_case::test_case;
|
||||
|
@ -373,7 +374,7 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) {
|
|||
.unwrap();
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
assert_eq!(rebase_map.len(), 0);
|
||||
|
||||
|
@ -382,7 +383,7 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) {
|
|||
let commit4 = tx.repo_mut().rewrite_commit(&commit2).write().unwrap();
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit3, &[commit4.id()]);
|
||||
assert_eq!(rebase_map.len(), 1);
|
||||
|
@ -396,7 +397,7 @@ fn test_commit_builder_descendants(backend: TestRepoBackend) {
|
|||
.unwrap();
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
assert!(rebase_map.is_empty());
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ use jj_lib::op_store::RemoteRef;
|
|||
use jj_lib::op_store::RemoteRefState;
|
||||
use jj_lib::op_store::WorkspaceId;
|
||||
use jj_lib::repo::Repo;
|
||||
use jj_lib::rewrite::RebaseOptions;
|
||||
use maplit::hashset;
|
||||
use testutils::assert_rebased_onto;
|
||||
use testutils::create_random_commit;
|
||||
|
@ -532,7 +533,7 @@ fn test_rebase_descendants_simple() {
|
|||
mut_repo.record_abandoned_commit(&commit4);
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::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()]);
|
||||
|
@ -543,7 +544,7 @@ fn test_rebase_descendants_simple() {
|
|||
// No more descendants to rebase if we try again.
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
assert_eq!(rebase_map.len(), 0);
|
||||
}
|
||||
|
@ -576,7 +577,7 @@ fn test_rebase_descendants_divergent_rewrite() {
|
|||
// commit 4 or commit 5
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
assert!(rebase_map.is_empty());
|
||||
}
|
||||
|
|
|
@ -100,7 +100,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::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()]);
|
||||
|
@ -153,7 +153,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
let new_commit_d =
|
||||
assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_d, &[(commit_f.id())]);
|
||||
|
@ -213,7 +213,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::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);
|
||||
|
@ -248,7 +248,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::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);
|
||||
|
@ -289,7 +289,7 @@ fn test_rebase_descendants_chain_becomes_branchy() {
|
|||
.set_rewritten_commit(commit_c.id().clone(), commit_f.id().clone());
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
let new_commit_f = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_f, &[commit_e.id()]);
|
||||
let new_commit_d =
|
||||
|
@ -332,7 +332,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::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()]);
|
||||
|
@ -379,7 +379,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
let new_commit_e = assert_rebased_onto(
|
||||
tx.repo_mut(),
|
||||
|
@ -422,7 +422,7 @@ fn test_rebase_descendants_abandon() {
|
|||
tx.repo_mut().record_abandoned_commit(&commit_e);
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::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()]);
|
||||
|
@ -459,7 +459,7 @@ fn test_rebase_descendants_abandon_no_descendants() {
|
|||
tx.repo_mut().record_abandoned_commit(&commit_c);
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
assert_eq!(rebase_map.len(), 0);
|
||||
|
||||
|
@ -497,7 +497,7 @@ fn test_rebase_descendants_abandon_and_replace() {
|
|||
tx.repo_mut().record_abandoned_commit(&commit_c);
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::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);
|
||||
|
@ -531,7 +531,7 @@ fn test_rebase_descendants_abandon_degenerate_merge_simplify() {
|
|||
tx.repo_mut().record_abandoned_commit(&commit_b);
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(RebaseOptions {
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions {
|
||||
simplify_ancestor_merge: true,
|
||||
..Default::default()
|
||||
})
|
||||
|
@ -568,7 +568,7 @@ fn test_rebase_descendants_abandon_degenerate_merge_preserve() {
|
|||
tx.repo_mut().record_abandoned_commit(&commit_b);
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(RebaseOptions {
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions {
|
||||
simplify_ancestor_merge: false,
|
||||
..Default::default()
|
||||
})
|
||||
|
@ -614,7 +614,7 @@ fn test_rebase_descendants_abandon_widen_merge() {
|
|||
tx.repo_mut().record_abandoned_commit(&commit_e);
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
let new_commit_f = assert_rebased_onto(
|
||||
tx.repo_mut(),
|
||||
|
@ -658,7 +658,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::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()]);
|
||||
|
@ -775,7 +775,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
let new_commit_c =
|
||||
assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c, &[commit_b2.id()]);
|
||||
|
@ -825,7 +825,7 @@ fn test_rebase_descendants_repeated() {
|
|||
.unwrap();
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
let commit_c2 = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c, &[commit_b2.id()]);
|
||||
assert_eq!(rebase_map.len(), 1);
|
||||
|
@ -840,7 +840,7 @@ fn test_rebase_descendants_repeated() {
|
|||
// We made no more changes, so nothing should be rebased.
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
assert_eq!(rebase_map.len(), 0);
|
||||
|
||||
|
@ -853,7 +853,7 @@ fn test_rebase_descendants_repeated() {
|
|||
.unwrap();
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
let commit_c3 = assert_rebased_onto(tx.repo_mut(), &rebase_map, &commit_c2, &[commit_b3.id()]);
|
||||
assert_eq!(rebase_map.len(), 1);
|
||||
|
@ -914,7 +914,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_with_options_return_map(Default::default())
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions::default())
|
||||
.unwrap();
|
||||
assert_eq!(rebase_map.len(), 1);
|
||||
let new_commit_c = repo
|
||||
|
@ -1572,7 +1572,7 @@ fn test_empty_commit_option(empty_behavior: EmptyBehaviour) {
|
|||
.set_rewritten_commit(commit_b.id().clone(), commit_bd.id().clone());
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(RebaseOptions {
|
||||
.rebase_descendants_with_options_return_map(&RebaseOptions {
|
||||
empty: empty_behavior,
|
||||
simplify_ancestor_merge: true,
|
||||
})
|
||||
|
@ -1712,7 +1712,7 @@ fn test_rebase_abandoning_empty() {
|
|||
rebase_commit_with_options(rewriter, &rebase_options).unwrap();
|
||||
let rebase_map = tx
|
||||
.repo_mut()
|
||||
.rebase_descendants_with_options_return_map(rebase_options)
|
||||
.rebase_descendants_with_options_return_map(&rebase_options)
|
||||
.unwrap();
|
||||
assert_eq!(rebase_map.len(), 5);
|
||||
let new_commit_c =
|
||||
|
|
Loading…
Reference in a new issue