History

Add all types the handle would have to store (#266)

Sebastian Thiel committed 4 years ago

Commit e2f0cb01 parent 580e96c2 files · +87 −4Browse files

Unified · Split

2 files
  1. git-odb/src/lib.rs +2 −3
  2. git-odb/src/store/general/mod.rs +85 −1
git-odb/src/lib.rs+2−3
@@ -29,9 +29,8 @@ pub type Handle = Cache<general::Handle<OwnShared<general::Store>>>; · 28 unmodified lines
29 29
30/// Create a new cached odb handle.30/// Create a new cached odb handle.
31pub fn at(objects_dir: impl Into<PathBuf>) -> std::io::Result<Handle> {31pub fn at(objects_dir: impl Into<PathBuf>) -> std::io::Result<Handle> {
32 Ok(Cache::from(32 let handle = OwnShared::new(general::Store::at(objects_dir)?).to_handle();
33 OwnShared::new(general::Store::at(objects_dir)?).to_handle(),33 Ok(Cache::from(handle))
34 ))
35}34}
36 35
37///36///
git-odb/src/store/general/mod.rs+85−1
@@ -65,7 +65,7 @@ mod find { · 64 unmodified lines
65 }65 }
66}66}
67 67
68mod store {68mod init {
69 use git_features::threading::OwnShared;69 use git_features::threading::OwnShared;
70 use std::path::PathBuf;70 use std::path::PathBuf;
71 use std::sync::atomic::AtomicUsize;71 use std::sync::atomic::AtomicUsize;
@@ -92,3 +92,87 @@ mod store { · 20 unmodified lines
92 }92 }
93 }93 }
94}94}
95
96mod store {
97 /// An id to refer to an index file or a multipack index file
98 pub type IndexId = usize;
99
100 /// A way to load and refer to a pack uniquely, namespaced by their indexing mechanism, aka multi-pack or not.
101 pub struct PackId {
102 /// Note that if `multipack_index = None`, this index is corresponding to the index id.
103 /// So a pack is always identified by its corresponding index.
104 /// If it is a multipack index, this is the id / offset of the pack in the `multipack_index`.
105 pub(crate) index: IndexId,
106 pub(crate) multipack_index: Option<IndexId>,
107 }
108}
109
110mod handle {
111 use crate::general::store;
112 use std::sync::Arc;
113
114 mod multi_index {
115 // TODO: replace this one with an actual implementation of a multi-pack index.
116 pub type File = ();
117 }
118
119 pub enum SingleOrMultiIndex {
120 Single {
121 index: Arc<git_pack::index::File>,
122 data: Option<Arc<git_pack::data::File>>,
123 },
124 Multi {
125 index: Arc<multi_index::File>,
126 data: Vec<Option<Arc<git_pack::data::File>>>,
127 },
128 }
129
130 pub struct IndexLookup {
131 file: SingleOrMultiIndex,
132 id: store::IndexId,
133 }
134
135 pub struct IndexForObjectInPack {
136 /// The internal identifier of the pack itself, which either is referred to by an index or a multi-pack index.
137 pack_id: store::PackId,
138 /// The index of the object within the pack
139 object_index_in_pack: u32,
140 }
141
142 mod index_lookup {
143 use crate::general::{handle, store};
144 use git_hash::oid;
145 use std::sync::Arc;
146
147 impl handle::IndexLookup {
148 /// See if the oid is contained in this index, and return its full id for lookup possibly alongside its data file if already
149 /// loaded.
150 /// If it is not loaded, ask it to be loaded and put it into the returned mutable option for safe-keeping.
151 fn lookup(
152 &mut self,
153 object_id: &oid,
154 ) -> Option<(handle::IndexForObjectInPack, &mut Option<Arc<git_pack::data::File>>)> {
155 let id = self.id;
156 match &mut self.file {
157 handle::SingleOrMultiIndex::Single { index, data } => {
158 index.lookup(object_id).map(|object_index_in_pack| {
159 (
160 handle::IndexForObjectInPack {
161 pack_id: store::PackId {
162 index: id,
163 multipack_index: None,
164 },
165 object_index_in_pack,
166 },
167 data,
168 )
169 })
170 }
171 handle::SingleOrMultiIndex::Multi { index, data } => {
172 todo!("find respective pack and return it as &mut Option<>")
173 }
174 }
175 }
176 }
177 }
178}