commit_builder: relax type of description parameter

The next commit will introduce a newtype for -m/--message argument which
can be converted Into<String>.

Since CommitBuilder is a thin wrapper, code bloat caused by generic parameters
wouldn't matter. I have another set of commits that makes all builder methods
accept Into/IntoIterator, which will remove some of .clone() calls from tests.
This commit is contained in:
Yuya Nishihara 2022-12-21 18:13:56 +09:00
parent 6063fe8f06
commit 986649623d
8 changed files with 22 additions and 22 deletions

View File

@ -43,7 +43,7 @@ fn run(ui: &mut Ui) -> Result<(), CommandError> {
let commit = workspace_command.resolve_single_rev(&args.revision)?;
let mut tx = workspace_command.start_transaction("Frobnicate");
let new_commit = CommitBuilder::for_rewrite_from(ui.settings(), &commit)
.set_description("Frobnicated!".to_string())
.set_description("Frobnicated!")
.write_to_repo(tx.mut_repo());
workspace_command.finish_transaction(ui, tx)?;
writeln!(

View File

@ -97,8 +97,8 @@ impl CommitBuilder {
self
}
pub fn set_description(mut self, description: String) -> Self {
self.commit.description = description;
pub fn set_description(mut self, description: impl Into<String>) -> Self {
self.commit.description = description.into();
self
}

View File

@ -133,7 +133,7 @@ fn test_checkout_previous_empty_with_description(use_git: bool) {
vec![repo.store().root_commit_id().clone()],
repo.store().empty_tree_id().clone(),
)
.set_description("not empty".to_string())
.set_description("not empty")
.write_to_repo(mut_repo);
let ws_id = WorkspaceId::default();
mut_repo.edit(ws_id.clone(), &old_checkout).unwrap();

View File

@ -152,11 +152,11 @@ fn test_isolation(use_git: bool) {
assert_heads(mut_repo2.as_repo_ref(), vec![initial.id()]);
let rewrite1 = CommitBuilder::for_rewrite_from(&settings, &initial)
.set_description("rewrite1".to_string())
.set_description("rewrite1")
.write_to_repo(mut_repo1);
mut_repo1.rebase_descendants(&settings).unwrap();
let rewrite2 = CommitBuilder::for_rewrite_from(&settings, &initial)
.set_description("rewrite2".to_string())
.set_description("rewrite2")
.write_to_repo(mut_repo2);
mut_repo2.rebase_descendants(&settings).unwrap();

View File

@ -1500,15 +1500,15 @@ fn test_evaluate_expression_description(use_git: bool) {
let mut_repo = tx.mut_repo();
let commit1 = create_random_commit(&settings, repo)
.set_description("commit 1".to_string())
.set_description("commit 1")
.write_to_repo(mut_repo);
let commit2 = create_random_commit(&settings, repo)
.set_parents(vec![commit1.id().clone()])
.set_description("commit 2".to_string())
.set_description("commit 2")
.write_to_repo(mut_repo);
let commit3 = create_random_commit(&settings, repo)
.set_parents(vec![commit2.id().clone()])
.set_description("commit 3".to_string())
.set_description("commit 3")
.write_to_repo(mut_repo);
// Can find multiple matches

View File

@ -793,7 +793,7 @@ fn test_rebase_descendants_repeated(use_git: bool) {
let commit_c = graph_builder.commit_with_parents(&[&commit_b]);
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
.set_description("b2".to_string())
.set_description("b2")
.write_to_repo(tx.mut_repo());
let mut rebaser = tx.mut_repo().create_descendant_rebaser(&settings);
let commit_c2 = assert_rebased(rebaser.rebase_next().unwrap(), &commit_c, &[&commit_b2]);
@ -814,7 +814,7 @@ fn test_rebase_descendants_repeated(use_git: bool) {
// Now mark B3 as rewritten from B2 and rebase descendants again.
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, &commit_b2)
.set_description("b3".to_string())
.set_description("b3")
.write_to_repo(tx.mut_repo());
let mut rebaser = tx.mut_repo().create_descendant_rebaser(&settings);
let commit_c3 = assert_rebased(rebaser.rebase_next().unwrap(), &commit_c2, &[&commit_b3]);
@ -1094,11 +1094,11 @@ fn test_rebase_descendants_update_branches_after_divergent_rewrite() {
CommitBuilder::for_rewrite_from(&settings, &commit_b).write_to_repo(tx.mut_repo());
// Different description so they're not the same commit
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
.set_description("different".to_string())
.set_description("different")
.write_to_repo(tx.mut_repo());
// Different description so they're not the same commit
let commit_b4 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
.set_description("more different".to_string())
.set_description("more different")
.write_to_repo(tx.mut_repo());
tx.mut_repo().rebase_descendants(&settings).unwrap();
assert_eq!(
@ -1151,13 +1151,13 @@ fn test_rebase_descendants_rewrite_updates_branch_conflict() {
CommitBuilder::for_rewrite_from(&settings, &commit_a).write_to_repo(tx.mut_repo());
// Different description so they're not the same commit
let commit_a3 = CommitBuilder::for_rewrite_from(&settings, &commit_a)
.set_description("different".to_string())
.set_description("different")
.write_to_repo(tx.mut_repo());
let commit_b2 =
CommitBuilder::for_rewrite_from(&settings, &commit_b).write_to_repo(tx.mut_repo());
// Different description so they're not the same commit
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
.set_description("different".to_string())
.set_description("different")
.write_to_repo(tx.mut_repo());
tx.mut_repo().rebase_descendants(&settings).unwrap();
assert_eq!(
@ -1291,7 +1291,7 @@ fn test_rebase_descendants_update_checkout(use_git: bool) {
let mut tx = repo.start_transaction(&settings, "test");
let commit_c = CommitBuilder::for_rewrite_from(&settings, &commit_b)
.set_description("C".to_string())
.set_description("C")
.write_to_repo(tx.mut_repo());
tx.mut_repo().rebase_descendants(&settings).unwrap();
let repo = tx.commit();

View File

@ -464,13 +464,13 @@ fn test_merge_views_divergent() {
let mut tx1 = repo.start_transaction(&settings, "test");
let commit_a2 = CommitBuilder::for_rewrite_from(&settings, &commit_a)
.set_description("A2".to_string())
.set_description("A2")
.write_to_repo(tx1.mut_repo());
tx1.mut_repo().rebase_descendants(&settings).unwrap();
let mut tx2 = repo.start_transaction(&settings, "test");
let commit_a3 = CommitBuilder::for_rewrite_from(&settings, &commit_a)
.set_description("A3".to_string())
.set_description("A3")
.write_to_repo(tx2.mut_repo());
tx2.mut_repo().rebase_descendants(&settings).unwrap();
@ -502,7 +502,7 @@ fn test_merge_views_child_on_rewritten(child_first: bool) {
let mut tx2 = repo.start_transaction(&settings, "test");
let commit_a2 = CommitBuilder::for_rewrite_from(&settings, &commit_a)
.set_description("A2".to_string())
.set_description("A2")
.write_to_repo(tx2.mut_repo());
tx2.mut_repo().rebase_descendants(&settings).unwrap();
@ -548,7 +548,7 @@ fn test_merge_views_child_on_rewritten_divergent(on_rewritten: bool, child_first
let mut tx2 = repo.start_transaction(&settings, "test");
let commit_a4 = CommitBuilder::for_rewrite_from(&settings, &commit_a2)
.set_description("A4".to_string())
.set_description("A4")
.write_to_repo(tx2.mut_repo());
tx2.mut_repo().rebase_descendants(&settings).unwrap();

View File

@ -1186,7 +1186,7 @@ fn cmd_checkout(
vec![target.id().clone()],
target.tree_id().clone(),
)
.set_description(args.message.clone());
.set_description(&args.message);
let new_commit = commit_builder.write_to_repo(tx.mut_repo());
tx.mut_repo().edit(workspace_id, &new_commit).unwrap();
workspace_command.finish_transaction(ui, tx)?;
@ -2032,7 +2032,7 @@ fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), C
let merged_tree = merge_commit_trees(workspace_command.repo().as_repo_ref(), &commits);
let new_commit =
CommitBuilder::for_new_commit(ui.settings(), parent_ids, merged_tree.id().clone())
.set_description(args.message.clone())
.set_description(&args.message)
.write_to_repo(tx.mut_repo());
let workspace_id = workspace_command.workspace_id();
tx.mut_repo().edit(workspace_id, &new_commit).unwrap();