MCPcopy Create free account
hub / github.com/git/git / look_up_object

Method look_up_object

src/loose.rs:410–446  ·  view source on GitHub ↗

Look up `oid` in the map in order to convert it to `algo`. If this object is in the map, return the offset in the table for the main algorithm.

(&self, oid: &ObjectID)

Source from the content-addressed store, hash-verified

408 ///
409 /// If this object is in the map, return the offset in the table for the main algorithm.
410 fn look_up_object(&self, oid: &ObjectID) -> Option<usize> {
411 let oid_algo = HashAlgorithm::from_u32(oid.algo)?;
412 let params = self.obj_formats.get(&oid_algo)?;
413 let short_table =
414 &self.memory[params.data_off..params.data_off + (params.shortened_len * self.nitems)];
415 let index = Self::binary_search_slice(
416 short_table,
417 &oid.as_slice().unwrap()[0..params.shortened_len],
418 )?;
419 match params.mapping_off {
420 Some(from_off) => {
421 // oid is in a compatibility algorithm. Find the mapping index.
422 let mapped = Self::u32_at_offset(self.memory, from_off + index * 4) as usize;
423 if mapped >= self.nitems {
424 return None;
425 }
426 let oid_offset = params.full_off + mapped * oid_algo.raw_len();
427 if self.memory[oid_offset..oid_offset + oid_algo.raw_len()]
428 != *oid.as_slice().unwrap()
429 {
430 return None;
431 }
432 Some(mapped)
433 }
434 None => {
435 // oid is in the main algorithm. Find the object ID in the main map to confirm
436 // it's correct.
437 let oid_offset = params.full_off + index * oid_algo.raw_len();
438 if self.memory[oid_offset..oid_offset + oid_algo.raw_len()]
439 != *oid.as_slice().unwrap()
440 {
441 return None;
442 }
443 Some(index)
444 }
445 }
446 }
447
448 #[allow(dead_code)]
449 fn map_object(&self, oid: &ObjectID, algo: HashAlgorithm) -> Option<MappedObject> {

Callers 2

map_objectMethod · 0.80
map_oidMethod · 0.80

Calls 2

as_sliceMethod · 0.80
raw_lenMethod · 0.80

Tested by

no test coverage detected