mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-28 09:14:04 +00:00
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:
parent
6703810c6e
commit
61468ed126
6 changed files with 22 additions and 51 deletions
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue