1 use crate::store_impl
::{
3 file
::{log, loose, loose::Reference}
,
6 pub(crate) fn must_be_io_err(err
: loose
::reflog
::Error
) -> std
::io
::Error
{
8 loose
::reflog
::Error
::Io(err
) => err
,
9 loose
::reflog
::Error
::RefnameValidation(_
) => unreachable
!("we are called from a valid ref"),
14 /// Returns true if a reflog exists in the given `store`.
16 /// Please note that this method shouldn't be used to check if a log exists before trying to read it, but instead
17 /// is meant to be the fastest possible way to determine if a log exists or not.
18 /// If the caller needs to know if it's readable, try to read the log instead with a reverse or forward iterator.
19 pub fn log_exists(&self, store
: &file
::Store
) -> bool
{
21 .reflog_exists(self.name
.as_ref())
22 .expect("name conversion infallible")
24 /// Return a reflog reverse iterator for this ref, reading chunks from the back into the fixed buffer `buf`, in the given `store`.
26 /// The iterator will traverse log entries from most recent to oldest, reading the underlying file in chunks from the back.
27 /// Return `Ok(None)` if no reflog exists.
28 pub fn log_iter_rev
<'b
>(
32 ) -> std
::io
::Result
<Option
<log
::iter
::Reverse
<'b
, std
::fs
::File
>>> {
33 store
.reflog_iter_rev(self.name
.as_ref(), buf
).map_err(must_be_io_err
)
36 /// Return a reflog forward iterator for this ref and write its file contents into `buf`, in the given `store`.
38 /// The iterator will traverse log entries from oldest to newest.
39 /// Return `Ok(None)` if no reflog exists.
40 pub fn log_iter
<'a
, 'b
: 'a
>(
44 ) -> std
::io
::Result
<Option
<impl Iterator
<Item
= Result
<log
::LineRef
<'b
>, log
::iter
::decode
::Error
>> + 'a
>> {
45 store
.reflog_iter(self.name
.as_ref(), buf
).map_err(must_be_io_err
)