Bugfix (consider porting): undo triggered

Transaction::cancel was sometimes triggering an undo:
when the current transaction was empty, "commit" did just
remove it which made the subsequent undo act on the
*previous* transaction.
This commit is contained in:
Matthias Koefferlein 2020-12-01 23:00:11 +01:00
parent 63819e3292
commit 9305861102
1 changed files with 15 additions and 6 deletions

View File

@ -147,15 +147,24 @@ Manager::last_transaction_id () const
void
Manager::cancel ()
{
// equivalent to commit and undo. But takes care that an empty commit is not followed by undo
// (which would undo the previous transaction!)
if (m_enabled) {
// commit and undo - revert changes done so far
commit ();
undo ();
tl_assert (m_opened);
tl_assert (! m_replay);
m_opened = false;
// delete all following transactions
erase_transactions (m_current, m_transactions.end ());
m_current = m_transactions.end ();
if (m_current->first.begin () != m_current->first.end ()) {
++m_current;
undo ();
} else {
// empty transactions .. just delete
erase_transactions (m_current, m_transactions.end ());
m_current = m_transactions.end ();
}
}
}