git_ref/store/general/handle/
find.rs

1use std::convert::TryInto;
2
3use crate::{store, PartialNameRef, Reference};
4
5mod error {
6    use std::convert::Infallible;
7
8    /// The error returned by [crate::file::Store::find_loose()].
9    #[derive(Debug, thiserror::Error)]
10    #[allow(missing_docs)]
11    pub enum Error {
12        #[error("An error occurred while finding a reference in the loose file database")]
13        Loose(#[from] crate::file::find::Error),
14        #[error("The ref name or path is not a valid ref name")]
15        RefnameValidation(#[from] crate::name::Error),
16    }
17
18    impl From<Infallible> for Error {
19        fn from(_: Infallible) -> Self {
20            unreachable!("this impl is needed to allow passing a known valid partial path as parameter")
21        }
22    }
23}
24
25pub use error::Error;
26
27use crate::store::handle;
28
29impl store::Handle {
30    /// TODO: actually implement this with handling of the packed buffer.
31    pub fn try_find<'a, Name, E>(&self, partial: Name) -> Result<Option<Reference>, Error>
32    where
33        Name: TryInto<&'a PartialNameRef, Error = E>,
34        Error: From<E>,
35    {
36        let _name = partial.try_into()?;
37        match &self.state {
38            handle::State::Loose { store: _, .. } => {
39                todo!()
40            }
41        }
42    }
43}
44
45mod existing {
46    mod error {
47        use std::path::PathBuf;
48
49        /// The error returned by [file::Store::find_existing()][crate::file::Store::find_existing()].
50        #[derive(Debug, thiserror::Error)]
51        #[allow(missing_docs)]
52        pub enum Error {
53            #[error("An error occurred while finding a reference in the database")]
54            Find(#[from] crate::store::find::Error),
55            #[error("The ref partially named {name:?} could not be found")]
56            NotFound { name: PathBuf },
57        }
58    }
59
60    use std::convert::TryInto;
61
62    pub use error::Error;
63
64    use crate::{store, PartialNameRef, Reference};
65
66    impl store::Handle {
67        /// Similar to [`crate::file::Store::find()`] but a non-existing ref is treated as error.
68        pub fn find<'a, Name, E>(&self, _partial: Name) -> Result<Reference, Error>
69        where
70            Name: TryInto<&'a PartialNameRef, Error = E>,
71            crate::name::Error: From<E>,
72        {
73            todo!()
74            // match self.try_find(partial) {}
75            // match self.find_one_with_verified_input(path.to_partial_path().as_ref(), packed) {
76            //     Ok(Some(r)) => Ok(r),
77            //     Ok(None) => Err(Error::NotFound(path.to_partial_path().into_owned())),
78            //     Err(err) => Err(err.into()),
79            // }
80        }
81    }
82}