Skip to content

Commit

Permalink
Fix fetch_latest_commit fetching the earliest commit
Browse files Browse the repository at this point in the history
  • Loading branch information
w4 committed Jan 15, 2024
1 parent 8afe9ca commit 2e0bc34
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/database/schema/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,16 @@ impl CommitTree {
.cf_handle(COMMIT_FAMILY)
.context("missing column family")?;

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")
let mut key = self.prefix.to_vec();
key.extend_from_slice(&self.len()?.to_be_bytes());

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

Yoke::try_attach_to_cart(Box::from(value), |data| bincode::deserialize(data))
.map(Some)
.context("Failed to deserialize commit")
}

pub fn fetch_latest(
Expand Down

0 comments on commit 2e0bc34

Please sign in to comment.