forked from mirrors/jj
cli: teach RepoCommand to commit transaction and update working copy
This commit is contained in:
parent
e913f03a06
commit
6716a5f069
1 changed files with 30 additions and 37 deletions
|
@ -45,6 +45,7 @@ use jujube_lib::rewrite::{back_out_commit, merge_commit_trees, rebase_commit};
|
|||
use jujube_lib::settings::UserSettings;
|
||||
use jujube_lib::store::{StoreError, Timestamp, TreeValue};
|
||||
use jujube_lib::store_wrapper::StoreWrapper;
|
||||
use jujube_lib::transaction::Transaction;
|
||||
use jujube_lib::tree::Tree;
|
||||
use jujube_lib::trees::Diff;
|
||||
use jujube_lib::working_copy::{CheckoutStats, WorkingCopy};
|
||||
|
@ -198,6 +199,15 @@ impl RepoCommand {
|
|||
self.repo = reloaded_repo;
|
||||
commit
|
||||
}
|
||||
|
||||
fn finish_transaction(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
tx: Transaction,
|
||||
) -> Result<Option<CheckoutStats>, CommandError> {
|
||||
self.repo = tx.commit();
|
||||
update_working_copy(ui, &self.repo, &self.repo.working_copy_locked())
|
||||
}
|
||||
}
|
||||
|
||||
fn rev_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||
|
@ -679,8 +689,7 @@ fn cmd_checkout(
|
|||
let repo = repo_command.repo();
|
||||
let mut tx = repo.start_transaction(&format!("check out commit {}", new_commit.id().hex()));
|
||||
tx.mut_repo().check_out(ui.settings(), &new_commit);
|
||||
let repo = tx.commit();
|
||||
let stats = update_working_copy(ui, &repo, &repo.working_copy_locked())?;
|
||||
let stats = repo_command.finish_transaction(ui, tx)?;
|
||||
match stats {
|
||||
None => ui.write("Already on that commit\n")?,
|
||||
Some(stats) => writeln!(
|
||||
|
@ -1247,8 +1256,7 @@ fn cmd_describe(
|
|||
.set_description(description)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
update_checkout_after_rewrite(ui, tx.mut_repo())?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1265,8 +1273,7 @@ fn cmd_open(
|
|||
.set_open(true)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
update_checkout_after_rewrite(ui, tx.mut_repo())?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1292,8 +1299,7 @@ fn cmd_close(
|
|||
let mut tx = repo.start_transaction(&format!("close commit {}", commit.id().hex()));
|
||||
commit_builder.write_to_repo(tx.mut_repo());
|
||||
update_checkout_after_rewrite(ui, tx.mut_repo())?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1335,8 +1341,7 @@ fn cmd_prune(
|
|||
.set_pruned(true)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
update_checkout_after_rewrite(ui, tx.mut_repo())?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1360,8 +1365,7 @@ fn cmd_new(
|
|||
if mut_repo.view().checkout() == parent.id() {
|
||||
mut_repo.check_out(ui.settings(), &new_commit);
|
||||
}
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1409,8 +1413,7 @@ fn cmd_squash(
|
|||
.set_pruned(prune_child)
|
||||
.write_to_repo(mut_repo);
|
||||
update_checkout_after_rewrite(ui, mut_repo)?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1459,8 +1462,7 @@ fn cmd_unsquash(
|
|||
.set_parents(vec![new_parent.id().clone()])
|
||||
.write_to_repo(mut_repo);
|
||||
update_checkout_after_rewrite(ui, mut_repo)?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1538,8 +1540,7 @@ fn cmd_restore(
|
|||
ui.write_commit_summary(mut_repo.as_repo_ref(), &new_commit)?;
|
||||
ui.write("\n")?;
|
||||
update_checkout_after_rewrite(ui, mut_repo)?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1566,8 +1567,7 @@ fn cmd_edit(
|
|||
ui.write_commit_summary(mut_repo.as_repo_ref(), &new_commit)?;
|
||||
ui.write("\n")?;
|
||||
update_checkout_after_rewrite(ui, mut_repo)?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1607,8 +1607,7 @@ fn cmd_split(
|
|||
ui.write_commit_summary(mut_repo.as_repo_ref(), &second_commit)?;
|
||||
ui.write("\n")?;
|
||||
update_checkout_after_rewrite(ui, mut_repo)?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1647,8 +1646,7 @@ fn cmd_merge(
|
|||
.set_open(false)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
update_checkout_after_rewrite(ui, tx.mut_repo())?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1669,8 +1667,7 @@ fn cmd_rebase(
|
|||
let mut tx = repo.start_transaction(&format!("rebase commit {}", commit_to_rebase.id().hex()));
|
||||
rebase_commit(ui.settings(), tx.mut_repo(), &commit_to_rebase, &parents);
|
||||
update_checkout_after_rewrite(ui, tx.mut_repo())?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1694,8 +1691,7 @@ fn cmd_backout(
|
|||
));
|
||||
back_out_commit(ui.settings(), tx.mut_repo(), &commit_to_back_out, &parents);
|
||||
update_checkout_after_rewrite(ui, tx.mut_repo())?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1705,7 +1701,7 @@ fn cmd_evolve<'s>(
|
|||
matches: &ArgMatches,
|
||||
_sub_matches: &ArgMatches,
|
||||
) -> Result<(), CommandError> {
|
||||
let repo_command = RepoCommand::new(ui, matches)?;
|
||||
let mut repo_command = RepoCommand::new(ui, matches)?;
|
||||
|
||||
struct Listener<'a, 's> {
|
||||
ui: &'a mut Ui<'s>,
|
||||
|
@ -1795,8 +1791,7 @@ fn cmd_evolve<'s>(
|
|||
let mut tx = repo.start_transaction("evolve");
|
||||
evolve(&user_settings, tx.mut_repo(), &mut listener);
|
||||
update_checkout_after_rewrite(ui, tx.mut_repo())?;
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -2028,7 +2023,7 @@ fn cmd_op_undo(
|
|||
_op_matches: &ArgMatches,
|
||||
_cmd_matches: &ArgMatches,
|
||||
) -> Result<(), CommandError> {
|
||||
let repo_command = RepoCommand::new(ui, matches)?;
|
||||
let mut repo_command = RepoCommand::new(ui, matches)?;
|
||||
let repo = repo_command.repo();
|
||||
let bad_op = resolve_single_op(&repo, _cmd_matches.value_of("operation").unwrap())?;
|
||||
let parent_ops = bad_op.parents();
|
||||
|
@ -2047,8 +2042,7 @@ fn cmd_op_undo(
|
|||
let bad_repo = repo.loader().load_at(&bad_op)?;
|
||||
let parent_repo = repo.loader().load_at(&parent_ops[0])?;
|
||||
tx.mut_repo().merge(&bad_repo, &parent_repo);
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -2058,13 +2052,12 @@ fn cmd_op_restore(
|
|||
_op_matches: &ArgMatches,
|
||||
_cmd_matches: &ArgMatches,
|
||||
) -> Result<(), CommandError> {
|
||||
let repo_command = RepoCommand::new(ui, matches)?;
|
||||
let mut repo_command = RepoCommand::new(ui, matches)?;
|
||||
let repo = repo_command.repo();
|
||||
let target_op = resolve_single_op(&repo, _cmd_matches.value_of("operation").unwrap())?;
|
||||
let mut tx = repo.start_transaction(&format!("restore to operation {}", target_op.id().hex()));
|
||||
tx.mut_repo().set_view(target_op.view().take_store_view());
|
||||
let repo = tx.commit();
|
||||
update_working_copy(ui, &repo, &repo.working_copy().lock().unwrap())?;
|
||||
repo_command.finish_transaction(ui, tx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue