1use crate::{FullName, Kind, Target};
23/// 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.
7pub name: FullName,
8/// The target of the reference, either a symbolic reference by full name or an object by its id.
9pub target: Target,
10}
1112impl Reference {
13/// Return the kind of ref.
14pub fn kind(&self) -> Kind {
15self.target.kind()
16 }
17}
1819///
20pub(crate) mod reflog;
2122///
23pub(crate) mod iter;
24///
25pub mod reference;
2627mod init {
28use std::path::PathBuf;
2930use crate::store_impl::file;
3132impl 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.
36pub 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 }
4647/// 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.
49pub 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}