ok/jj
1
0
Fork 0
forked from mirrors/jj

lib repo.rs & rewrite.rs: Move clearing of rewritten/abandoned commits

This commit is a little out of place in this sequence, but
it seems to make more sense for MutRepo to own these maps.

@yuja [pointed out] that any tests written using `create_descendant_rebaser` now
need to do this cleanup, but there are no longer any such tests after the
previous commits and a follow-up commit removes `create_descendant_rebaser`
entirely.

[pointed out]: https://github.com/martinvonz/jj/pull/2737#discussion_r1435754370
This commit is contained in:
Ilya Grigoriev 2023-12-17 21:47:01 -08:00
parent 4461d61254
commit 7cef879ef6
2 changed files with 12 additions and 11 deletions

View file

@ -859,10 +859,6 @@ impl MutableRepo {
.insert(new_id);
}
pub fn clear_rewritten_commits(&mut self) {
self.rewritten_commits.clear();
}
/// Record a commit as having been abandoned in this transaction.
///
/// This record is used by `rebase_descendants` to know which commits have
@ -877,7 +873,8 @@ impl MutableRepo {
self.abandoned_commits.insert(old_id);
}
pub fn clear_abandoned_commits(&mut self) {
fn clear_descendant_rebaser_plans(&mut self) {
self.rewritten_commits.clear();
self.abandoned_commits.clear();
}
@ -900,6 +897,8 @@ impl MutableRepo {
)
}
/// After the rebaser returned by this function is dropped,
/// self.clear_descendant_rebaser_plans() needs to be called.
fn rebase_descendants_return_rebaser<'settings, 'repo>(
&'repo mut self,
settings: &'settings UserSettings,
@ -923,9 +922,11 @@ impl MutableRepo {
settings: &UserSettings,
options: RebaseOptions,
) -> Result<usize, TreeMergeError> {
Ok(self
let result = self
.rebase_descendants_return_rebaser(settings, options)?
.map_or(0, |rebaser| rebaser.rebased().len()))
.map_or(0, |rebaser| rebaser.rebased().len());
self.clear_descendant_rebaser_plans();
Ok(result)
}
pub fn rebase_descendants(&mut self, settings: &UserSettings) -> Result<usize, TreeMergeError> {
@ -936,12 +937,14 @@ impl MutableRepo {
&mut self,
settings: &UserSettings,
) -> Result<HashMap<CommitId, CommitId>, TreeMergeError> {
Ok(self
let result = Ok(self
// We do not set RebaseOptions here, since this function does not currently return
// enough information to describe the results of a rebase if some commits got
// abandoned
.rebase_descendants_return_rebaser(settings, Default::default())?
.map_or(HashMap::new(), |rebaser| rebaser.rebased().clone()))
.map_or(HashMap::new(), |rebaser| rebaser.rebased().clone()));
self.clear_descendant_rebaser_plans();
result
}
pub fn set_wc_commit(

View file

@ -600,8 +600,6 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
self.heads_to_remove.clear();
self.heads_to_add.clear();
self.mut_repo.set_view(view);
self.mut_repo.clear_rewritten_commits();
self.mut_repo.clear_abandoned_commits();
Ok(None)
}