Showing the changes to git-commitgraph/src (4 of 6 files). Show all
Unified · Split
| @@ -1,7 +1,7 @@ | |||
| 1 | use crate::file::{self, commit::Commit, File, COMMIT_DATA_ENTRY_SIZE}; | 1 | use crate::file::{self, commit::Commit, File, COMMIT_DATA_ENTRY_SIZE}; |
| 2 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; | 2 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; |
| 3 | use std::{ | 3 | use std::{ |
| 4 | convert::{TryFrom, TryInto}, | 4 | convert::TryInto, |
| 5 | fmt::{Debug, Formatter}, | 5 | fmt::{Debug, Formatter}, |
| 6 | path::Path, | 6 | path::Path, |
| 7 | }; | 7 | }; |
| @@ -34,7 +34,7 @@ impl File { · 26 unmodified lines | |||
| 34 | /// Returns 20 bytes sha1 at the given index in our list of (sorted) sha1 hashes. | 34 | /// Returns 20 bytes sha1 at the given index in our list of (sorted) sha1 hashes. |
| 35 | /// The position ranges from 0 to self.num_commits() | 35 | /// The position ranges from 0 to self.num_commits() |
| 36 | // copied from git-odb/src/pack/index/access.rs | 36 | // copied from git-odb/src/pack/index/access.rs |
| 37 | pub fn id_at(&self, pos: file::Position) -> git_hash::borrowed::Id<'_> { | 37 | pub fn id_at(&self, pos: file::Position) -> &git_hash::oid { |
| 38 | assert!( | 38 | assert!( |
| 39 | pos.0 < self.num_commits(), | 39 | pos.0 < self.num_commits(), |
| 40 | "expected lexigraphical position less than {}, got {}", | 40 | "expected lexigraphical position less than {}, got {}", |
| @@ -46,16 +46,16 @@ impl File { · 5 unmodified lines | |||
| 46 | .try_into() | 46 | .try_into() |
| 47 | .expect("an architecture able to hold 32 bits of integer"); | 47 | .expect("an architecture able to hold 32 bits of integer"); |
| 48 | let start = self.oid_lookup_offset + (pos * SHA1_SIZE); | 48 | let start = self.oid_lookup_offset + (pos * SHA1_SIZE); |
| 49 | git_hash::borrowed::Id::try_from(&self.data[start..start + SHA1_SIZE]).expect("20 bytes SHA1 to be alright") | 49 | git_hash::oid::try_from(&self.data[start..start + SHA1_SIZE]).expect("20 bytes SHA1 to be alright") |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | /// Return an iterator over all object hashes stored in the base graph. | 52 | /// Return an iterator over all object hashes stored in the base graph. |
| 53 | pub fn iter_base_graph_ids(&self) -> impl Iterator<Item = git_hash::borrowed::Id<'_>> { | 53 | pub fn iter_base_graph_ids(&self) -> impl Iterator<Item = &git_hash::oid> { |
| 54 | let start = self.base_graphs_list_offset.unwrap_or(0); | 54 | let start = self.base_graphs_list_offset.unwrap_or(0); |
| 55 | let base_graphs_list = &self.data[start..start + (SHA1_SIZE * usize::from(self.base_graph_count))]; | 55 | let base_graphs_list = &self.data[start..start + (SHA1_SIZE * usize::from(self.base_graph_count))]; |
| 56 | base_graphs_list | 56 | base_graphs_list |
| 57 | .chunks(SHA1_SIZE) | 57 | .chunks(SHA1_SIZE) |
| 58 | .map(|bytes| git_hash::borrowed::Id::try_from(bytes).expect("20 bytes SHA1 to be alright")) | 58 | .map(|bytes| git_hash::oid::try_from(bytes).expect("20 bytes SHA1 to be alright")) |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | /// return an iterator over all commits in this file. | 61 | /// return an iterator over all commits in this file. |
| @@ -64,13 +64,13 @@ impl File { · 2 unmodified lines | |||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | /// Return an iterator over all object hashes stored in this file. | 66 | /// Return an iterator over all object hashes stored in this file. |
| 67 | pub fn iter_ids(&self) -> impl Iterator<Item = git_hash::borrowed::Id<'_>> { | 67 | pub fn iter_ids(&self) -> impl Iterator<Item = &git_hash::oid> { |
| 68 | (0..self.num_commits()).map(move |i| self.id_at(file::Position(i))) | 68 | (0..self.num_commits()).map(move |i| self.id_at(file::Position(i))) |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | /// Translate the given object hash to its position within this file, if present. | 71 | /// Translate the given object hash to its position within this file, if present. |
| 72 | // copied from git-odb/src/pack/index/access.rs | 72 | // copied from git-odb/src/pack/index/access.rs |
| 73 | pub fn lookup(&self, id: git_hash::borrowed::Id<'_>) -> Option<file::Position> { | 73 | pub fn lookup(&self, id: &git_hash::oid) -> Option<file::Position> { |
| 74 | let first_byte = usize::from(id.first_byte()); | 74 | let first_byte = usize::from(id.first_byte()); |
| 75 | let mut upper_bound = self.fan[first_byte]; | 75 | let mut upper_bound = self.fan[first_byte]; |
| 76 | let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 }; | 76 | let mut lower_bound = if first_byte != 0 { self.fan[first_byte - 1] } else { 0 }; |
| @@ -6,7 +6,7 @@ use crate::{ · 5 unmodified lines | |||
| 6 | use byteorder::{BigEndian, ByteOrder}; | 6 | use byteorder::{BigEndian, ByteOrder}; |
| 7 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; | 7 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; |
| 8 | use std::{ | 8 | use std::{ |
| 9 | convert::{TryFrom, TryInto}, | 9 | convert::TryInto, |
| 10 | fmt::{Debug, Formatter}, | 10 | fmt::{Debug, Formatter}, |
| 11 | slice::Chunks, | 11 | slice::Chunks, |
| 12 | }; | 12 | }; |
| @@ -39,7 +39,7 @@ pub struct Commit<'a> { · 26 unmodified lines | |||
| 39 | generation: u32, | 39 | generation: u32, |
| 40 | parent1: ParentEdge, | 40 | parent1: ParentEdge, |
| 41 | parent2: ParentEdge, | 41 | parent2: ParentEdge, |
| 42 | root_tree_id: git_hash::borrowed::Id<'a>, | 42 | root_tree_id: &'a git_hash::oid, |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | impl<'a> Commit<'a> { | 45 | impl<'a> Commit<'a> { |
| @@ -48,7 +48,7 @@ impl<'a> Commit<'a> { · 2 unmodified lines | |||
| 48 | Commit { | 48 | Commit { |
| 49 | file, | 49 | file, |
| 50 | pos, | 50 | pos, |
| 51 | root_tree_id: git_hash::borrowed::Id::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"), | 51 | root_tree_id: git_hash::oid::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"), |
| 52 | parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE..SHA1_SIZE + 4])), | 52 | parent1: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE..SHA1_SIZE + 4])), |
| 53 | parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE + 4..SHA1_SIZE + 8])), | 53 | parent2: ParentEdge::from_raw(BigEndian::read_u32(&bytes[SHA1_SIZE + 4..SHA1_SIZE + 8])), |
| 54 | generation: BigEndian::read_u32(&bytes[SHA1_SIZE + 8..SHA1_SIZE + 12]) >> 2, | 54 | generation: BigEndian::read_u32(&bytes[SHA1_SIZE + 8..SHA1_SIZE + 12]) >> 2, |
| @@ -83,7 +83,7 @@ impl<'a> Commit<'a> { · 28 unmodified lines | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | /// Returns the hash of this commit. | 85 | /// Returns the hash of this commit. |
| 86 | pub fn id(&self) -> git_hash::borrowed::Id<'a> { | 86 | pub fn id(&self) -> &'a git_hash::oid { |
| 87 | self.file.id_at(self.pos) | 87 | self.file.id_at(self.pos) |
| 88 | } | 88 | } |
| 89 | 89 | ||
| @@ -98,7 +98,7 @@ impl<'a> Commit<'a> { · 8 unmodified lines | |||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | /// Return the hash of the tree this commit points to. | 100 | /// Return the hash of the tree this commit points to. |
| 101 | pub fn root_tree_id(&self) -> git_hash::borrowed::Id<'a> { | 101 | pub fn root_tree_id(&self) -> &git_hash::oid { |
| 102 | self.root_tree_id | 102 | self.root_tree_id |
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| @@ -8,7 +8,6 @@ use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; · 7 unmodified lines | |||
| 8 | use std::{ | 8 | use std::{ |
| 9 | cmp::{max, min}, | 9 | cmp::{max, min}, |
| 10 | collections::HashMap, | 10 | collections::HashMap, |
| 11 | convert::TryFrom, | ||
| 12 | path::Path, | 11 | path::Path, |
| 13 | }; | 12 | }; |
| 14 | 13 | ||
| @@ -66,9 +65,8 @@ pub struct Outcome { · 51 unmodified lines | |||
| 66 | /// Verification | 65 | /// Verification |
| 67 | impl File { | 66 | impl File { |
| 68 | /// Returns the trailing checksum over the entire content of this file. | 67 | /// Returns the trailing checksum over the entire content of this file. |
| 69 | pub fn checksum(&self) -> git_hash::borrowed::Id<'_> { | 68 | pub fn checksum(&self) -> &git_hash::oid { |
| 70 | git_hash::borrowed::Id::try_from(&self.data[self.data.len() - SHA1_SIZE..]) | 69 | git_hash::oid::try_from(&self.data[self.data.len() - SHA1_SIZE..]).expect("file to be large enough for a hash") |
| 71 | .expect("file to be large enough for a hash") | ||
| 72 | } | 70 | } |
| 73 | 71 | ||
| 74 | /// Traverse all [commits][file::Commit] stored in this file and call `processor(commit) -> Result<(), Error>` on it. | 72 | /// Traverse all [commits][file::Commit] stored in this file and call `processor(commit) -> Result<(), Error>` on it. |
| @@ -83,7 +81,7 @@ impl File { · 8 unmodified lines | |||
| 83 | .map_err(|(actual, expected)| Error::Mismatch { actual, expected })?; | 81 | .map_err(|(actual, expected)| Error::Mismatch { actual, expected })?; |
| 84 | verify_split_chain_filename_hash(&self.path, self.checksum()).map_err(Error::Filename)?; | 82 | verify_split_chain_filename_hash(&self.path, self.checksum()).map_err(Error::Filename)?; |
| 85 | 83 | ||
| 86 | let null_id = git_hash::borrowed::Id::null_sha1(); | 84 | let null_id = git_hash::oid::null_sha1(); |
| 87 | 85 | ||
| 88 | let mut stats = Outcome { | 86 | let mut stats = Outcome { |
| 89 | max_generation: 0, | 87 | max_generation: 0, |
| @@ -94,7 +92,7 @@ impl File { · 4 unmodified lines | |||
| 94 | }; | 92 | }; |
| 95 | 93 | ||
| 96 | // TODO: Verify self.fan values as we go. | 94 | // TODO: Verify self.fan values as we go. |
| 97 | let mut prev_id: git_hash::borrowed::Id<'a> = null_id; | 95 | let mut prev_id: &git_hash::oid = null_id; |
| 98 | for commit in self.iter_commits() { | 96 | for commit in self.iter_commits() { |
| 99 | if commit.id() <= prev_id { | 97 | if commit.id() <= prev_id { |
| 100 | if commit.id() == null_id { | 98 | if commit.id() == null_id { |
| @@ -156,7 +154,7 @@ impl File { · 55 unmodified lines | |||
| 156 | let actual = git_hash::ObjectId::new_sha1(hasher.digest()); | 154 | let actual = git_hash::ObjectId::new_sha1(hasher.digest()); |
| 157 | 155 | ||
| 158 | let expected = self.checksum(); | 156 | let expected = self.checksum(); |
| 159 | if actual.to_borrowed() == expected { | 157 | if actual.as_ref() == expected { |
| 160 | Ok(actual) | 158 | Ok(actual) |
| 161 | } else { | 159 | } else { |
| 162 | Err((actual, expected.into())) | 160 | Err((actual, expected.into())) |
| @@ -166,17 +164,14 @@ impl File { · 3 unmodified lines | |||
| 166 | 164 | ||
| 167 | /// If the given path's filename matches "graph-{hash}.graph", check that `hash` matches the | 165 | /// If the given path's filename matches "graph-{hash}.graph", check that `hash` matches the |
| 168 | /// expected hash. | 166 | /// expected hash. |
| 169 | fn verify_split_chain_filename_hash( | 167 | fn verify_split_chain_filename_hash(path: impl AsRef<Path>, expected: &git_hash::oid) -> Result<(), String> { |
| 170 | path: impl AsRef<Path>, | ||
| 171 | expected: git_hash::borrowed::Id<'_>, | ||
| 172 | ) -> Result<(), String> { | ||
| 173 | let path = path.as_ref(); | 168 | let path = path.as_ref(); |
| 174 | path.file_name() | 169 | path.file_name() |
| 175 | .and_then(|filename| filename.to_str()) | 170 | .and_then(|filename| filename.to_str()) |
| 176 | .and_then(|filename| filename.strip_suffix(".graph")) | 171 | .and_then(|filename| filename.strip_suffix(".graph")) |
| 177 | .and_then(|stem| stem.strip_prefix("graph-")) | 172 | .and_then(|stem| stem.strip_prefix("graph-")) |
| 178 | .map_or(Ok(()), |hex| match git_hash::ObjectId::from_hex(hex.as_bytes()) { | 173 | .map_or(Ok(()), |hex| match git_hash::ObjectId::from_hex(hex.as_bytes()) { |
| 179 | Ok(actual) if actual.to_borrowed() == expected => Ok(()), | 174 | Ok(actual) if actual.as_ref() == expected => Ok(()), |
| 180 | _ => Err(format!("graph-{}.graph", expected.to_sha1_hex().as_bstr())), | 175 | _ => Err(format!("graph-{}.graph", expected.to_sha1_hex().as_bstr())), |
| 181 | }) | 176 | }) |
| 182 | } | 177 | } |
| @@ -15,7 +15,7 @@ impl Graph { · 14 unmodified lines | |||
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | /// Returns the commit matching the given `id`. | 17 | /// Returns the commit matching the given `id`. |
| 18 | pub fn commit_by_id(&self, id: git_hash::borrowed::Id<'_>) -> Option<Commit<'_>> { | 18 | pub fn commit_by_id(&self, id: &git_hash::oid) -> Option<Commit<'_>> { |
| 19 | let r = self.lookup_by_id(id)?; | 19 | let r = self.lookup_by_id(id)?; |
| 20 | Some(r.file.commit_at(r.file_pos)) | 20 | Some(r.file.commit_at(r.file_pos)) |
| 21 | } | 21 | } |
| @@ -24,7 +24,7 @@ impl Graph { · 2 unmodified lines | |||
| 24 | /// | 24 | /// |
| 25 | /// # Panics | 25 | /// # Panics |
| 26 | /// If `pos` is greater or equal to [`num_commits()`][Graph::num_commits()]. | 26 | /// If `pos` is greater or equal to [`num_commits()`][Graph::num_commits()]. |
| 27 | pub fn id_at(&self, pos: graph::Position) -> git_hash::borrowed::Id<'_> { | 27 | pub fn id_at(&self, pos: graph::Position) -> &git_hash::oid { |
| 28 | let r = self.lookup_by_pos(pos); | 28 | let r = self.lookup_by_pos(pos); |
| 29 | r.file.id_at(r.pos) | 29 | r.file.id_at(r.pos) |
| 30 | } | 30 | } |
| @@ -35,12 +35,12 @@ impl Graph { · 4 unmodified lines | |||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /// Iterate over commit IDs in unsorted order. | 37 | /// Iterate over commit IDs in unsorted order. |
| 38 | pub fn iter_ids(&self) -> impl Iterator<Item = git_hash::borrowed::Id<'_>> { | 38 | pub fn iter_ids(&self) -> impl Iterator<Item = &git_hash::oid> { |
| 39 | self.files.iter().flat_map(|file| file.iter_ids()) | 39 | self.files.iter().flat_map(|file| file.iter_ids()) |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | /// Translate the given `id` to its position in the file. | 42 | /// Translate the given `id` to its position in the file. |
| 43 | pub fn lookup(&self, id: git_hash::borrowed::Id<'_>) -> Option<graph::Position> { | 43 | pub fn lookup(&self, id: &git_hash::oid) -> Option<graph::Position> { |
| 44 | Some(self.lookup_by_id(id)?.graph_pos) | 44 | Some(self.lookup_by_id(id)?.graph_pos) |
| 45 | } | 45 | } |
| 46 | 46 | ||
| @@ -52,7 +52,7 @@ impl Graph { · 5 unmodified lines | |||
| 52 | 52 | ||
| 53 | /// Access fundamentals | 53 | /// Access fundamentals |
| 54 | impl Graph { | 54 | impl Graph { |
| 55 | pub(crate) fn lookup_by_id(&self, id: git_hash::borrowed::Id<'_>) -> Option<LookupByIdResult<'_>> { | 55 | pub(crate) fn lookup_by_id(&self, id: &git_hash::oid) -> Option<LookupByIdResult<'_>> { |
| 56 | let mut current_file_start = 0; | 56 | let mut current_file_start = 0; |
| 57 | for file in &self.files { | 57 | for file in &self.files { |
| 58 | if let Some(lex_pos) = file.lookup(id) { | 58 | if let Some(lex_pos) = file.lookup(id) { |