commit_builder: remove redundant for_open_commit()

The function is now the same as `for_new_commit()`, except that it
accepts only one parent.
This commit is contained in:
Martin von Zweigbergk 2022-11-04 23:27:46 -07:00 committed by Martin von Zweigbergk
parent 6703810c6e
commit 61468ed126
6 changed files with 22 additions and 51 deletions

View file

@ -71,27 +71,6 @@ impl CommitBuilder {
}
}
pub fn for_open_commit(
settings: &UserSettings,
parent_id: CommitId,
tree_id: TreeId,
) -> CommitBuilder {
let signature = settings.signature();
let commit = backend::Commit {
parents: vec![parent_id],
predecessors: vec![],
root_tree: tree_id,
change_id: new_change_id(),
description: String::new(),
author: signature.clone(),
committer: signature,
};
CommitBuilder {
commit,
rewrite_source: None,
}
}
pub fn set_parents(mut self, parents: Vec<CommitId>) -> Self {
assert!(!parents.is_empty());
self.commit.parents = parents;

View file

@ -620,12 +620,15 @@ impl MutableRepo {
commit: &Commit,
) -> Commit {
self.leave_commit(&workspace_id);
let open_commit =
CommitBuilder::for_open_commit(settings, commit.id().clone(), commit.tree_id().clone())
.write_to_repo(self);
self.set_wc_commit(workspace_id, open_commit.id().clone())
let wc_commit = CommitBuilder::for_new_commit(
settings,
vec![commit.id().clone()],
commit.tree_id().clone(),
)
.write_to_repo(self);
self.set_wc_commit(workspace_id, wc_commit.id().clone())
.unwrap();
open_commit
wc_commit
}
pub fn edit(

View file

@ -351,9 +351,9 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
let new_wc_commit = if edit {
new_commit
} else {
CommitBuilder::for_open_commit(
CommitBuilder::for_new_commit(
self.settings,
new_commit.id().clone(),
vec![new_commit.id().clone()],
new_commit.tree_id().clone(),
)
.write_to_repo(self.mut_repo)

View file

@ -226,17 +226,6 @@ fn test_commit_builder_descendants(use_git: bool) {
let mut rebaser = tx.mut_repo().create_descendant_rebaser(&settings);
assert!(rebaser.rebase_next().unwrap().is_none());
// Test with for_open_commit()
let mut tx = repo.start_transaction("test");
CommitBuilder::for_open_commit(
&settings,
commit2.id().clone(),
store.empty_tree_id().clone(),
)
.write_to_repo(tx.mut_repo());
let mut rebaser = tx.mut_repo().create_descendant_rebaser(&settings);
assert!(rebaser.rebase_next().unwrap().is_none());
// Test with for_rewrite_from()
let mut tx = repo.start_transaction("test");
let commit4 = CommitBuilder::for_rewrite_from(&settings, &commit2).write_to_repo(tx.mut_repo());

View file

@ -101,9 +101,9 @@ fn test_checkout_previous_empty(use_git: bool) {
let mut tx = repo.start_transaction("test");
let mut_repo = tx.mut_repo();
let old_checkout = CommitBuilder::for_open_commit(
let old_checkout = CommitBuilder::for_new_commit(
&settings,
repo.store().root_commit_id().clone(),
vec![repo.store().root_commit_id().clone()],
repo.store().empty_tree_id().clone(),
)
.write_to_repo(mut_repo);
@ -130,9 +130,9 @@ fn test_checkout_previous_empty_with_description(use_git: bool) {
let mut tx = repo.start_transaction("test");
let mut_repo = tx.mut_repo();
let old_checkout = CommitBuilder::for_open_commit(
let old_checkout = CommitBuilder::for_new_commit(
&settings,
repo.store().root_commit_id().clone(),
vec![repo.store().root_commit_id().clone()],
repo.store().empty_tree_id().clone(),
)
.set_description("not empty".to_string())
@ -160,15 +160,15 @@ fn test_checkout_previous_empty_non_head(use_git: bool) {
let mut tx = repo.start_transaction("test");
let mut_repo = tx.mut_repo();
let old_checkout = CommitBuilder::for_open_commit(
let old_checkout = CommitBuilder::for_new_commit(
&settings,
repo.store().root_commit_id().clone(),
vec![repo.store().root_commit_id().clone()],
repo.store().empty_tree_id().clone(),
)
.write_to_repo(mut_repo);
let old_child = CommitBuilder::for_open_commit(
let old_child = CommitBuilder::for_new_commit(
&settings,
old_checkout.id().clone(),
vec![old_checkout.id().clone()],
old_checkout.tree_id().clone(),
)
.write_to_repo(mut_repo);

View file

@ -1117,9 +1117,9 @@ fn cmd_checkout(
let workspace_id = workspace_command.workspace_id();
let mut tx =
workspace_command.start_transaction(&format!("check out commit {}", target.id().hex()));
let commit_builder = CommitBuilder::for_open_commit(
let commit_builder = CommitBuilder::for_new_commit(
ui.settings(),
target.id().clone(),
vec![target.id().clone()],
target.tree_id().clone(),
)
.set_description(args.message.clone());
@ -2388,9 +2388,9 @@ fn cmd_commit(ui: &mut Ui, command: &CommandHelper, args: &CommitArgs) -> Result
.view()
.workspaces_for_wc_commit_id(commit.id());
if !workspace_ids.is_empty() {
let new_checkout = CommitBuilder::for_open_commit(
let new_checkout = CommitBuilder::for_new_commit(
ui.settings(),
new_commit.id().clone(),
vec![new_commit.id().clone()],
new_commit.tree_id().clone(),
)
.write_to_repo(tx.mut_repo());