From e5ebc301176352ad476fdfeb122d8403b640bb73 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 17 Sep 2024 19:09:13 +0200 Subject: [PATCH] repo: introduce `MutableRepo::reparent_descendants()` --- lib/src/repo.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 6be4b4fc9c..bd8a33c76b 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -1334,6 +1334,27 @@ impl MutableRepo { Ok(num_rebased) } + /// Reparent descendants of the rewritten commits. + /// + /// The descendants of the commits registered in `self.parent_mappings` will + /// be recursively reparented onto the new version of their parents. + /// The content of those descendants will remain untouched. + /// Returns the number of reparented descendants. + pub fn reparent_descendants(&mut self, settings: &UserSettings) -> BackendResult { + let roots = self.parent_mapping.keys().cloned().collect_vec(); + let mut num_reparented = 0; + self.transform_descendants(settings, roots, |rewriter| { + if rewriter.parents_changed() { + let builder = rewriter.reparent(settings)?; + builder.write()?; + num_reparented += 1; + } + Ok(()) + })?; + self.parent_mapping.clear(); + Ok(num_reparented) + } + pub fn rebase_descendants_return_map( &mut self, settings: &UserSettings,