mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-18 21:54:26 +00:00
cli: extract a helper for evolving descendants
I want to reuse this bit of code for evolving descendants of a rewritten working copy commit. I expect this to change again soon (I'll probably make it do a regular rebase instead of evolve), but this will do for now.
This commit is contained in:
parent
7deba1172c
commit
0d24e72260
@ -381,27 +381,19 @@ impl RepoCommandHelper {
|
|||||||
) -> Result<Option<CheckoutStats>, CommandError> {
|
) -> Result<Option<CheckoutStats>, CommandError> {
|
||||||
let mut_repo = tx.mut_repo();
|
let mut_repo = tx.mut_repo();
|
||||||
if self.evolve_orphans {
|
if self.evolve_orphans {
|
||||||
let mut orphan_resolver = OrphanResolver::new(ui.settings(), mut_repo);
|
let evolve_result = evolve_orphans(ui.settings(), mut_repo)?;
|
||||||
let mut num_resolved = 0;
|
if evolve_result.num_resolved > 0 {
|
||||||
let mut num_failed = 0;
|
writeln!(
|
||||||
while let Some(resolution) = orphan_resolver.resolve_next(mut_repo) {
|
ui,
|
||||||
match resolution {
|
"Rebased {} descendant commits",
|
||||||
OrphanResolution::Resolved { .. } => {
|
evolve_result.num_resolved
|
||||||
num_resolved += 1;
|
)?;
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
num_failed += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if num_resolved > 0 {
|
if evolve_result.num_failed > 0 {
|
||||||
writeln!(ui, "Rebased {} descendant commits", num_resolved)?;
|
|
||||||
}
|
|
||||||
if num_failed > 0 {
|
|
||||||
writeln!(
|
writeln!(
|
||||||
ui,
|
ui,
|
||||||
"Failed to rebase {} descendant commits (run `jj evolve`)",
|
"Failed to rebase {} descendant commits (run `jj evolve`)",
|
||||||
num_failed
|
evolve_result.num_failed
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -559,6 +551,34 @@ fn update_working_copy(
|
|||||||
Ok(Some(stats))
|
Ok(Some(stats))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct OrphanEvolutionResult {
|
||||||
|
num_resolved: i32,
|
||||||
|
num_failed: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn evolve_orphans(
|
||||||
|
settings: &UserSettings,
|
||||||
|
mut_repo: &mut MutableRepo,
|
||||||
|
) -> Result<OrphanEvolutionResult, CommandError> {
|
||||||
|
let mut orphan_resolver = OrphanResolver::new(settings, mut_repo);
|
||||||
|
let mut num_resolved = 0;
|
||||||
|
let mut num_failed = 0;
|
||||||
|
while let Some(resolution) = orphan_resolver.resolve_next(mut_repo) {
|
||||||
|
match resolution {
|
||||||
|
OrphanResolution::Resolved { .. } => {
|
||||||
|
num_resolved += 1;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
num_failed += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(OrphanEvolutionResult {
|
||||||
|
num_resolved,
|
||||||
|
num_failed,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn update_checkout_after_rewrite(ui: &mut Ui, mut_repo: &mut MutableRepo) -> io::Result<()> {
|
fn update_checkout_after_rewrite(ui: &mut Ui, mut_repo: &mut MutableRepo) -> io::Result<()> {
|
||||||
// TODO: Perhaps this method should be in MutableRepo.
|
// TODO: Perhaps this method should be in MutableRepo.
|
||||||
let new_checkout_candidates = mut_repo
|
let new_checkout_candidates = mut_repo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user