mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 13:23:09 +00:00
Never rewrite history file when adding ephemeral items
When I run a command with leading space, it is not added to the on-disk history. However we still call History::save(). After 25 of such calls, we rewrite the history file (even though nothing was written by us). This is annoying when diagnosing #10300 where the history of the current shell (but not other shells) is broken; because the history rewrite will make the problem go away. Let's not save in this case, to make it easier to run commands to inspect the state of the history file.
This commit is contained in:
parent
33bcf4d0ce
commit
f36f757fa6
1 changed files with 7 additions and 4 deletions
|
@ -375,7 +375,7 @@ struct HistoryImpl {
|
||||||
/// The most recent "unique" identifier for a history item.
|
/// The most recent "unique" identifier for a history item.
|
||||||
last_identifier: HistoryIdentifier, // 0
|
last_identifier: HistoryIdentifier, // 0
|
||||||
/// How many items we add until the next vacuum. Initially a random value.
|
/// How many items we add until the next vacuum. Initially a random value.
|
||||||
countdown_to_vacuum: Option<usize>, // -1
|
countdown_to_vacuum: Option<usize>,
|
||||||
/// Whether we've loaded old items.
|
/// Whether we've loaded old items.
|
||||||
loaded_old: bool, // false
|
loaded_old: bool, // false
|
||||||
/// List of old items, as offsets into out mmap data.
|
/// List of old items, as offsets into out mmap data.
|
||||||
|
@ -1581,6 +1581,7 @@ impl History {
|
||||||
let when = imp.timestamp_now();
|
let when = imp.timestamp_now();
|
||||||
let identifier = imp.next_identifier();
|
let identifier = imp.next_identifier();
|
||||||
let item = HistoryItem::new(s.to_owned(), when, identifier, persist_mode);
|
let item = HistoryItem::new(s.to_owned(), when, identifier, persist_mode);
|
||||||
|
let do_save = persist_mode != PersistenceMode::Ephemeral;
|
||||||
|
|
||||||
if wants_file_detection {
|
if wants_file_detection {
|
||||||
imp.disable_automatic_saving();
|
imp.disable_automatic_saving();
|
||||||
|
@ -1596,14 +1597,16 @@ impl History {
|
||||||
let validated_paths = expand_and_detect_paths(potential_paths, &vars_snapshot);
|
let validated_paths = expand_and_detect_paths(potential_paths, &vars_snapshot);
|
||||||
let mut imp = self.imp();
|
let mut imp = self.imp();
|
||||||
imp.set_valid_file_paths(validated_paths, identifier);
|
imp.set_valid_file_paths(validated_paths, identifier);
|
||||||
imp.enable_automatic_saving();
|
if do_save {
|
||||||
|
imp.enable_automatic_saving();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Add the item.
|
// Add the item.
|
||||||
// If we think we're about to exit, save immediately, regardless of any disabling. This may
|
// 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.
|
// cause us to lose file hinting for some commands, but it beats losing history items.
|
||||||
imp.add(item, /*pending=*/ true, /*do_save=*/ true);
|
imp.add(item, /*pending=*/ true, do_save);
|
||||||
if needs_sync_write {
|
if do_save && needs_sync_write {
|
||||||
imp.save(false);
|
imp.save(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue