aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/atuin_client
diff options
context:
space:
mode:
Diffstat (limited to 'crates/turtle/src/atuin_client')
-rw-r--r--crates/turtle/src/atuin_client/database.rs37
-rw-r--r--crates/turtle/src/atuin_client/encryption.rs6
-rw-r--r--crates/turtle/src/atuin_client/ordering.rs15
-rw-r--r--crates/turtle/src/atuin_client/record/sqlite_store.rs4
-rw-r--r--crates/turtle/src/atuin_client/settings.rs5
5 files changed, 35 insertions, 32 deletions
diff --git a/crates/turtle/src/atuin_client/database.rs b/crates/turtle/src/atuin_client/database.rs
index 24f017be..c730b1d4 100644
--- a/crates/turtle/src/atuin_client/database.rs
+++ b/crates/turtle/src/atuin_client/database.rs
@@ -178,6 +178,7 @@ impl ClientSqlite {
Ok(())
}
+ #[expect(clippy::needless_pass_by_value)]
fn query_history_inner(row: SqliteRow) -> History {
let deleted_at: Option<i64> = row.get("deleted_at");
let hostname: String = row.get("hostname");
@@ -205,7 +206,8 @@ impl ClientSqlite {
.author(author)
.intent(intent)
.deleted_at(
- deleted_at.and_then(|t| OffsetDateTime::from_unix_timestamp_nanos(i128::from(t)).ok()),
+ deleted_at
+ .and_then(|t| OffsetDateTime::from_unix_timestamp_nanos(i128::from(t)).ok()),
)
.build()
.into()
@@ -265,11 +267,10 @@ impl ClientSqlite {
query.and_where_is_null("deleted_at");
}
- let git_root = if let Some(git_root) = context.git_root.clone() {
- git_root.to_str().unwrap_or("/").to_string()
- } else {
- context.cwd.clone()
- };
+ let git_root = context.git_root.clone().map_or_else(
+ || context.cwd.clone(),
+ |git_root| git_root.to_str().unwrap_or("/").to_string(),
+ );
let session_start = get_session_start_time(&context.session);
@@ -352,6 +353,7 @@ impl ClientSqlite {
// Yes I know, it's a lot.
// Could maybe break it down to a searchparams struct or smth but that feels a little... pointless.
// Been debating maybe a DSL for search? eg "before:time limit:1 the query"
+ #[expect(clippy::too_many_lines)]
pub(crate) async fn search(
&self,
search_mode: SearchMode,
@@ -380,11 +382,10 @@ impl ClientSqlite {
sql.order_desc("timestamp");
}
- let git_root = if let Some(git_root) = context.git_root.clone() {
- git_root.to_str().unwrap_or("/").to_string()
- } else {
- context.cwd.clone()
- };
+ let git_root = context.git_root.clone().map_or_else(
+ || context.cwd.clone(),
+ |git_root| git_root.to_str().unwrap_or("/").to_string(),
+ );
let session_start = get_session_start_time(&context.session);
@@ -1120,6 +1121,7 @@ mod test {
}
#[tokio::test(flavor = "multi_thread")]
+ #[expect(clippy::similar_names)]
async fn test_paged_basic() {
let mut db = ClientSqlite::new("sqlite::memory:", test_local_timeout())
.await
@@ -1188,8 +1190,8 @@ mod test {
// With unique flag - should get 3 (duplicates collapsed)
let mut paged_unique = db.all_paged(10, false, true);
- let page_unique = paged_unique.next().await.unwrap().unwrap();
- assert_eq!(page_unique.len(), 3);
+ let paged_unique = paged_unique.next().await.unwrap().unwrap();
+ assert_eq!(paged_unique.len(), 3);
}
#[tokio::test(flavor = "multi_thread")]
@@ -1301,11 +1303,12 @@ impl<'a> Iterator for QueryTokenizer<'a> {
return Some(QueryToken::Or);
}
- let mut is_inverse = false;
- if let Some(s) = part.strip_prefix('!') {
+ let is_inverse = part.strip_prefix('!').is_some_and(|s| {
part = s;
- is_inverse = true;
- }
+ true
+ });
+
+ #[expect(clippy::option_if_let_else, reason = "It's too ugly")]
let token = if let Some(s) = part.strip_prefix('^') {
QueryToken::MatchStart(s, is_inverse)
} else if let Some(s) = part.strip_suffix('$') {
diff --git a/crates/turtle/src/atuin_client/encryption.rs b/crates/turtle/src/atuin_client/encryption.rs
index 661a6669..f1c921cb 100644
--- a/crates/turtle/src/atuin_client/encryption.rs
+++ b/crates/turtle/src/atuin_client/encryption.rs
@@ -63,7 +63,7 @@ pub(crate) fn encode_key(key: &Key) -> Result<String> {
Ok(buf)
}
-pub(crate) fn decode_key(key: String) -> Result<Key> {
+pub(crate) fn decode_key(key: &str) -> Result<Key> {
use rmp::decode;
let buf = BASE64_STANDARD
@@ -102,8 +102,6 @@ pub(crate) fn decode_key(key: String) -> Result<Key> {
#[cfg(test)]
mod test {
- use pretty_assertions::assert_eq;
-
#[test]
fn key_encodings() {
use super::{Key, decode_key, encode_key};
@@ -138,7 +136,7 @@ mod test {
];
for k in valid_encodings {
- assert_eq!(decode_key(k.to_owned()).expect(k), key);
+ assert_eq!(decode_key(k).expect(k), key);
}
}
}
diff --git a/crates/turtle/src/atuin_client/ordering.rs b/crates/turtle/src/atuin_client/ordering.rs
index 446a5dac..84001f52 100644
--- a/crates/turtle/src/atuin_client/ordering.rs
+++ b/crates/turtle/src/atuin_client/ordering.rs
@@ -9,6 +9,7 @@ pub(crate) fn reorder_fuzzy(mode: SearchMode, query: &str, res: Vec<History>) ->
}
}
+#[expect(clippy::needless_pass_by_value, reason = "makes things easier")]
fn reorder<F, A>(query: &str, f: F, res: Vec<A>) -> Vec<A>
where
F: Fn(&A) -> &String,
@@ -18,14 +19,12 @@ where
let qvec = &query.chars().collect();
r.sort_by_cached_key(|h| {
// TODO for fzf search we should sum up scores for each matched term
- let (from, to) = match minspan::span(qvec, &(f(h).chars().collect())) {
- Some(x) => x,
- // this is a little unfortunate: when we are asked to match a query that is found nowhere,
- // we don't want to return a None, as the comparison behaviour would put the worst matches
- // at the front. therefore, we'll return a set of indices that are one larger than the longest
- // possible legitimate match. This is meaningless except as a comparison.
- None => (0, res.len()),
- };
+ //
+ // The fallback is a little unfortunate: when we are asked to match a query that is found nowhere,
+ // we don't want to return a None, as the comparison behaviour would put the worst matches
+ // at the front. Therefore, we'll return a set of indices that are one larger than the longest
+ // possible legitimate match. This is meaningless except as a comparison.
+ let (from, to) = minspan::span(qvec, &(f(h).chars().collect())).unwrap_or((0, res.len()));
1 + to - from
});
r
diff --git a/crates/turtle/src/atuin_client/record/sqlite_store.rs b/crates/turtle/src/atuin_client/record/sqlite_store.rs
index 12f9fc4e..8a9afe45 100644
--- a/crates/turtle/src/atuin_client/record/sqlite_store.rs
+++ b/crates/turtle/src/atuin_client/record/sqlite_store.rs
@@ -95,6 +95,10 @@ impl SqliteStore {
Ok(())
}
+ #[expect(
+ clippy::needless_pass_by_value,
+ reason = "this is used in a place with fixed function signature"
+ )]
fn query_row(row: SqliteRow) -> Record<EncryptedData> {
let idx: i64 = row.get("idx");
let timestamp: i64 = row.get("timestamp");
diff --git a/crates/turtle/src/atuin_client/settings.rs b/crates/turtle/src/atuin_client/settings.rs
index bfb8d001..c02221eb 100644
--- a/crates/turtle/src/atuin_client/settings.rs
+++ b/crates/turtle/src/atuin_client/settings.rs
@@ -62,9 +62,7 @@ impl SearchMode {
// if the user is using skim, we go to skim
Self::FullText if settings.search_mode == Self::Skim => Self::Skim,
// if the user is using daemon-fuzzy, we go to daemon-fuzzy
- Self::FullText if settings.search_mode == Self::DaemonFuzzy => {
- Self::DaemonFuzzy
- }
+ Self::FullText if settings.search_mode == Self::DaemonFuzzy => Self::DaemonFuzzy,
// otherwise fuzzy.
Self::FullText => Self::Fuzzy,
Self::Fuzzy | Self::Skim | Self::DaemonFuzzy => Self::Prefix,
@@ -845,6 +843,7 @@ impl Sync {
}
pub(crate) fn encryption_key(&self) -> Result<Option<Key>> {
Self::try_read_file(self.encryption_key_path.as_ref())?
+ .as_deref()
.map(decode_key)
.transpose()
}