Skip to content

Commit

Permalink
feat: add file::Store::force_refresh_packed_buffer() to public API (#…
Browse files Browse the repository at this point in the history
…1348)

That way it's possible to explicitly refresh if the caller knows that some other
operation might have invalidated the in-memory cache. The `mtime` based approach
doesn't work reliably on all filesystems due to coarse granularity of time.
  • Loading branch information
Byron committed Apr 22, 2024
1 parent 44a2e00 commit f2d8955
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gix-ref/src/store/file/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ pub(crate) mod modifiable {
pub(crate) type MutableSharedBuffer = OwnShared<gix_fs::SharedFileSnapshotMut<packed::Buffer>>;

impl file::Store {
pub(crate) fn force_refresh_packed_buffer(&self) -> Result<(), packed::buffer::open::Error> {
/// Forcefully reload the packed refs buffer.
///
/// This method should be used if it's clear that the buffer on disk has changed, to
/// make the latest changes visible before other operations are done on this instance.
///
/// As some filesystems don't have nanosecond granularity, changes are likely to be missed
/// if they happen within one second otherwise.
pub fn force_refresh_packed_buffer(&self) -> Result<(), packed::buffer::open::Error> {
self.packed.force_refresh(|| {
let modified = self.packed_refs_path().metadata()?.modified()?;
self.open_packed_buffer().map(|packed| Some(modified).zip(packed))
Expand Down

0 comments on commit f2d8955

Please sign in to comment.