From 4d6544591e734d950da7fc4b0ab9c4e3aacc772d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 29 Jan 2025 09:43:02 +0100 Subject: [PATCH] Fix regression breaking automatic history saving after adding ephemeral items Cherry-picked from acf9ba4195 (Fix regression causing missing automatic history saving after adding ephemeral items, 2025-01-29) --- src/history.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/history.rs b/src/history.rs index 458836a41..565c83f53 100644 --- a/src/history.rs +++ b/src/history.rs @@ -1080,7 +1080,6 @@ fn disable_automatic_saving(&mut self) { fn enable_automatic_saving(&mut self) { assert!(self.disable_automatic_save_counter > 0); // negative overflow! self.disable_automatic_save_counter -= 1; - self.save_unless_disabled(); } /// Irreversibly clears history. @@ -1614,7 +1613,7 @@ pub fn add_pending_with_file_detection( let when = imp.timestamp_now(); let identifier = imp.next_identifier(); let item = HistoryItem::new(s.to_owned(), when, identifier, persist_mode); - let do_save = persist_mode != PersistenceMode::Ephemeral; + let to_disk = persist_mode == PersistenceMode::Disk; if wants_file_detection { imp.disable_automatic_saving(); @@ -1622,7 +1621,7 @@ pub fn add_pending_with_file_detection( // Add the item. Then check for which paths are valid on a background thread, // and unblock the item. // Don't hold the lock while we perform this file detection. - imp.add(item, /*pending=*/ true, /*do_save=*/ true); + imp.add(item, /*pending=*/ true, to_disk); drop(imp); let vars_snapshot = vars.snapshot(); iothread_perform(move || { @@ -1630,16 +1629,17 @@ pub fn add_pending_with_file_detection( let validated_paths = expand_and_detect_paths(potential_paths, &vars_snapshot); let mut imp = self.imp(); imp.set_valid_file_paths(validated_paths, identifier); - if do_save { - imp.enable_automatic_saving(); + imp.enable_automatic_saving(); + if to_disk { + imp.save_unless_disabled(); } }); } else { // Add the item. // If we think we're about to exit, save immediately, regardless of any disabling. This may // cause us to lose file hinting for some commands, but it beats losing history items. - imp.add(item, /*pending=*/ true, do_save); - if do_save && needs_sync_write { + imp.add(item, /*pending=*/ true, to_disk); + if to_disk && needs_sync_write { imp.save(false); } }