1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#![allow(missing_docs)]
use std::cell::{Ref, RefMut};

use git_ref::file;

use crate::{
    easy,
    easy::{borrow, PackCache},
};

impl Clone for easy::State {
    fn clone(&self) -> Self {
        easy::State { ..Default::default() }
    }
}

impl easy::State {
    pub(crate) fn assure_packed_refs_uptodate(
        &self,
        file: &file::Store,
    ) -> Result<Ref<'_, easy::reference::packed::ModifieablePackedRefsBuffer>, easy::reference::packed::Error> {
        let mut packed_refs = self.packed_refs.try_borrow_mut()?;
        packed_refs.assure_packed_refs_uptodate(file)?;
        drop(packed_refs);
        Ok(self.packed_refs.try_borrow()?)
    }

    #[inline]
    pub(crate) fn try_borrow_mut_pack_cache(&self) -> Result<RefMut<'_, PackCache>, borrow::state::Error> {
        self.pack_cache.try_borrow_mut().map_err(Into::into)
    }

    #[inline]
    pub(crate) fn try_borrow_mut_buf(&self) -> Result<RefMut<'_, Vec<u8>>, borrow::state::Error> {
        self.buf.try_borrow_mut().map_err(Into::into)
    }

    #[inline]
    pub(crate) fn try_borrow_buf(&self) -> Result<Ref<'_, Vec<u8>>, borrow::state::Error> {
        self.buf.try_borrow().map_err(Into::into)
    }
}