| @@ -15,6 +15,8 @@ mod error { · 14 unmodified lines |
| 15 | pub enum Error { | 15 | pub enum Error { |
| 16 | #[error("An error occurred while obtaining an object from the loose object store")] | 16 | #[error("An error occurred while obtaining an object from the loose object store")] |
| 17 | Loose(#[from] loose::find::Error), | 17 | Loose(#[from] loose::find::Error), |
| | 18 | #[error("An error occurred looking up a prefix which requires iteration")] |
| | 19 | LooseWalkDir(#[from] loose::iter::Error), |
| 18 | #[error("An error occurred while obtaining an object from the packed object store")] | 20 | #[error("An error occurred while obtaining an object from the packed object store")] |
| 19 | Pack(#[from] pack::data::decode_entry::Error), | 21 | Pack(#[from] pack::data::decode_entry::Error), |
| 20 | #[error(transparent)] | 22 | #[error(transparent)] |
| @@ -32,8 +34,44 @@ where · 11 unmodified lines |
| 32 | S: Deref<Target = super::Store> + Clone, | 34 | S: Deref<Target = super::Store> + Clone, |
| 33 | { | 35 | { |
| 34 | #[allow(missing_docs)] // TODO: docs | 36 | #[allow(missing_docs)] // TODO: docs |
| 35 | pub fn lookup_prefix(&self, _prefix: git_hash::Prefix) -> Result<Option<crate::find::PrefixLookupResult>, Error> { | 37 | pub fn lookup_prefix(&self, prefix: git_hash::Prefix) -> Result<Option<crate::find::PrefixLookupResult>, Error> { |
| 36 | todo!() | 38 | let mut candidate: Option<git_hash::ObjectId> = None; |
| | 39 | loop { |
| | 40 | let snapshot = self.snapshot.borrow(); |
| | 41 | { |
| | 42 | for index in snapshot.indices.iter() { |
| | 43 | match (index.lookup_prefix(prefix), candidate) { |
| | 44 | (Some(Ok(oid)), Some(candidate)) if candidate != oid => return Ok(Some(Err(()))), |
| | 45 | (Some(Ok(_)), Some(_)) | (None, None) | (None, Some(_)) => continue, |
| | 46 | (Some(Err(())), _) => return Ok(Some(Err(()))), |
| | 47 | (Some(Ok(oid)), None) => { |
| | 48 | candidate = Some(oid); |
| | 49 | continue; |
| | 50 | } |
| | 51 | } |
| | 52 | } |
| | 53 | } |
| | 54 | |
| | 55 | for lodb in snapshot.loose_dbs.iter() { |
| | 56 | match (lodb.lookup_prefix(prefix)?, candidate) { |
| | 57 | (Some(Ok(oid)), Some(candidate)) if candidate != oid => return Ok(Some(Err(()))), |
| | 58 | (Some(Ok(_)), Some(_)) | (None, None) | (None, Some(_)) => continue, |
| | 59 | (Some(Err(())), _) => return Ok(Some(Err(()))), |
| | 60 | (Some(Ok(oid)), None) => { |
| | 61 | candidate = Some(oid); |
| | 62 | continue; |
| | 63 | } |
| | 64 | } |
| | 65 | } |
| | 66 | |
| | 67 | match self.store.load_one_index(self.refresh_mode, snapshot.marker)? { |
| | 68 | Some(new_snapshot) => { |
| | 69 | drop(snapshot); |
| | 70 | *self.snapshot.borrow_mut() = new_snapshot; |
| | 71 | } |
| | 72 | None => return Ok(candidate.map(Ok)), |
| | 73 | } |
| | 74 | } |
| 37 | } | 75 | } |
| 38 | } | 76 | } |
| 39 | | 77 | |
| @@ -46,8 +84,8 @@ where · 6 unmodified lines |
| 46 | // TODO: probably make this method fallible, but that would mean its own error type. | 84 | // TODO: probably make this method fallible, but that would mean its own error type. |
| 47 | fn contains(&self, id: impl AsRef<oid>) -> bool { | 85 | fn contains(&self, id: impl AsRef<oid>) -> bool { |
| 48 | let id = id.as_ref(); | 86 | let id = id.as_ref(); |
| | 87 | let mut snapshot = self.snapshot.borrow_mut(); |
| 49 | loop { | 88 | loop { |
| 50 | let mut snapshot = self.snapshot.borrow_mut(); | | |
| 51 | { | 89 | { |
| 52 | for (idx, index) in snapshot.indices.iter().enumerate() { | 90 | for (idx, index) in snapshot.indices.iter().enumerate() { |
| 53 | if index.contains(id) { | 91 | if index.contains(id) { |
| @@ -67,8 +105,7 @@ where · 13 unmodified lines |
| 67 | | 105 | |
| 68 | match self.store.load_one_index(self.refresh_mode, snapshot.marker) { | 106 | match self.store.load_one_index(self.refresh_mode, snapshot.marker) { |
| 69 | Ok(Some(new_snapshot)) => { | 107 | Ok(Some(new_snapshot)) => { |
| 70 | drop(snapshot); | 108 | *snapshot = new_snapshot; |
| 71 | *self.snapshot.borrow_mut() = new_snapshot; | | |
| 72 | } | 109 | } |
| 73 | Ok(None) => return false, // nothing more to load, or our refresh mode doesn't allow disk refreshes | 110 | Ok(None) => return false, // nothing more to load, or our refresh mode doesn't allow disk refreshes |
| 74 | Err(_) => return false, // something went wrong, nothing we can communicate here with this trait. TODO: Maybe that should change? | 111 | Err(_) => return false, // something went wrong, nothing we can communicate here with this trait. TODO: Maybe that should change? |
| @@ -83,8 +120,8 @@ where · 8 unmodified lines |
| 83 | pack_cache: &mut impl DecodeEntry, | 120 | pack_cache: &mut impl DecodeEntry, |
| 84 | ) -> Result<Option<(Data<'a>, Option<Location>)>, Self::Error> { | 121 | ) -> Result<Option<(Data<'a>, Option<Location>)>, Self::Error> { |
| 85 | let id = id.as_ref(); | 122 | let id = id.as_ref(); |
| | 123 | let mut snapshot = self.snapshot.borrow_mut(); |
| 86 | 'outer: loop { | 124 | 'outer: loop { |
| 87 | let mut snapshot = self.snapshot.borrow_mut(); | | |
| 88 | { | 125 | { |
| 89 | let marker = snapshot.marker; | 126 | let marker = snapshot.marker; |
| 90 | for (idx, index) in snapshot.indices.iter_mut().enumerate() { | 127 | for (idx, index) in snapshot.indices.iter_mut().enumerate() { |
| @@ -105,8 +142,7 @@ where · 14 unmodified lines |
| 105 | // The pack wasn't available anymore so we are supposed to try another round with a fresh index | 142 | // The pack wasn't available anymore so we are supposed to try another round with a fresh index |
| 106 | match self.store.load_one_index(self.refresh_mode, snapshot.marker)? { | 143 | match self.store.load_one_index(self.refresh_mode, snapshot.marker)? { |
| 107 | Some(new_snapshot) => { | 144 | Some(new_snapshot) => { |
| 108 | drop(snapshot); | 145 | *snapshot = new_snapshot; |
| 109 | *self.snapshot.borrow_mut() = new_snapshot; | | |
| 110 | continue 'outer; | 146 | continue 'outer; |
| 111 | } | 147 | } |
| 112 | None => { | 148 | None => { |
| @@ -166,8 +202,7 @@ where · 53 unmodified lines |
| 166 | | 202 | |
| 167 | match self.store.load_one_index(self.refresh_mode, snapshot.marker)? { | 203 | match self.store.load_one_index(self.refresh_mode, snapshot.marker)? { |
| 168 | Some(new_snapshot) => { | 204 | Some(new_snapshot) => { |
| 169 | drop(snapshot); | 205 | *snapshot = new_snapshot; |
| 170 | *self.snapshot.borrow_mut() = new_snapshot; | | |
| 171 | } | 206 | } |
| 172 | None => return Ok(None), | 207 | None => return Ok(None), |
| 173 | } | 208 | } |
| @@ -180,8 +215,8 @@ where · 6 unmodified lines |
| 180 | "BUG: handle must be configured to `prevent_pack_unload()` before using this method" | 215 | "BUG: handle must be configured to `prevent_pack_unload()` before using this method" |
| 181 | ); | 216 | ); |
| 182 | let id = id.as_ref(); | 217 | let id = id.as_ref(); |
| | 218 | let mut snapshot = self.snapshot.borrow_mut(); |
| 183 | 'outer: loop { | 219 | 'outer: loop { |
| 184 | let mut snapshot = self.snapshot.borrow_mut(); | | |
| 185 | { | 220 | { |
| 186 | let marker = snapshot.marker; | 221 | let marker = snapshot.marker; |
| 187 | for (idx, index) in snapshot.indices.iter_mut().enumerate() { | 222 | for (idx, index) in snapshot.indices.iter_mut().enumerate() { |
| @@ -202,8 +237,7 @@ where · 14 unmodified lines |
| 202 | // The pack wasn't available anymore so we are supposed to try another round with a fresh index | 237 | // The pack wasn't available anymore so we are supposed to try another round with a fresh index |
| 203 | match self.store.load_one_index(self.refresh_mode, snapshot.marker).ok()? { | 238 | match self.store.load_one_index(self.refresh_mode, snapshot.marker).ok()? { |
| 204 | Some(new_snapshot) => { | 239 | Some(new_snapshot) => { |
| 205 | drop(snapshot); | 240 | *snapshot = new_snapshot; |
| 206 | *self.snapshot.borrow_mut() = new_snapshot; | | |
| 207 | continue 'outer; | 241 | continue 'outer; |
| 208 | } | 242 | } |
| 209 | None => { | 243 | None => { |
| @@ -239,8 +273,7 @@ where · 29 unmodified lines |
| 239 | | 273 | |
| 240 | match self.store.load_one_index(self.refresh_mode, snapshot.marker).ok()? { | 274 | match self.store.load_one_index(self.refresh_mode, snapshot.marker).ok()? { |
| 241 | Some(new_snapshot) => { | 275 | Some(new_snapshot) => { |
| 242 | drop(snapshot); | 276 | *snapshot = new_snapshot; |
| 243 | *self.snapshot.borrow_mut() = new_snapshot; | | |
| 244 | } | 277 | } |
| 245 | None => return None, | 278 | None => return None, |
| 246 | } | 279 | } |
| @@ -279,9 +312,9 @@ where · 32 unmodified lines |
| 279 | "BUG: handle must be configured to `prevent_pack_unload()` before using this method" | 312 | "BUG: handle must be configured to `prevent_pack_unload()` before using this method" |
| 280 | ); | 313 | ); |
| 281 | let pack_id = PackId::from_intrinsic_pack_id(location.pack_id); | 314 | let pack_id = PackId::from_intrinsic_pack_id(location.pack_id); |
| | 315 | let mut snapshot = self.snapshot.borrow_mut(); |
| | 316 | let marker = snapshot.marker; |
| 282 | loop { | 317 | loop { |
| 283 | let mut snapshot = self.snapshot.borrow_mut(); | | |
| 284 | let marker = snapshot.marker; | | |
| 285 | { | 318 | { |
| 286 | for index in snapshot.indices.iter_mut() { | 319 | for index in snapshot.indices.iter_mut() { |
| 287 | if let Some(possibly_pack) = index.pack(pack_id) { | 320 | if let Some(possibly_pack) = index.pack(pack_id) { |
| @@ -289,7 +322,7 @@ where · 1 unmodified line |
| 289 | Some(pack) => pack, | 322 | Some(pack) => pack, |
| 290 | None => { | 323 | None => { |
| 291 | let pack = self.store.load_pack(pack_id, marker).ok()?.expect( | 324 | let pack = self.store.load_pack(pack_id, marker).ok()?.expect( |
| 292 | "BUG: pack must exist from previous call to locaion_by_oid() and must not be unloaded", | 325 | "BUG: pack must exist from previous call to location_by_oid() and must not be unloaded", |
| 293 | ); | 326 | ); |
| 294 | *possibly_pack = Some(pack); | 327 | *possibly_pack = Some(pack); |
| 295 | possibly_pack.as_deref().expect("just put it in") | 328 | possibly_pack.as_deref().expect("just put it in") |