From 2ca7dd57b12861e8c9bbc9238cda612e0ff22ff3 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 12 Jun 2026 17:16:19 +0200 Subject: chore(treewide): Cleanup themes --- crates/turtle/src/atuin_common/record.rs | 114 +++---------------------------- 1 file changed, 10 insertions(+), 104 deletions(-) (limited to 'crates/turtle/src/atuin_common') diff --git a/crates/turtle/src/atuin_common/record.rs b/crates/turtle/src/atuin_common/record.rs index 9db9cf98..8a10804c 100644 --- a/crates/turtle/src/atuin_common/record.rs +++ b/crates/turtle/src/atuin_common/record.rs @@ -83,18 +83,6 @@ pub(crate) struct AdditionalData<'a> { pub(crate) host: &'a HostId, } -impl Record { - pub(crate) fn append(&self, data: Vec) -> Record { - Record::builder() - .host(self.host.clone()) - .version(self.version.clone()) - .idx(self.idx + 1) - .tag(self.tag.clone()) - .data(DecryptedData(data)) - .build() - } -} - /// An index representing the current state of the record stores /// This can be both remote, or local, and compared in either direction #[derive(Debug, Serialize, Deserialize)] @@ -125,16 +113,12 @@ impl RecordStatus { } /// Insert a new tail record into the store - pub(crate) fn set(&mut self, tail: Record) { - self.set_raw(tail.host.id, tail.tag, tail.idx) - } - pub(crate) fn set_raw(&mut self, host: HostId, tag: String, tail_id: RecordIdx) { self.hosts.entry(host).or_default().insert(tag, tail_id); } pub(crate) fn get(&self, host: HostId, tag: String) -> Option { - self.hosts.get(&host).and_then(|v| v.get(&tag)).cloned() + self.hosts.get(&host).and_then(|v| v.get(&tag)).copied() } /// Diff this index with another, likely remote index. @@ -148,11 +132,11 @@ impl RecordStatus { let mut ret = Vec::new(); // First, we check if other has everything that self has - for (host, tag_map) in self.hosts.iter() { - for (tag, idx) in tag_map.iter() { + for (host, tag_map) in &self.hosts { + for (tag, idx) in tag_map { match other.get(*host, tag.clone()) { // The other store is all up to date! No diff. - Some(t) if t.eq(idx) => continue, + Some(t) if t.eq(idx) => (), // The other store does exist, and it is either ahead or behind us. A diff regardless Some(t) => ret.push(Diff { @@ -169,7 +153,7 @@ impl RecordStatus { local: Some(*idx), remote: None, }), - }; + } } } @@ -177,11 +161,11 @@ impl RecordStatus { // If the other store knows of a tag that we are not yet aware of, then the diff will be missed // account for that! - for (host, tag_map) in other.hosts.iter() { - for (tag, idx) in tag_map.iter() { + for (host, tag_map) in &other.hosts { + for (tag, idx) in tag_map { match self.get(*host, tag.clone()) { // If we have this host/tag combo, the comparison and diff will have already happened above - Some(_) => continue, + Some(_) => (), None => ret.push(Diff { host: *host, @@ -189,7 +173,7 @@ impl RecordStatus { remote: Some(*idx), local: None, }), - }; + } } } @@ -282,7 +266,7 @@ impl Record { mod tests { use crate::atuin_common::record::{Host, HostId}; - use super::{DecryptedData, Diff, Record, RecordStatus}; + use super::{DecryptedData, Record, RecordStatus}; use pretty_assertions::assert_eq; fn test_record() -> Record { @@ -295,84 +279,6 @@ mod tests { .build() } - #[test] - fn record_index() { - let mut index = RecordStatus::new(); - let record = test_record(); - - index.set(record.clone()); - - let tail = index.get(record.host.id, record.tag); - - assert_eq!( - record.idx, - tail.expect("tail not in store"), - "tail in store did not match" - ); - } - - #[test] - fn record_index_overwrite() { - let mut index = RecordStatus::new(); - let record = test_record(); - let child = record.append(vec![1, 2, 3]); - - index.set(record.clone()); - index.set(child.clone()); - - let tail = index.get(record.host.id, record.tag); - - assert_eq!( - child.idx, - tail.expect("tail not in store"), - "tail in store did not match" - ); - } - - #[test] - fn record_index_no_diff() { - // Here, they both have the same version and should have no diff - - let mut index1 = RecordStatus::new(); - let mut index2 = RecordStatus::new(); - - let record1 = test_record(); - - index1.set(record1.clone()); - index2.set(record1); - - let diff = index1.diff(&index2); - - assert_eq!(0, diff.len(), "expected empty diff"); - } - - #[test] - fn record_index_single_diff() { - // Here, they both have the same stores, but one is ahead by a single record - - let mut index1 = RecordStatus::new(); - let mut index2 = RecordStatus::new(); - - let record1 = test_record(); - let record2 = record1.append(vec![1, 2, 3]); - - index1.set(record1); - index2.set(record2.clone()); - - let diff = index1.diff(&index2); - - assert_eq!(1, diff.len(), "expected single diff"); - assert_eq!( - diff[0], - Diff { - host: record2.host.id, - tag: record2.tag, - remote: Some(1), - local: Some(0) - } - ); - } - #[test] fn record_index_multi_diff() { // A much more complex case, with a bunch more checks -- cgit v1.3.1