gix_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 /// Use [`Options`](crate::store::init::Options) to adjust settings.
36 ///
37 /// Note that if [`precompose_unicode`](crate::store::init::Options::precompose_unicode) is set in the options,
38 /// the `git_dir` is also expected to use precomposed unicode, or else some operations that strip prefixes will fail.
39 pub fn at(
40 git_dir: PathBuf,
41 crate::store::init::Options {
42 write_reflog,
43 object_hash,
44 precompose_unicode,
45 prohibit_windows_device_names,
46 }: crate::store::init::Options,
47 ) -> Self {
48 file::Store {
49 git_dir,
50 packed_buffer_mmap_threshold: packed_refs_mmap_threshold(),
51 common_dir: None,
52 write_reflog,
53 namespace: None,
54 prohibit_windows_device_names,
55 packed: gix_fs::SharedFileSnapshotMut::new().into(),
56 object_hash,
57 precompose_unicode,
58 }
59 }
60
61 /// Like [`at()`][file::Store::at()], but for _linked_ work-trees which use `git_dir` as private ref store and `common_dir` for
62 /// shared references.
63 ///
64 /// Note that if [`precompose_unicode`](crate::store::init::Options::precompose_unicode) is set, the `git_dir` and
65 /// `common_dir` are also expected to use precomposed unicode, or else some operations that strip prefixes will fail.
66 pub fn for_linked_worktree(
67 git_dir: PathBuf,
68 common_dir: PathBuf,
69 crate::store::init::Options {
70 write_reflog,
71 object_hash,
72 precompose_unicode,
73 prohibit_windows_device_names,
74 }: crate::store::init::Options,
75 ) -> Self {
76 file::Store {
77 git_dir,
78 packed_buffer_mmap_threshold: packed_refs_mmap_threshold(),
79 common_dir: Some(common_dir),
80 write_reflog,
81 namespace: None,
82 prohibit_windows_device_names,
83 packed: gix_fs::SharedFileSnapshotMut::new().into(),
84 object_hash,
85 precompose_unicode,
86 }
87 }
88 }
89
90 fn packed_refs_mmap_threshold() -> u64 {
91 if cfg!(windows) {
92 u64::MAX
93 } else {
94 32 * 1024
95 }
96 }
97}