mirror of
https://github.com/martinvonz/jj.git
synced 2024-10-24 07:32:54 +00:00
repo: extract a function for abandoning previous checkout
This is a little refactoring to prepare for removing the `open` flag off of commits.
This commit is contained in:
parent
54285a9c56
commit
9a3c6928cc
1 changed files with 16 additions and 12 deletions
|
@ -584,18 +584,7 @@ impl MutableRepo {
|
|||
settings: &UserSettings,
|
||||
commit: &Commit,
|
||||
) -> Commit {
|
||||
let maybe_current_checkout_id = self.view.borrow().get_checkout(&workspace_id).cloned();
|
||||
if let Some(current_checkout_id) = maybe_current_checkout_id {
|
||||
let current_checkout = self.store().get_commit(¤t_checkout_id).unwrap();
|
||||
assert!(current_checkout.is_open(), "current checkout is closed");
|
||||
if current_checkout.is_empty()
|
||||
&& current_checkout.description().is_empty()
|
||||
&& self.view().heads().contains(current_checkout.id())
|
||||
{
|
||||
// Abandon the checkout we're leaving if it's empty and a head commit
|
||||
self.record_abandoned_commit(current_checkout_id);
|
||||
}
|
||||
}
|
||||
self.leave_commit(&workspace_id);
|
||||
let open_commit = if !commit.is_open() {
|
||||
// If the commit is closed, create a new open commit on top
|
||||
CommitBuilder::for_open_commit(
|
||||
|
@ -614,6 +603,21 @@ impl MutableRepo {
|
|||
open_commit
|
||||
}
|
||||
|
||||
fn leave_commit(&mut self, workspace_id: &WorkspaceId) {
|
||||
let maybe_current_checkout_id = self.view.borrow().get_checkout(workspace_id).cloned();
|
||||
if let Some(current_checkout_id) = maybe_current_checkout_id {
|
||||
let current_checkout = self.store().get_commit(¤t_checkout_id).unwrap();
|
||||
assert!(current_checkout.is_open(), "current checkout is closed");
|
||||
if current_checkout.is_empty()
|
||||
&& current_checkout.description().is_empty()
|
||||
&& self.view().heads().contains(current_checkout.id())
|
||||
{
|
||||
// Abandon the checkout we're leaving if it's empty and a head commit
|
||||
self.record_abandoned_commit(current_checkout_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn enforce_view_invariants(&self) {
|
||||
if !self.view_dirty {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue