History

Remove all public exports of git-hash types in git-object (#63)

Sebastian Thiel committed 5 years ago

Commit accf89d1 parent a3f281660 files · +262 −252Browse files

Showing the changes to git-commitgraph/src (5 of 60 files). Show all

Unified · Split

5 files
  1. git-commitgraph/src/file/access.rs +2 −3
  2. git-commitgraph/src/file/commit.rs +4 −5
  3. git-commitgraph/src/file/verify.rs +15 −10
  4. git-commitgraph/src/graph/init.rs +2 −3
  5. git-commitgraph/src/graph/verify.rs +8 −5
git-commitgraph/src/file/access.rs+2−3
@@ -1,6 +1,5 @@
1use crate::file::{self, commit::Commit, File, COMMIT_DATA_ENTRY_SIZE};1use crate::file::{self, commit::Commit, File, COMMIT_DATA_ENTRY_SIZE};
2use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;2use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
3use git_object::HashKind;
4use std::{3use std::{
5 convert::{TryFrom, TryInto},4 convert::{TryFrom, TryInto},
6 fmt::{Debug, Formatter},5 fmt::{Debug, Formatter},
@@ -28,8 +27,8 @@ impl File { · 21 unmodified lines
28 /// The kind of hash used in this File.27 /// The kind of hash used in this File.
29 ///28 ///
30 /// Note that it is always conforming to the hash used in the owning repository.29 /// Note that it is always conforming to the hash used in the owning repository.
31 pub fn hash_kind(&self) -> HashKind {30 pub fn hash_kind(&self) -> git_hash::Kind {
32 HashKind::Sha131 git_hash::Kind::Sha1
33 }32 }
34 33
35 /// 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.
git-commitgraph/src/file/commit.rs+4−5
@@ -5,7 +5,6 @@ use crate::{ · 4 unmodified lines
5};5};
6use byteorder::{BigEndian, ByteOrder};6use byteorder::{BigEndian, ByteOrder};
7use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;7use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
8use git_object::owned;
9use std::{8use std::{
10 convert::{TryFrom, TryInto},9 convert::{TryFrom, TryInto},
11 fmt::{Debug, Formatter},10 fmt::{Debug, Formatter},
@@ -17,13 +16,13 @@ use std::{ · 5 unmodified lines
17#[allow(missing_docs)]16#[allow(missing_docs)]
18pub enum Error {17pub enum Error {
19 #[error("commit {0}'s extra edges overflows the commit-graph file's extra edges list")]18 #[error("commit {0}'s extra edges overflows the commit-graph file's extra edges list")]
20 ExtraEdgesListOverflow(owned::Id),19 ExtraEdgesListOverflow(git_hash::Id),
21 #[error("commit {0}'s first parent is an extra edge index, which is invalid")]20 #[error("commit {0}'s first parent is an extra edge index, which is invalid")]
22 FirstParentIsExtraEdgeIndex(owned::Id),21 FirstParentIsExtraEdgeIndex(git_hash::Id),
23 #[error("commit {0} has extra edges, but commit-graph file has no extra edges list")]22 #[error("commit {0} has extra edges, but commit-graph file has no extra edges list")]
24 MissingExtraEdgesList(owned::Id),23 MissingExtraEdgesList(git_hash::Id),
25 #[error("commit {0} has a second parent but not a first parent")]24 #[error("commit {0} has a second parent but not a first parent")]
26 SecondParentWithoutFirstParent(owned::Id),25 SecondParentWithoutFirstParent(git_hash::Id),
27}26}
28 27
29// Note that git's commit-graph-format.txt as of v2.28.0 gives an incorrect value 0x0700_0000 for28// Note that git's commit-graph-format.txt as of v2.28.0 gives an incorrect value 0x0700_0000 for
git-commitgraph/src/file/verify.rs+15−10
@@ -5,7 +5,6 @@ use crate::{ · 4 unmodified lines
5};5};
6use bstr::ByteSlice;6use bstr::ByteSlice;
7use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;7use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
8use git_object::owned;
9use std::{8use std::{
10 cmp::{max, min},9 cmp::{max, min},
11 collections::HashMap,10 collections::HashMap,
@@ -20,23 +19,29 @@ pub enum Error<E: std::error::Error + 'static> { · 8 unmodified lines
20 #[error(transparent)]19 #[error(transparent)]
21 Commit(#[from] file::commit::Error),20 Commit(#[from] file::commit::Error),
22 #[error("commit at file position {pos} has invalid ID {id}")]21 #[error("commit at file position {pos} has invalid ID {id}")]
23 CommitId { id: owned::Id, pos: file::Position },22 CommitId { id: git_hash::Id, pos: file::Position },
24 #[error("commit at file position {pos} with ID {id} is out of order relative to its predecessor with ID {predecessor_id}")]23 #[error("commit at file position {pos} with ID {id} is out of order relative to its predecessor with ID {predecessor_id}")]
25 CommitsOutOfOrder {24 CommitsOutOfOrder {
26 id: owned::Id,25 id: git_hash::Id,
27 pos: file::Position,26 pos: file::Position,
28 predecessor_id: owned::Id,27 predecessor_id: git_hash::Id,
29 },28 },
30 #[error("commit-graph filename should be {0}")]29 #[error("commit-graph filename should be {0}")]
31 Filename(String),30 Filename(String),
32 #[error("commit {id} has invalid generation {generation}")]31 #[error("commit {id} has invalid generation {generation}")]
33 Generation { generation: u32, id: owned::Id },32 Generation { generation: u32, id: git_hash::Id },
34 #[error("checksum mismatch: expected {expected}, got {actual}")]33 #[error("checksum mismatch: expected {expected}, got {actual}")]
35 Mismatch { actual: owned::Id, expected: owned::Id },34 Mismatch {
35 actual: git_hash::Id,
36 expected: git_hash::Id,
37 },
36 #[error("{0}")]38 #[error("{0}")]
37 Processor(#[source] E),39 Processor(#[source] E),
38 #[error("commit {id} has invalid root tree ID {root_tree_id}")]40 #[error("commit {id} has invalid root tree ID {root_tree_id}")]
39 RootTreeId { id: owned::Id, root_tree_id: owned::Id },41 RootTreeId {
42 id: git_hash::Id,
43 root_tree_id: git_hash::Id,
44 },
40}45}
41 46
42/// The positive result of [`File::traverse()`] providing some statistical information.47/// The positive result of [`File::traverse()`] providing some statistical information.
@@ -137,7 +142,7 @@ impl File { · 94 unmodified lines
137 /// checksum itself.142 /// checksum itself.
138 ///143 ///
139 /// Return the actual checksum on success or `(actual checksum, expected checksum)` if there is a mismatch.144 /// Return the actual checksum on success or `(actual checksum, expected checksum)` if there is a mismatch.
140 pub fn verify_checksum(&self) -> Result<owned::Id, (owned::Id, owned::Id)> {145 pub fn verify_checksum(&self) -> Result<git_hash::Id, (git_hash::Id, git_hash::Id)> {
141 // Even though we could use git_features::hash::bytes_of_file(…), this would require using our own146 // Even though we could use git_features::hash::bytes_of_file(…), this would require using our own
142 // Error type to support io::Error and Mismatch. As we only gain progress, there probably isn't much value147 // Error type to support io::Error and Mismatch. As we only gain progress, there probably isn't much value
143 // as these files are usually small enough to process them in less than a second, even for the large ones.148 // as these files are usually small enough to process them in less than a second, even for the large ones.
@@ -145,7 +150,7 @@ impl File { · 1 unmodified line
145 let data_len_without_trailer = self.data.len() - SHA1_SIZE;150 let data_len_without_trailer = self.data.len() - SHA1_SIZE;
146 let mut hasher = git_features::hash::Sha1::default();151 let mut hasher = git_features::hash::Sha1::default();
147 hasher.update(&self.data[..data_len_without_trailer]);152 hasher.update(&self.data[..data_len_without_trailer]);
148 let actual = owned::Id::new_sha1(hasher.digest());153 let actual = git_hash::Id::new_sha1(hasher.digest());
149 154
150 let expected = self.checksum();155 let expected = self.checksum();
151 if actual.to_borrowed() == expected {156 if actual.to_borrowed() == expected {
@@ -167,7 +172,7 @@ fn verify_split_chain_filename_hash( · 15 unmodified lines
167 .and_then(|filename| filename.to_str())172 .and_then(|filename| filename.to_str())
168 .and_then(|filename| filename.strip_suffix(".graph"))173 .and_then(|filename| filename.strip_suffix(".graph"))
169 .and_then(|stem| stem.strip_prefix("graph-"))174 .and_then(|stem| stem.strip_prefix("graph-"))
170 .map_or(Ok(()), |hex| match owned::Id::from_40_bytes_in_hex(hex.as_bytes()) {175 .map_or(Ok(()), |hex| match git_hash::Id::from_40_bytes_in_hex(hex.as_bytes()) {
171 Ok(actual) if actual.to_borrowed() == expected => Ok(()),176 Ok(actual) if actual.to_borrowed() == expected => Ok(()),
172 _ => Err(format!("graph-{}.graph", expected.to_sha1_hex().as_bstr())),177 _ => Err(format!("graph-{}.graph", expected.to_sha1_hex().as_bstr())),
173 })178 })
git-commitgraph/src/graph/init.rs+2−3
@@ -2,7 +2,6 @@ use crate::{ · 1 unmodified line
2 file::{self, File},2 file::{self, File},
3 Graph, MAX_COMMITS,3 Graph, MAX_COMMITS,
4};4};
5use git_object::HashKind;
6use std::{5use std::{
7 convert::TryFrom,6 convert::TryFrom,
8 io::{BufRead, BufReader},7 io::{BufRead, BufReader},
@@ -22,9 +21,9 @@ pub enum Error { · 13 unmodified lines
22 #[error("Commit-graph files mismatch: '{}' uses hash {hash1:?}, but '{}' uses hash {hash2:?}", .path1.display(), .path2.display())]21 #[error("Commit-graph files mismatch: '{}' uses hash {hash1:?}, but '{}' uses hash {hash2:?}", .path1.display(), .path2.display())]
23 HashVersionMismatch {22 HashVersionMismatch {
24 path1: PathBuf,23 path1: PathBuf,
25 hash1: HashKind,24 hash1: git_hash::Kind,
26 path2: PathBuf,25 path2: PathBuf,
27 hash2: HashKind,26 hash2: git_hash::Kind,
28 },27 },
29 #[error("Did not find any files that look like commit graphs at '{}'", .0.display())]28 #[error("Did not find any files that look like commit graphs at '{}'", .0.display())]
30 InvalidPath(PathBuf),29 InvalidPath(PathBuf),
git-commitgraph/src/graph/verify.rs+8−5
@@ -3,7 +3,6 @@ use crate::{ · 2 unmodified lines
3 file::{self, commit},3 file::{self, commit},
4 graph, Graph, GENERATION_NUMBER_MAX,4 graph, Graph, GENERATION_NUMBER_MAX,
5};5};
6use git_object::owned;
7use std::{6use std::{
8 cmp::{max, min},7 cmp::{max, min},
9 collections::BTreeMap,8 collections::BTreeMap,
@@ -19,8 +18,8 @@ pub enum Error<E: std::error::Error + 'static> { · 9 unmodified lines
19 BaseGraphCount { actual: u8, expected: u8, path: PathBuf },18 BaseGraphCount { actual: u8, expected: u8, path: PathBuf },
20 #[error("'{}' base graph at index {index} should have ID {expected} but is {actual}", .path.display())]19 #[error("'{}' base graph at index {index} should have ID {expected} but is {actual}", .path.display())]
21 BaseGraphId {20 BaseGraphId {
22 actual: owned::Id,21 actual: git_hash::Id,
23 expected: owned::Id,22 expected: git_hash::Id,
24 index: u8,23 index: u8,
25 path: PathBuf,24 path: PathBuf,
26 },25 },
@@ -36,12 +35,16 @@ pub enum Error<E: std::error::Error + 'static> { · 9 unmodified lines
36 path: PathBuf,35 path: PathBuf,
37 },36 },
38 #[error("Commit {id}'s generation should be {expected} but is {actual}")]37 #[error("Commit {id}'s generation should be {expected} but is {actual}")]
39 Generation { actual: u32, expected: u32, id: owned::Id },38 Generation {
39 actual: u32,
40 expected: u32,
41 id: git_hash::Id,
42 },
40 #[error(43 #[error(
41 "Commit {id} has parent position {parent_pos} that is out of range (should be in range 0-{max_valid_pos})"44 "Commit {id} has parent position {parent_pos} that is out of range (should be in range 0-{max_valid_pos})"
42 )]45 )]
43 ParentOutOfRange {46 ParentOutOfRange {
44 id: owned::Id,47 id: git_hash::Id,
45 max_valid_pos: graph::Position,48 max_valid_pos: graph::Position,
46 parent_pos: graph::Position,49 parent_pos: graph::Position,
47 },50 },