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