git_ref/store/file/loose/
mod.rs

1use crate::{FullName, Kind, Target};
2
3/// A git _ref_ which is stored in a file.
4#[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)]
5pub struct Reference {
6    /// The path to uniquely identify this ref within its store.
7    pub name: FullName,
8    /// The target of the reference, either a symbolic reference by full name or an object by its id.
9    pub target: Target,
10}
11
12impl Reference {
13    /// Return the kind of ref.
14    pub fn kind(&self) -> Kind {
15        self.target.kind()
16    }
17}
18
19///
20pub(crate) mod reflog;
21
22///
23pub(crate) mod iter;
24///
25pub mod reference;
26
27mod init {
28    use std::path::PathBuf;
29
30    use crate::store_impl::file;
31
32    impl file::Store {
33        /// Create a new instance at the given `git_dir`, which commonly is a standard git repository with a
34        /// `refs/` subdirectory.
35        /// The `object_hash` defines which kind of hash we should recognize.
36        pub fn at(git_dir: impl Into<PathBuf>, write_reflog: file::WriteReflog, object_hash: git_hash::Kind) -> Self {
37            file::Store {
38                git_dir: git_dir.into(),
39                common_dir: None,
40                write_reflog,
41                namespace: None,
42                packed: git_features::fs::MutableSnapshot::new().into(),
43                object_hash,
44            }
45        }
46
47        /// Like [`at()`][file::Store::at()], but for _linked_ work-trees which use `git_dir` as private ref store and `common_dir` for
48        /// shared references.
49        pub fn for_linked_worktree(
50            git_dir: impl Into<PathBuf>,
51            common_dir: impl Into<PathBuf>,
52            write_reflog: file::WriteReflog,
53            object_hash: git_hash::Kind,
54        ) -> Self {
55            file::Store {
56                git_dir: git_dir.into(),
57                common_dir: Some(common_dir.into()),
58                write_reflog,
59                namespace: None,
60                packed: git_features::fs::MutableSnapshot::new().into(),
61                object_hash,
62            }
63        }
64    }
65}