pub struct Buffer { /* private fields */ }
Expand description
A buffer containing a packed-ref file that is either memory mapped or fully in-memory depending on a cutoff.
The buffer is guaranteed to be sorted as per the packed-ref rules which allows some operations to be more efficient.
Implementations§
source§impl Buffer
impl Buffer
packed-refs specific functionality
sourcepub fn iter(&self) -> Result<Iter<'_>, Error>
pub fn iter(&self) -> Result<Iter<'_>, Error>
Return an iterator of references stored in this packed refs buffer, ordered by reference name.
Note
There is no namespace support in packed iterators. It can be emulated using iter_prefixed(…)
.
sourcepub fn iter_prefixed(&self, prefix: BString) -> Result<Iter<'_>, Error>
pub fn iter_prefixed(&self, prefix: BString) -> Result<Iter<'_>, Error>
Return an iterator yielding only references matching the given prefix, ordered by reference name.
source§impl Buffer
impl Buffer
Initialization
sourcepub fn open(
path: PathBuf,
use_memory_map_if_larger_than_bytes: u64
) -> Result<Self, Error>
pub fn open( path: PathBuf, use_memory_map_if_larger_than_bytes: u64 ) -> Result<Self, Error>
Open the file at path
and map it into memory if the file size is larger than use_memory_map_if_larger_than_bytes
.
In order to allow fast lookups and optimizations, the contents of the packed refs must be sorted. If that’s not the case, they will be sorted on the fly with the data being written into a memory buffer.
sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
Open a buffer from bytes
, which is the content of a typical packed-refs
file.
In order to allow fast lookups and optimizations, the contents of the packed refs must be sorted. If that’s not the case, they will be sorted on the fly.
source§impl Buffer
impl Buffer
packed-refs specific functionality
sourcepub fn try_find<'a, Name, E>(
&self,
name: Name
) -> Result<Option<Reference<'_>>, Error>
pub fn try_find<'a, Name, E>( &self, name: Name ) -> Result<Option<Reference<'_>>, Error>
Find a reference with the given name
and return it.
Note that it will look it up verbatim and does not deal with namespaces or special prefixes like
main-worktree/
or worktrees/<name>/
, as this is left to the caller.