mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-09 09:22:50 +00:00
repo: add a convenience function for rebasing all descendants
All non-test users of `create_descendant_rebaser()` just want to rebase all commits, so let's make that easy.
This commit is contained in:
parent
9f8c6fe07d
commit
10ebf35c27
@ -528,6 +528,12 @@ impl MutableRepo {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn rebase_descendants(&mut self, settings: &UserSettings) -> usize {
|
||||
let mut rebaser = self.create_descendant_rebaser(settings);
|
||||
rebaser.rebase_all();
|
||||
rebaser.rebased().len()
|
||||
}
|
||||
|
||||
pub fn get_checkout(&mut self) -> CommitId {
|
||||
self.view.borrow().checkout().clone()
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ fn test_checkout_previous_not_empty(use_git: bool) {
|
||||
.set_open(true)
|
||||
.write_to_repo(mut_repo);
|
||||
mut_repo.check_out(&settings, &new_checkout);
|
||||
mut_repo.create_descendant_rebaser(&settings).rebase_all();
|
||||
mut_repo.rebase_descendants(&settings);
|
||||
assert!(mut_repo.view().heads().contains(old_checkout.id()));
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ fn test_checkout_previous_empty(use_git: bool) {
|
||||
.set_open(true)
|
||||
.write_to_repo(mut_repo);
|
||||
mut_repo.check_out(&settings, &new_checkout);
|
||||
mut_repo.create_descendant_rebaser(&settings).rebase_all();
|
||||
mut_repo.rebase_descendants(&settings);
|
||||
assert!(!mut_repo.view().heads().contains(old_checkout.id()));
|
||||
}
|
||||
|
||||
|
@ -811,9 +811,7 @@ fn test_rebase_descendants_basic_branch_update() {
|
||||
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());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_b2.id().clone()))
|
||||
@ -857,9 +855,7 @@ fn test_rebase_descendants_basic_branch_update_with_non_local_branch() {
|
||||
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());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_b2.id().clone()))
|
||||
@ -904,9 +900,7 @@ fn test_rebase_descendants_update_branch_after_abandon() {
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
tx.mut_repo().record_abandoned_commit(commit_b.id().clone());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_a.id().clone()))
|
||||
@ -951,9 +945,7 @@ fn test_rebase_descendants_update_branches_after_divergent_rewrite() {
|
||||
let commit_b4 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.set_description("more different".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Conflict {
|
||||
@ -1013,9 +1005,7 @@ fn test_rebase_descendants_rewrite_updates_branch_conflict() {
|
||||
let commit_b3 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.set_description("different".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Conflict {
|
||||
@ -1077,9 +1067,7 @@ fn test_rebase_descendants_rewrite_resolves_branch_conflict() {
|
||||
let commit_b2 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.set_parents(vec![commit_c.id().clone()])
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
assert_eq!(
|
||||
tx.mut_repo().get_local_branch("main"),
|
||||
Some(RefTarget::Normal(commit_b2.id().clone()))
|
||||
@ -1128,9 +1116,7 @@ fn test_rebase_descendants_update_checkout_open(use_git: bool) {
|
||||
let commit_c = CommitBuilder::for_rewrite_from(&settings, repo.store(), &commit_b)
|
||||
.set_description("C".to_string())
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
let repo = tx.commit();
|
||||
|
||||
assert_eq!(repo.view().checkout(), commit_c.id());
|
||||
@ -1163,9 +1149,7 @@ fn test_rebase_descendants_update_checkout_closed(use_git: bool) {
|
||||
.set_description("C".to_string())
|
||||
.set_open(false)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
let repo = tx.commit();
|
||||
|
||||
let checkout = repo.store().get_commit(repo.view().checkout()).unwrap();
|
||||
@ -1205,9 +1189,7 @@ fn test_rebase_descendants_update_checkout_abandoned_merge(use_git: bool) {
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
tx.mut_repo().record_abandoned_commit(commit_d.id().clone());
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&settings);
|
||||
let repo = tx.commit();
|
||||
|
||||
let checkout = repo.store().get_commit(repo.view().checkout()).unwrap();
|
||||
|
@ -46,7 +46,7 @@ use jujutsu_lib::op_heads_store::OpHeadsStore;
|
||||
use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, RefTarget};
|
||||
use jujutsu_lib::operation::Operation;
|
||||
use jujutsu_lib::refs::{classify_branch_push_action, BranchPushAction};
|
||||
use jujutsu_lib::repo::{MutableRepo, ReadonlyRepo, RepoRef};
|
||||
use jujutsu_lib::repo::{ReadonlyRepo, RepoRef};
|
||||
use jujutsu_lib::repo_path::RepoPath;
|
||||
use jujutsu_lib::revset::{RevsetError, RevsetExpression, RevsetParseError};
|
||||
use jujutsu_lib::revset_graph_iterator::RevsetGraphEdgeType;
|
||||
@ -296,9 +296,7 @@ impl WorkspaceCommandHelper {
|
||||
// so we just need to reset our working copy state to it without updating
|
||||
// working copy files.
|
||||
locked_working_copy.reset(&new_checkout.tree())?;
|
||||
tx.mut_repo()
|
||||
.create_descendant_rebaser(&self.settings)
|
||||
.rebase_all();
|
||||
tx.mut_repo().rebase_descendants(&self.settings);
|
||||
self.repo = tx.commit();
|
||||
locked_working_copy.finish(self.repo.op_id().clone(), new_wc_commit.id().clone());
|
||||
} else {
|
||||
@ -539,7 +537,7 @@ impl WorkspaceCommandHelper {
|
||||
mut_repo.set_checkout(commit.id().clone());
|
||||
|
||||
// Rebase descendants
|
||||
let num_rebased = rebase_descendants(&self.settings, mut_repo);
|
||||
let num_rebased = mut_repo.rebase_descendants(&self.settings);
|
||||
if num_rebased > 0 {
|
||||
writeln!(
|
||||
ui,
|
||||
@ -594,7 +592,7 @@ impl WorkspaceCommandHelper {
|
||||
return Ok(());
|
||||
}
|
||||
if self.rebase_descendants {
|
||||
let num_rebased = rebase_descendants(ui.settings(), mut_repo);
|
||||
let num_rebased = mut_repo.rebase_descendants(ui.settings());
|
||||
if num_rebased > 0 {
|
||||
writeln!(ui, "Rebased {} descendant commits", num_rebased)?;
|
||||
}
|
||||
@ -782,15 +780,6 @@ fn update_working_copy(
|
||||
Ok(Some(stats))
|
||||
}
|
||||
|
||||
fn rebase_descendants(settings: &UserSettings, mut_repo: &mut MutableRepo) -> i32 {
|
||||
let mut rebaser = mut_repo.create_descendant_rebaser(settings);
|
||||
let mut num_rebased = 0;
|
||||
while rebaser.rebase_next().is_some() {
|
||||
num_rebased += 1;
|
||||
}
|
||||
num_rebased
|
||||
}
|
||||
|
||||
fn get_app<'help>() -> App<'help> {
|
||||
let init_command = App::new("init")
|
||||
.about("Create a new repo in the given directory")
|
||||
@ -1695,7 +1684,7 @@ fn cmd_untrack(
|
||||
let new_commit = CommitBuilder::for_rewrite_from(ui.settings(), &store, &old_commit)
|
||||
.set_tree(new_tree_id)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let num_rebased = rebase_descendants(ui.settings(), tx.mut_repo());
|
||||
let num_rebased = tx.mut_repo().rebase_descendants(ui.settings());
|
||||
if num_rebased > 0 {
|
||||
writeln!(ui, "Rebased {} descendant commits", num_rebased)?;
|
||||
}
|
||||
@ -2766,9 +2755,7 @@ fn cmd_abandon(
|
||||
for commit in to_abandon {
|
||||
tx.mut_repo().record_abandoned_commit(commit.id().clone());
|
||||
}
|
||||
let mut rebaser = tx.mut_repo().create_descendant_rebaser(ui.settings());
|
||||
rebaser.rebase_all();
|
||||
let num_rebased = rebaser.rebased().len();
|
||||
let num_rebased = tx.mut_repo().rebase_descendants(ui.settings());
|
||||
if num_rebased > 0 {
|
||||
writeln!(
|
||||
ui,
|
||||
@ -3162,9 +3149,7 @@ fn cmd_rebase(ui: &mut Ui, command: &CommandHelper, args: &ArgMatches) -> Result
|
||||
));
|
||||
workspace_command.check_rewriteable(&old_commit)?;
|
||||
rebase_commit(ui.settings(), tx.mut_repo(), &old_commit, &parents);
|
||||
let mut rebaser = tx.mut_repo().create_descendant_rebaser(ui.settings());
|
||||
rebaser.rebase_all();
|
||||
let num_rebased = rebaser.rebased().len() + 1;
|
||||
let num_rebased = tx.mut_repo().rebase_descendants(ui.settings()) + 1;
|
||||
writeln!(ui, "Rebased {} commits", num_rebased)?;
|
||||
workspace_command.finish_transaction(ui, tx)?;
|
||||
} else {
|
||||
@ -3194,9 +3179,7 @@ fn cmd_rebase(ui: &mut Ui, command: &CommandHelper, args: &ArgMatches) -> Result
|
||||
);
|
||||
num_rebased_descendants += 1;
|
||||
}
|
||||
let mut rebaser = tx.mut_repo().create_descendant_rebaser(ui.settings());
|
||||
rebaser.rebase_all();
|
||||
num_rebased_descendants += rebaser.rebased().len();
|
||||
num_rebased_descendants += tx.mut_repo().rebase_descendants(ui.settings());
|
||||
if num_rebased_descendants > 0 {
|
||||
writeln!(
|
||||
ui,
|
||||
|
Loading…
x
Reference in New Issue
Block a user