mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-26 22:10:52 +00:00
CommitBuilder: remove unneeded store
arguments
The `CommitBuilder::store` field is used only in `CommitBuilder::write_to_repo()`, but we can easily get access to the `Store` from the `repo` argument there, so let's remove the field.
This commit is contained in:
parent
c2c32ba0dc
commit
1b5cd140d5
12 changed files with 100 additions and 144 deletions
|
@ -12,8 +12,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::backend;
|
||||
|
@ -21,11 +19,9 @@ use crate::backend::{ChangeId, CommitId, Signature, TreeId};
|
|||
use crate::commit::Commit;
|
||||
use crate::repo::MutableRepo;
|
||||
use crate::settings::UserSettings;
|
||||
use crate::store::Store;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CommitBuilder {
|
||||
store: Arc<Store>,
|
||||
commit: backend::Commit,
|
||||
rewrite_source: Option<Commit>,
|
||||
}
|
||||
|
@ -35,11 +31,7 @@ pub fn new_change_id() -> ChangeId {
|
|||
}
|
||||
|
||||
impl CommitBuilder {
|
||||
pub fn for_new_commit(
|
||||
settings: &UserSettings,
|
||||
store: &Arc<Store>,
|
||||
tree_id: TreeId,
|
||||
) -> CommitBuilder {
|
||||
pub fn for_new_commit(settings: &UserSettings, tree_id: TreeId) -> CommitBuilder {
|
||||
let signature = settings.signature();
|
||||
let commit = backend::Commit {
|
||||
parents: vec![],
|
||||
|
@ -52,17 +44,12 @@ impl CommitBuilder {
|
|||
is_open: false,
|
||||
};
|
||||
CommitBuilder {
|
||||
store: store.clone(),
|
||||
commit,
|
||||
rewrite_source: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_rewrite_from(
|
||||
settings: &UserSettings,
|
||||
store: &Arc<Store>,
|
||||
predecessor: &Commit,
|
||||
) -> CommitBuilder {
|
||||
pub fn for_rewrite_from(settings: &UserSettings, predecessor: &Commit) -> CommitBuilder {
|
||||
let mut commit = predecessor.store_commit().clone();
|
||||
commit.predecessors = vec![predecessor.id().clone()];
|
||||
commit.committer = settings.signature();
|
||||
|
@ -75,7 +62,6 @@ impl CommitBuilder {
|
|||
commit.author.email = commit.committer.email.clone();
|
||||
}
|
||||
CommitBuilder {
|
||||
store: store.clone(),
|
||||
commit,
|
||||
rewrite_source: Some(predecessor.clone()),
|
||||
}
|
||||
|
@ -83,7 +69,6 @@ impl CommitBuilder {
|
|||
|
||||
pub fn for_open_commit(
|
||||
settings: &UserSettings,
|
||||
store: &Arc<Store>,
|
||||
parent_id: CommitId,
|
||||
tree_id: TreeId,
|
||||
) -> CommitBuilder {
|
||||
|
@ -99,7 +84,6 @@ impl CommitBuilder {
|
|||
is_open: true,
|
||||
};
|
||||
CommitBuilder {
|
||||
store: store.clone(),
|
||||
commit,
|
||||
rewrite_source: None,
|
||||
}
|
||||
|
@ -152,7 +136,7 @@ impl CommitBuilder {
|
|||
|
||||
pub fn write_to_repo(mut self, repo: &mut MutableRepo) -> Commit {
|
||||
let parents = &mut self.commit.parents;
|
||||
if parents.contains(self.store.root_commit_id()) {
|
||||
if parents.contains(repo.store().root_commit_id()) {
|
||||
assert_eq!(parents.len(), 1);
|
||||
parents.clear();
|
||||
}
|
||||
|
|
|
@ -585,13 +585,9 @@ impl MutableRepo {
|
|||
commit: &Commit,
|
||||
) -> Commit {
|
||||
self.leave_commit(&workspace_id);
|
||||
let open_commit = CommitBuilder::for_open_commit(
|
||||
settings,
|
||||
self.store(),
|
||||
commit.id().clone(),
|
||||
commit.tree_id().clone(),
|
||||
)
|
||||
.write_to_repo(self);
|
||||
let open_commit =
|
||||
CommitBuilder::for_open_commit(settings, commit.id().clone(), commit.tree_id().clone())
|
||||
.write_to_repo(self);
|
||||
self.set_checkout(workspace_id, open_commit.id().clone());
|
||||
open_commit
|
||||
}
|
||||
|
|
|
@ -61,7 +61,6 @@ pub fn rebase_commit(
|
|||
old_commit: &Commit,
|
||||
new_parents: &[Commit],
|
||||
) -> Commit {
|
||||
let store = mut_repo.store();
|
||||
let old_parents = old_commit.parents();
|
||||
let old_parent_trees = old_parents
|
||||
.iter()
|
||||
|
@ -84,7 +83,7 @@ pub fn rebase_commit(
|
|||
.iter()
|
||||
.map(|commit| commit.id().clone())
|
||||
.collect();
|
||||
CommitBuilder::for_rewrite_from(settings, store, old_commit)
|
||||
CommitBuilder::for_rewrite_from(settings, old_commit)
|
||||
.set_parents(new_parent_ids)
|
||||
.set_tree(new_tree_id)
|
||||
.write_to_repo(mut_repo)
|
||||
|
@ -96,7 +95,6 @@ pub fn back_out_commit(
|
|||
old_commit: &Commit,
|
||||
new_parents: &[Commit],
|
||||
) -> Commit {
|
||||
let store = mut_repo.store();
|
||||
let old_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), &old_commit.parents());
|
||||
let new_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), new_parents);
|
||||
// TODO: pass in labels for the merge parts
|
||||
|
@ -106,7 +104,7 @@ pub fn back_out_commit(
|
|||
.map(|commit| commit.id().clone())
|
||||
.collect();
|
||||
// TODO: i18n the description based on repo language
|
||||
CommitBuilder::for_new_commit(settings, store, new_tree_id)
|
||||
CommitBuilder::for_new_commit(settings, new_tree_id)
|
||||
.set_parents(new_parent_ids)
|
||||
.set_description(format!("backout of commit {}", &old_commit.id().hex()))
|
||||
.write_to_repo(mut_repo)
|
||||
|
@ -350,7 +348,6 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
|
|||
} else {
|
||||
CommitBuilder::for_open_commit(
|
||||
self.settings,
|
||||
self.mut_repo.store(),
|
||||
new_commit.id().clone(),
|
||||
new_commit.tree_id().clone(),
|
||||
)
|
||||
|
|
|
@ -176,7 +176,7 @@ pub fn create_random_tree(repo: &ReadonlyRepo) -> TreeId {
|
|||
pub fn create_random_commit(settings: &UserSettings, repo: &ReadonlyRepo) -> CommitBuilder {
|
||||
let tree_id = create_random_tree(repo);
|
||||
let number = rand::random::<u32>();
|
||||
CommitBuilder::for_new_commit(settings, repo.store(), tree_id)
|
||||
CommitBuilder::for_new_commit(settings, tree_id)
|
||||
.set_description(format!("random commit {}", number))
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ fn test_initial(use_git: bool) {
|
|||
);
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit = CommitBuilder::for_new_commit(&settings, store, tree.id().clone())
|
||||
let commit = CommitBuilder::for_new_commit(&settings, tree.id().clone())
|
||||
.set_parents(vec![store.root_commit_id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.commit();
|
||||
|
@ -85,10 +85,9 @@ fn test_rewrite(use_git: bool) {
|
|||
);
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let initial_commit =
|
||||
CommitBuilder::for_new_commit(&settings, &store, initial_tree.id().clone())
|
||||
.set_parents(vec![store.root_commit_id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let initial_commit = CommitBuilder::for_new_commit(&settings, initial_tree.id().clone())
|
||||
.set_parents(vec![store.root_commit_id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let repo = tx.commit();
|
||||
|
||||
let rewritten_tree = testutils::create_tree(
|
||||
|
@ -108,10 +107,9 @@ fn test_rewrite(use_git: bool) {
|
|||
.unwrap();
|
||||
let rewrite_settings = UserSettings::from_config(config);
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let rewritten_commit =
|
||||
CommitBuilder::for_rewrite_from(&rewrite_settings, &store, &initial_commit)
|
||||
.set_tree(rewritten_tree.id().clone())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let rewritten_commit = CommitBuilder::for_rewrite_from(&rewrite_settings, &initial_commit)
|
||||
.set_tree(rewritten_tree.id().clone())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
tx.commit();
|
||||
assert_eq!(rewritten_commit.parents(), vec![store.root_commit()]);
|
||||
|
@ -162,15 +160,11 @@ fn test_rewrite_update_missing_user(use_git: bool) {
|
|||
UserSettings::from_config(config::Config::builder().build().unwrap());
|
||||
let test_repo = TestRepo::init(use_git);
|
||||
let repo = &test_repo.repo;
|
||||
let store = repo.store().clone();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let initial_commit = CommitBuilder::for_new_commit(
|
||||
&missing_user_settings,
|
||||
&store,
|
||||
repo.store().empty_tree_id().clone(),
|
||||
)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let initial_commit =
|
||||
CommitBuilder::for_new_commit(&missing_user_settings, repo.store().empty_tree_id().clone())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
assert_eq!(initial_commit.author().name, "(no name configured)");
|
||||
assert_eq!(initial_commit.author().email, "(no email configured)");
|
||||
assert_eq!(initial_commit.committer().name, "(no name configured)");
|
||||
|
@ -184,8 +178,8 @@ fn test_rewrite_update_missing_user(use_git: bool) {
|
|||
.build()
|
||||
.unwrap();
|
||||
let settings = UserSettings::from_config(config);
|
||||
let rewritten_commit = CommitBuilder::for_rewrite_from(&settings, &store, &initial_commit)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let rewritten_commit =
|
||||
CommitBuilder::for_rewrite_from(&settings, &initial_commit).write_to_repo(tx.mut_repo());
|
||||
|
||||
assert_eq!(rewritten_commit.author().name, "Configured User");
|
||||
assert_eq!(
|
||||
|
@ -216,7 +210,7 @@ fn test_commit_builder_descendants(use_git: bool) {
|
|||
|
||||
// Test with for_new_commit()
|
||||
let mut tx = repo.start_transaction("test");
|
||||
CommitBuilder::for_new_commit(&settings, &store, store.empty_tree_id().clone())
|
||||
CommitBuilder::for_new_commit(&settings, 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());
|
||||
|
@ -225,7 +219,6 @@ fn test_commit_builder_descendants(use_git: bool) {
|
|||
let mut tx = repo.start_transaction("test");
|
||||
CommitBuilder::for_open_commit(
|
||||
&settings,
|
||||
&store,
|
||||
commit2.id().clone(),
|
||||
store.empty_tree_id().clone(),
|
||||
)
|
||||
|
@ -235,15 +228,14 @@ fn test_commit_builder_descendants(use_git: bool) {
|
|||
|
||||
// Test with for_rewrite_from()
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit4 =
|
||||
CommitBuilder::for_rewrite_from(&settings, &store, &commit2).write_to_repo(tx.mut_repo());
|
||||
let commit4 = CommitBuilder::for_rewrite_from(&settings, &commit2).write_to_repo(tx.mut_repo());
|
||||
let mut rebaser = tx.mut_repo().create_descendant_rebaser(&settings);
|
||||
assert_rebased(rebaser.rebase_next().unwrap(), &commit3, &[&commit4]);
|
||||
assert!(rebaser.rebase_next().unwrap().is_none());
|
||||
|
||||
// Test with for_rewrite_from() but new change id
|
||||
let mut tx = repo.start_transaction("test");
|
||||
CommitBuilder::for_rewrite_from(&settings, &store, &commit2)
|
||||
CommitBuilder::for_rewrite_from(&settings, &commit2)
|
||||
.generate_new_change_id()
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let mut rebaser = tx.mut_repo().create_descendant_rebaser(&settings);
|
||||
|
|
|
@ -573,18 +573,18 @@ fn test_simplify_conflict_after_resolving_parent(use_git: bool) {
|
|||
let path = RepoPath::from_internal_string("dir/file");
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let tree_a = testutils::create_tree(repo, &[(&path, "abc\ndef\nghi\n")]);
|
||||
let commit_a = CommitBuilder::for_new_commit(&settings, repo.store(), tree_a.id().clone())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_a =
|
||||
CommitBuilder::for_new_commit(&settings, tree_a.id().clone()).write_to_repo(tx.mut_repo());
|
||||
let tree_b = testutils::create_tree(repo, &[(&path, "Abc\ndef\nghi\n")]);
|
||||
let commit_b = CommitBuilder::for_new_commit(&settings, repo.store(), tree_b.id().clone())
|
||||
let commit_b = CommitBuilder::for_new_commit(&settings, tree_b.id().clone())
|
||||
.set_parents(vec![commit_a.id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let tree_c = testutils::create_tree(repo, &[(&path, "Abc\ndef\nGhi\n")]);
|
||||
let commit_c = CommitBuilder::for_new_commit(&settings, repo.store(), tree_c.id().clone())
|
||||
let commit_c = CommitBuilder::for_new_commit(&settings, tree_c.id().clone())
|
||||
.set_parents(vec![commit_b.id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let tree_d = testutils::create_tree(repo, &[(&path, "abC\ndef\nghi\n")]);
|
||||
let commit_d = CommitBuilder::for_new_commit(&settings, repo.store(), tree_d.id().clone())
|
||||
let commit_d = CommitBuilder::for_new_commit(&settings, tree_d.id().clone())
|
||||
.set_parents(vec![commit_a.id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
|
||||
|
@ -603,7 +603,7 @@ fn test_simplify_conflict_after_resolving_parent(use_git: bool) {
|
|||
|
||||
// Create the resolved B and rebase C on top.
|
||||
let tree_b3 = testutils::create_tree(repo, &[(&path, "AbC\ndef\nghi\n")]);
|
||||
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b2)
|
||||
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, &commit_b2)
|
||||
.set_tree(tree_b3.id().clone())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_c3 = rebase_commit(&settings, tx.mut_repo(), &commit_c2, &[commit_b3]);
|
||||
|
|
|
@ -111,7 +111,6 @@ fn test_checkout_previous_empty(use_git: bool) {
|
|||
let mut_repo = tx.mut_repo();
|
||||
let old_checkout = CommitBuilder::for_open_commit(
|
||||
&settings,
|
||||
repo.store(),
|
||||
repo.store().root_commit_id().clone(),
|
||||
repo.store().empty_tree_id().clone(),
|
||||
)
|
||||
|
@ -143,7 +142,6 @@ fn test_checkout_previous_empty_with_description(use_git: bool) {
|
|||
let mut_repo = tx.mut_repo();
|
||||
let old_checkout = CommitBuilder::for_open_commit(
|
||||
&settings,
|
||||
repo.store(),
|
||||
repo.store().root_commit_id().clone(),
|
||||
repo.store().empty_tree_id().clone(),
|
||||
)
|
||||
|
@ -176,14 +174,12 @@ fn test_checkout_previous_empty_non_head(use_git: bool) {
|
|||
let mut_repo = tx.mut_repo();
|
||||
let old_checkout = CommitBuilder::for_open_commit(
|
||||
&settings,
|
||||
repo.store(),
|
||||
repo.store().root_commit_id().clone(),
|
||||
repo.store().empty_tree_id().clone(),
|
||||
)
|
||||
.write_to_repo(mut_repo);
|
||||
let old_child = CommitBuilder::for_open_commit(
|
||||
&settings,
|
||||
repo.store(),
|
||||
old_checkout.id().clone(),
|
||||
old_checkout.tree_id().clone(),
|
||||
)
|
||||
|
|
|
@ -152,11 +152,11 @@ fn test_isolation(use_git: bool) {
|
|||
assert_heads(mut_repo1.as_repo_ref(), vec![initial.id()]);
|
||||
assert_heads(mut_repo2.as_repo_ref(), vec![initial.id()]);
|
||||
|
||||
let rewrite1 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &initial)
|
||||
let rewrite1 = CommitBuilder::for_rewrite_from(&settings, &initial)
|
||||
.set_description("rewrite1".to_string())
|
||||
.write_to_repo(mut_repo1);
|
||||
mut_repo1.rebase_descendants(&settings).unwrap();
|
||||
let rewrite2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &initial)
|
||||
let rewrite2 = CommitBuilder::for_rewrite_from(&settings, &initial)
|
||||
.set_description("rewrite2".to_string())
|
||||
.write_to_repo(mut_repo2);
|
||||
mut_repo2.rebase_descendants(&settings).unwrap();
|
||||
|
|
|
@ -53,15 +53,11 @@ fn test_resolve_symbol_commit_id() {
|
|||
|
||||
let mut commits = vec![];
|
||||
for i in &[1, 167, 895] {
|
||||
let commit = CommitBuilder::for_new_commit(
|
||||
&settings,
|
||||
repo.store(),
|
||||
repo.store().empty_tree_id().clone(),
|
||||
)
|
||||
.set_description(format!("test {}", i))
|
||||
.set_author(signature.clone())
|
||||
.set_committer(signature.clone())
|
||||
.write_to_repo(mut_repo);
|
||||
let commit = CommitBuilder::for_new_commit(&settings, repo.store().empty_tree_id().clone())
|
||||
.set_description(format!("test {}", i))
|
||||
.set_author(signature.clone())
|
||||
.set_committer(signature.clone())
|
||||
.write_to_repo(mut_repo);
|
||||
commits.push(commit);
|
||||
}
|
||||
let repo = tx.commit();
|
||||
|
|
|
@ -793,7 +793,7 @@ fn test_rebase_descendants_repeated(use_git: bool) {
|
|||
let commit_b = graph_builder.commit_with_parents(&[&commit_a]);
|
||||
let commit_c = graph_builder.commit_with_parents(&[&commit_b]);
|
||||
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
|
||||
.set_description("b2".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let mut rebaser = tx.mut_repo().create_descendant_rebaser(&settings);
|
||||
|
@ -814,7 +814,7 @@ fn test_rebase_descendants_repeated(use_git: bool) {
|
|||
assert_eq!(rebaser.rebased().len(), 0);
|
||||
|
||||
// Now mark B3 as rewritten from B2 and rebase descendants again.
|
||||
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b2)
|
||||
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, &commit_b2)
|
||||
.set_description("b3".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let mut rebaser = tx.mut_repo().create_descendant_rebaser(&settings);
|
||||
|
@ -849,21 +849,21 @@ fn test_rebase_descendants_contents(use_git: bool) {
|
|||
let mut tx = repo.start_transaction("test");
|
||||
let path1 = RepoPath::from_internal_string("file1");
|
||||
let tree1 = testutils::create_tree(repo, &[(&path1, "content")]);
|
||||
let commit_a = CommitBuilder::for_new_commit(&settings, repo.store(), tree1.id().clone())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_a =
|
||||
CommitBuilder::for_new_commit(&settings, tree1.id().clone()).write_to_repo(tx.mut_repo());
|
||||
let path2 = RepoPath::from_internal_string("file2");
|
||||
let tree2 = testutils::create_tree(repo, &[(&path2, "content")]);
|
||||
let commit_b = CommitBuilder::for_new_commit(&settings, repo.store(), tree2.id().clone())
|
||||
let commit_b = CommitBuilder::for_new_commit(&settings, tree2.id().clone())
|
||||
.set_parents(vec![commit_a.id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let path3 = RepoPath::from_internal_string("file3");
|
||||
let tree3 = testutils::create_tree(repo, &[(&path3, "content")]);
|
||||
let commit_c = CommitBuilder::for_new_commit(&settings, repo.store(), tree3.id().clone())
|
||||
let commit_c = CommitBuilder::for_new_commit(&settings, tree3.id().clone())
|
||||
.set_parents(vec![commit_b.id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let path4 = RepoPath::from_internal_string("file4");
|
||||
let tree4 = testutils::create_tree(repo, &[(&path4, "content")]);
|
||||
let commit_d = CommitBuilder::for_new_commit(&settings, repo.store(), tree4.id().clone())
|
||||
let commit_d = CommitBuilder::for_new_commit(&settings, tree4.id().clone())
|
||||
.set_parents(vec![commit_a.id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
|
||||
|
@ -918,8 +918,8 @@ fn test_rebase_descendants_basic_branch_update() {
|
|||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_b2 =
|
||||
CommitBuilder::for_rewrite_from(&settings, &commit_b).write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
|
@ -958,10 +958,10 @@ fn test_rebase_descendants_branch_move_two_steps() {
|
|||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_c2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_c)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_b2 =
|
||||
CommitBuilder::for_rewrite_from(&settings, &commit_b).write_to_repo(tx.mut_repo());
|
||||
let commit_c2 =
|
||||
CommitBuilder::for_rewrite_from(&settings, &commit_c).write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
let heads = tx.mut_repo().view().heads();
|
||||
assert_eq!(heads.len(), 1);
|
||||
|
@ -1005,8 +1005,8 @@ fn test_rebase_descendants_basic_branch_update_with_non_local_branch() {
|
|||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_b2 =
|
||||
CommitBuilder::for_rewrite_from(&settings, &commit_b).write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
|
@ -1087,14 +1087,14 @@ fn test_rebase_descendants_update_branches_after_divergent_rewrite() {
|
|||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.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, repo.store(), &commit_b)
|
||||
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
|
||||
.set_description("different".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
// Different description so they're not the same commit
|
||||
let commit_b4 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
let commit_b4 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
|
||||
.set_description("more different".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
|
@ -1144,16 +1144,16 @@ fn test_rebase_descendants_rewrite_updates_branch_conflict() {
|
|||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit_a2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_a)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_a2 =
|
||||
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, repo.store(), &commit_a)
|
||||
let commit_a3 = CommitBuilder::for_rewrite_from(&settings, &commit_a)
|
||||
.set_description("different".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.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, repo.store(), &commit_b)
|
||||
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
|
||||
.set_description("different".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
|
@ -1209,7 +1209,7 @@ fn test_rebase_descendants_rewrite_resolves_branch_conflict() {
|
|||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, &commit_b)
|
||||
.set_parents(vec![commit_c.id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
|
@ -1285,7 +1285,7 @@ fn test_rebase_descendants_update_checkout(use_git: bool) {
|
|||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit_c = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
let commit_c = CommitBuilder::for_rewrite_from(&settings, &commit_b)
|
||||
.set_description("C".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
|
|
|
@ -478,7 +478,7 @@ fn test_merge_views_child_on_rewritten(child_first: bool) {
|
|||
.write_to_repo(tx1.mut_repo());
|
||||
|
||||
let mut tx2 = repo.start_transaction("test");
|
||||
let commit_a2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_a)
|
||||
let commit_a2 = CommitBuilder::for_rewrite_from(&settings, &commit_a)
|
||||
.set_description("A2".to_string())
|
||||
.write_to_repo(tx2.mut_repo());
|
||||
tx2.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
|
@ -525,7 +525,7 @@ fn test_merge_views_child_on_rewritten_divergent(on_rewritten: bool, child_first
|
|||
.write_to_repo(tx1.mut_repo());
|
||||
|
||||
let mut tx2 = repo.start_transaction("test");
|
||||
let commit_a4 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_a2)
|
||||
let commit_a4 = CommitBuilder::for_rewrite_from(&settings, &commit_a2)
|
||||
.set_description("A4".to_string())
|
||||
.write_to_repo(tx2.mut_repo());
|
||||
tx2.mut_repo().rebase_descendants(&settings).unwrap();
|
||||
|
|
|
@ -677,13 +677,9 @@ impl WorkspaceCommandHelper {
|
|||
if new_tree_id != *checkout_commit.tree_id() {
|
||||
let mut tx = self.repo.start_transaction("commit working copy");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let commit = CommitBuilder::for_rewrite_from(
|
||||
&self.settings,
|
||||
self.repo.store(),
|
||||
&checkout_commit,
|
||||
)
|
||||
.set_tree(new_tree_id)
|
||||
.write_to_repo(mut_repo);
|
||||
let commit = CommitBuilder::for_rewrite_from(&self.settings, &checkout_commit)
|
||||
.set_tree(new_tree_id)
|
||||
.write_to_repo(mut_repo);
|
||||
mut_repo.set_checkout(workspace_id, commit.id().clone());
|
||||
|
||||
// Rebase descendants
|
||||
|
@ -2204,7 +2200,7 @@ fn cmd_untrack(
|
|||
locked_working_copy.reset(&new_tree)?;
|
||||
}
|
||||
}
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &store, ¤t_checkout)
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), ¤t_checkout)
|
||||
.set_tree(new_tree_id)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let num_rebased = tx.mut_repo().rebase_descendants(ui.settings())?;
|
||||
|
@ -3332,7 +3328,6 @@ fn cmd_describe(
|
|||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let commit = workspace_command.resolve_single_rev(ui, &args.revision)?;
|
||||
workspace_command.check_rewriteable(&commit)?;
|
||||
let repo = workspace_command.repo();
|
||||
let description;
|
||||
if args.stdin {
|
||||
let mut buffer = String::new();
|
||||
|
@ -3341,14 +3336,14 @@ fn cmd_describe(
|
|||
} else if let Some(message) = &args.message {
|
||||
description = message.to_owned()
|
||||
} else {
|
||||
description = edit_description(ui, repo, commit.description())?;
|
||||
description = edit_description(ui, workspace_command.repo(), commit.description())?;
|
||||
}
|
||||
if description == *commit.description() {
|
||||
ui.write("Nothing changed.\n")?;
|
||||
} else {
|
||||
let mut tx =
|
||||
workspace_command.start_transaction(&format!("describe commit {}", commit.id().hex()));
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &commit)
|
||||
.set_description(description)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
workspace_command.finish_transaction(ui, tx)?;
|
||||
|
@ -3360,9 +3355,8 @@ fn cmd_open(ui: &mut Ui, command: &CommandHelper, args: &OpenArgs) -> Result<(),
|
|||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let commit = workspace_command.resolve_single_rev(ui, &args.revision)?;
|
||||
workspace_command.check_rewriteable(&commit)?;
|
||||
let repo = workspace_command.repo();
|
||||
let mut tx = workspace_command.start_transaction(&format!("open commit {}", commit.id().hex()));
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &commit)
|
||||
.set_open(true)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
workspace_command.finish_transaction(ui, tx)?;
|
||||
|
@ -3373,15 +3367,18 @@ fn cmd_close(ui: &mut Ui, command: &CommandHelper, args: &CloseArgs) -> Result<(
|
|||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let commit = workspace_command.resolve_single_rev(ui, &args.revision)?;
|
||||
workspace_command.check_rewriteable(&commit)?;
|
||||
let repo = workspace_command.repo();
|
||||
let mut commit_builder =
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit).set_open(false);
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &commit).set_open(false);
|
||||
let description = if let Some(message) = &args.message {
|
||||
message.to_string()
|
||||
} else if commit.description().is_empty() {
|
||||
edit_description(ui, repo, "\n\nJJ: Enter commit description.\n")?
|
||||
edit_description(
|
||||
ui,
|
||||
workspace_command.repo(),
|
||||
"\n\nJJ: Enter commit description.\n",
|
||||
)?
|
||||
} else if args.edit {
|
||||
edit_description(ui, repo, commit.description())?
|
||||
edit_description(ui, workspace_command.repo(), commit.description())?
|
||||
} else {
|
||||
commit.description().to_string()
|
||||
};
|
||||
|
@ -3393,7 +3390,6 @@ fn cmd_close(ui: &mut Ui, command: &CommandHelper, args: &CloseArgs) -> Result<(
|
|||
if !workspace_ids.is_empty() {
|
||||
let new_checkout = CommitBuilder::for_open_commit(
|
||||
ui.settings(),
|
||||
repo.store(),
|
||||
new_commit.id().clone(),
|
||||
new_commit.tree_id().clone(),
|
||||
)
|
||||
|
@ -3413,11 +3409,10 @@ fn cmd_duplicate(
|
|||
) -> Result<(), CommandError> {
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let predecessor = workspace_command.resolve_single_rev(ui, &args.revision)?;
|
||||
let repo = workspace_command.repo();
|
||||
let mut tx = workspace_command
|
||||
.start_transaction(&format!("duplicate commit {}", predecessor.id().hex()));
|
||||
let mut_repo = tx.mut_repo();
|
||||
let new_commit = CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &predecessor)
|
||||
let new_commit = CommitBuilder::for_rewrite_from(ui.settings(), &predecessor)
|
||||
.generate_new_change_id()
|
||||
.write_to_repo(mut_repo);
|
||||
ui.write("Created: ")?;
|
||||
|
@ -3493,10 +3488,8 @@ fn cmd_edit(ui: &mut Ui, command: &CommandHelper, args: &EditArgs) -> Result<(),
|
|||
fn cmd_new(ui: &mut Ui, command: &CommandHelper, args: &NewArgs) -> Result<(), CommandError> {
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let parent = workspace_command.resolve_single_rev(ui, &args.revision)?;
|
||||
let repo = workspace_command.repo();
|
||||
let commit_builder = CommitBuilder::for_open_commit(
|
||||
ui.settings(),
|
||||
repo.store(),
|
||||
parent.id().clone(),
|
||||
parent.tree_id().clone(),
|
||||
)
|
||||
|
@ -3567,7 +3560,7 @@ from the source will be moved into the destination.
|
|||
if new_source_tree_id == *parent_tree.id() && !repo.view().is_checkout(source.id()) {
|
||||
mut_repo.record_abandoned_commit(source.id().clone());
|
||||
} else {
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &source)
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &source)
|
||||
.set_tree(new_source_tree_id)
|
||||
.write_to_repo(mut_repo);
|
||||
}
|
||||
|
@ -3583,7 +3576,7 @@ from the source will be moved into the destination.
|
|||
}
|
||||
// Apply the selected changes onto the destination
|
||||
let new_destination_tree_id = merge_trees(&destination.tree(), &parent_tree, &new_parent_tree)?;
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &destination)
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &destination)
|
||||
.set_tree(new_destination_tree_id)
|
||||
.write_to_repo(mut_repo);
|
||||
workspace_command.finish_transaction(ui, tx)?;
|
||||
|
@ -3638,7 +3631,7 @@ from the source will be moved into the parent.
|
|||
// (always the case in the non-interactive case).
|
||||
let abandon_child =
|
||||
&new_parent_tree_id == commit.tree_id() && !repo.view().is_checkout(commit.id());
|
||||
let new_parent = CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), parent)
|
||||
let new_parent = CommitBuilder::for_rewrite_from(ui.settings(), parent)
|
||||
.set_tree(new_parent_tree_id)
|
||||
.set_predecessors(vec![parent.id().clone(), commit.id().clone()])
|
||||
.write_to_repo(mut_repo);
|
||||
|
@ -3646,7 +3639,7 @@ from the source will be moved into the parent.
|
|||
mut_repo.record_abandoned_commit(commit.id().clone());
|
||||
} else {
|
||||
// Commit the remainder on top of the new parent commit.
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &commit)
|
||||
.set_parents(vec![new_parent.id().clone()])
|
||||
.write_to_repo(mut_repo);
|
||||
}
|
||||
|
@ -3674,7 +3667,8 @@ fn cmd_unsquash(
|
|||
let mut tx =
|
||||
workspace_command.start_transaction(&format!("unsquash commit {}", commit.id().hex()));
|
||||
let mut_repo = tx.mut_repo();
|
||||
let parent_base_tree = merge_commit_trees(repo.as_repo_ref(), &parent.parents());
|
||||
let parent_base_tree =
|
||||
merge_commit_trees(workspace_command.repo().as_repo_ref(), &parent.parents());
|
||||
let new_parent_tree_id;
|
||||
if args.interactive {
|
||||
let instructions = format!(
|
||||
|
@ -3705,16 +3699,16 @@ aborted.
|
|||
if &new_parent_tree_id == parent_base_tree.id() && !repo.view().is_checkout(parent.id()) {
|
||||
mut_repo.record_abandoned_commit(parent.id().clone());
|
||||
// Commit the new child on top of the parent's parents.
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &commit)
|
||||
.set_parents(parent.parent_ids())
|
||||
.write_to_repo(mut_repo);
|
||||
} else {
|
||||
let new_parent = CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), parent)
|
||||
let new_parent = CommitBuilder::for_rewrite_from(ui.settings(), parent)
|
||||
.set_tree(new_parent_tree_id)
|
||||
.set_predecessors(vec![parent.id().clone(), commit.id().clone()])
|
||||
.write_to_repo(mut_repo);
|
||||
// Commit the new child on top of the new parent.
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
|
||||
CommitBuilder::for_rewrite_from(ui.settings(), &commit)
|
||||
.set_parents(vec![new_parent.id().clone()])
|
||||
.write_to_repo(mut_repo);
|
||||
}
|
||||
|
@ -3737,7 +3731,6 @@ fn cmd_restore(
|
|||
let from_commit = workspace_command.resolve_single_rev(ui, from_str)?;
|
||||
let to_commit = workspace_command.resolve_single_rev(ui, to_str)?;
|
||||
workspace_command.check_rewriteable(&to_commit)?;
|
||||
let repo = workspace_command.repo();
|
||||
let tree_id;
|
||||
if args.interactive {
|
||||
let instructions = format!(
|
||||
|
@ -3763,7 +3756,10 @@ side. If you don't make any changes, then the operation will be aborted.
|
|||
)?;
|
||||
} else if !args.paths.is_empty() {
|
||||
let matcher = matcher_from_values(ui, workspace_command.workspace_root(), &args.paths)?;
|
||||
let mut tree_builder = repo.store().tree_builder(to_commit.tree_id().clone());
|
||||
let mut tree_builder = workspace_command
|
||||
.repo()
|
||||
.store()
|
||||
.tree_builder(to_commit.tree_id().clone());
|
||||
for (repo_path, diff) in from_commit.tree().diff(&to_commit.tree(), matcher.as_ref()) {
|
||||
match diff.into_options().0 {
|
||||
Some(value) => {
|
||||
|
@ -3784,7 +3780,7 @@ side. If you don't make any changes, then the operation will be aborted.
|
|||
let mut tx = workspace_command
|
||||
.start_transaction(&format!("restore into commit {}", to_commit.id().hex()));
|
||||
let mut_repo = tx.mut_repo();
|
||||
let new_commit = CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &to_commit)
|
||||
let new_commit = CommitBuilder::for_rewrite_from(ui.settings(), &to_commit)
|
||||
.set_tree(tree_id)
|
||||
.write_to_repo(mut_repo);
|
||||
ui.write("Created ")?;
|
||||
|
@ -3807,8 +3803,7 @@ fn cmd_touchup(
|
|||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let commit = workspace_command.resolve_single_rev(ui, &args.revision)?;
|
||||
workspace_command.check_rewriteable(&commit)?;
|
||||
let repo = workspace_command.repo();
|
||||
let base_tree = merge_commit_trees(repo.as_repo_ref(), &commit.parents());
|
||||
let base_tree = merge_commit_trees(workspace_command.repo().as_repo_ref(), &commit.parents());
|
||||
let instructions = format!(
|
||||
"\
|
||||
You are editing changes in: {}
|
||||
|
@ -3826,7 +3821,7 @@ don't make any changes, then the operation will be aborted.",
|
|||
let mut tx =
|
||||
workspace_command.start_transaction(&format!("edit commit {}", commit.id().hex()));
|
||||
let mut_repo = tx.mut_repo();
|
||||
let new_commit = CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
|
||||
let new_commit = CommitBuilder::for_rewrite_from(ui.settings(), &commit)
|
||||
.set_tree(tree_id)
|
||||
.write_to_repo(mut_repo);
|
||||
ui.write("Created ")?;
|
||||
|
@ -3880,7 +3875,7 @@ any changes, then the operation will be aborted.
|
|||
&("JJ: Enter commit description for the first part.\n".to_string()
|
||||
+ commit.description()),
|
||||
)?;
|
||||
let first_commit = CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
|
||||
let first_commit = CommitBuilder::for_rewrite_from(ui.settings(), &commit)
|
||||
.set_tree(tree_id)
|
||||
.set_description(first_description)
|
||||
.write_to_repo(mut_repo);
|
||||
|
@ -3890,7 +3885,7 @@ any changes, then the operation will be aborted.
|
|||
&("JJ: Enter commit description for the second part.\n".to_string()
|
||||
+ commit.description()),
|
||||
)?;
|
||||
let second_commit = CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
|
||||
let second_commit = CommitBuilder::for_rewrite_from(ui.settings(), &commit)
|
||||
.set_parents(vec![first_commit.id().clone()])
|
||||
.set_tree(commit.tree_id().clone())
|
||||
.generate_new_change_id()
|
||||
|
@ -3955,7 +3950,7 @@ fn cmd_merge(ui: &mut Ui, command: &CommandHelper, args: &MergeArgs) -> Result<(
|
|||
};
|
||||
let merged_tree = merge_commit_trees(repo.as_repo_ref(), &commits);
|
||||
let mut tx = workspace_command.start_transaction("merge commits");
|
||||
CommitBuilder::for_new_commit(ui.settings(), repo.store(), merged_tree.id().clone())
|
||||
CommitBuilder::for_new_commit(ui.settings(), merged_tree.id().clone())
|
||||
.set_parents(parent_ids)
|
||||
.set_description(description)
|
||||
.set_open(false)
|
||||
|
|
Loading…
Reference in a new issue