git_ref/store/general/
init.rs

1use std::path::PathBuf;
2
3use crate::store::WriteReflog;
4
5mod error {
6    /// The error returned by [crate::Store::at()].
7    #[derive(Debug, thiserror::Error)]
8    #[allow(missing_docs)]
9    pub enum Error {
10        #[error("There was an error accessing the store's directory")]
11        Io(#[from] std::io::Error),
12    }
13}
14
15pub use error::Error;
16
17use crate::file;
18
19#[allow(dead_code)]
20impl crate::Store {
21    /// Create a new store at the given location, typically the `.git/` directory.
22    ///
23    /// `object_hash` defines the kind of hash to assume when dealing with refs.
24    pub fn at(
25        git_dir: impl Into<PathBuf>,
26        reflog_mode: WriteReflog,
27        object_hash: git_hash::Kind,
28    ) -> Result<Self, Error> {
29        // for now, just try to read the directory - later we will do that naturally as we have to figure out if it's a ref-table or not.
30        let git_dir = git_dir.into();
31        std::fs::read_dir(&git_dir)?;
32        Ok(crate::Store {
33            inner: crate::store::State::Loose {
34                store: file::Store::at(git_dir, reflog_mode, object_hash),
35            },
36        })
37    }
38}