-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[repository #164] docs for top-level of easy::reference
- Loading branch information
Showing
5 changed files
with
142 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::{ | ||
cell::{BorrowError, BorrowMutError}, | ||
time::SystemTime, | ||
}; | ||
|
||
use git_ref::file; | ||
|
||
use crate::easy; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
PackedRefsOpen(#[from] git_ref::packed::buffer::open::Error), | ||
#[error("BUG: Part of interior state could not be borrowed.")] | ||
BorrowState(#[from] easy::borrow::state::Error), | ||
} | ||
|
||
impl From<std::cell::BorrowError> for Error { | ||
fn from(err: BorrowError) -> Self { | ||
Error::BorrowState(easy::borrow::state::Error::Borrow(err)) | ||
} | ||
} | ||
|
||
impl From<std::cell::BorrowMutError> for Error { | ||
fn from(err: BorrowMutError) -> Self { | ||
Error::BorrowState(easy::borrow::state::Error::BorrowMut(err)) | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub(crate) struct ModifieablePackedRefsBuffer { | ||
pub(crate) packed_refs: Option<git_ref::packed::Buffer>, | ||
modified: Option<SystemTime>, | ||
} | ||
|
||
impl ModifieablePackedRefsBuffer { | ||
pub fn assure_packed_refs_uptodate( | ||
&mut self, | ||
file: &file::Store, | ||
) -> Result<(), git_ref::packed::buffer::open::Error> { | ||
let packed_refs_modified_time = || file.packed_refs_path().metadata().and_then(|m| m.modified()).ok(); | ||
if self.packed_refs.is_none() { | ||
self.packed_refs = file.packed_buffer()?; | ||
if self.packed_refs.is_some() { | ||
self.modified = packed_refs_modified_time(); | ||
} | ||
} else { | ||
let recent_modification = packed_refs_modified_time(); | ||
match (&self.modified, recent_modification) { | ||
(None, None) => {} | ||
(Some(_), None) => { | ||
self.packed_refs = None; | ||
self.modified = None | ||
} | ||
(Some(cached_time), Some(modified_time)) => { | ||
if *cached_time < modified_time { | ||
self.packed_refs = file.packed_buffer()?; | ||
self.modified = Some(modified_time); | ||
} | ||
} | ||
(None, Some(modified_time)) => { | ||
self.packed_refs = file.packed_buffer()?; | ||
self.modified = Some(modified_time); | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#![allow(missing_docs)] | ||
//! | ||
use std::cell::{Ref, RefMut}; | ||
|
||
use git_ref::file; | ||
|