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