🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2024-01-15 2:05:53.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2024-01-15 2:14:10.0 +00:00:00
commit
584eadfa6b9f96b23745a45fed48421c1694a267 [patch]
tree
b04f4c253e0621369b32733c45abab0976ae9e61
parent
8afe9caffdf5b28416e487461c7a178d3d3687e6
download
584eadfa6b9f96b23745a45fed48421c1694a267.tar.gz

Fix fetch_latest_commit fetching the earliest commit



Diff

 src/database/schema/commit.rs | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/database/schema/commit.rs b/src/database/schema/commit.rs
index 5d9587d..7454113 100644
--- a/src/database/schema/commit.rs
+++ a/src/database/schema/commit.rs
@@ -188,19 +188,21 @@
    }

    pub fn fetch_latest_one(&self) -> Result<Option<YokedCommit>, anyhow::Error> {
        let mut key = self.prefix.to_vec();
        key.extend_from_slice(&(self.len()? - 1).to_be_bytes());

        let cf = self
            .db
            .cf_handle(COMMIT_FAMILY)
            .context("missing column family")?;

        let Some(value) = self.db.get_cf(cf, key)? else {
            return Ok(None);
        };

        self.db
            .prefix_iterator_cf(cf, &self.prefix)
            .next()
            .transpose()
            .context("Failed to instantiate iterator")?
            .map(|(_, value)| Yoke::try_attach_to_cart(value, |data| bincode::deserialize(data)))
            .transpose()
            .context("Failed to decode commit")
        Yoke::try_attach_to_cart(Box::from(value), |data| bincode::deserialize(data))
            .map(Some)
            .context("Failed to deserialize commit")
    }

    pub fn fetch_latest(