Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new clippy lint from 1.84.0 #872

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions src/history/file_backed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,19 @@ impl History for FileBackedHistory {
fn save(&mut self, h: HistoryItem) -> Result<HistoryItem> {
let entry = h.command_line;
// Don't append if the preceding value is identical or the string empty
let entry_id = if self
.entries
.back()
.map_or(true, |previous| previous != &entry)
&& !entry.is_empty()
&& self.capacity > 0
{
if self.entries.len() == self.capacity {
// History is "full", so we delete the oldest entry first,
// before adding a new one.
self.entries.pop_front();
self.len_on_disk = self.len_on_disk.saturating_sub(1);
}
self.entries.push_back(entry.to_string());
Some(HistoryItemId::new((self.entries.len() - 1) as i64))
} else {
None
};
let entry_id =
if (self.entries.back() != Some(&entry)) && !entry.is_empty() && self.capacity > 0 {
if self.entries.len() == self.capacity {
// History is "full", so we delete the oldest entry first,
// before adding a new one.
self.entries.pop_front();
self.len_on_disk = self.len_on_disk.saturating_sub(1);
}
self.entries.push_back(entry.to_string());
Some(HistoryItemId::new((self.entries.len() - 1) as i64))
} else {
None
};
Ok(FileBackedHistory::construct_entry(entry_id, entry))
}

Expand Down
Loading