History

Make ObjectId/oid happen! (#63)

Sebastian Thiel committed 5 years ago

Commit ca78d151 parent b3fc36551 files · +216 −209Browse files

Showing the changes to git-commitgraph/src/file (2 of 51 files). Show all

Unified · Split

2 files
  1. git-commitgraph/src/file/commit.rs +4 −4
  2. git-commitgraph/src/file/verify.rs +18 −13
git-commitgraph/src/file/commit.rs+4−4
@@ -16,13 +16,13 @@ use std::{ · 15 unmodified lines
1616 #[allow(missing_docs)]
1717 pub enum Error {
1818 #[error("commit {0}'s extra edges overflows the commit-graph file's extra edges list")]
19− ExtraEdgesListOverflow(git_hash::Id),
19+ ExtraEdgesListOverflow(git_hash::ObjectId),
2020 #[error("commit {0}'s first parent is an extra edge index, which is invalid")]
21− FirstParentIsExtraEdgeIndex(git_hash::Id),
21+ FirstParentIsExtraEdgeIndex(git_hash::ObjectId),
2222 #[error("commit {0} has extra edges, but commit-graph file has no extra edges list")]
23− MissingExtraEdgesList(git_hash::Id),
23+ MissingExtraEdgesList(git_hash::ObjectId),
2424 #[error("commit {0} has a second parent but not a first parent")]
25− SecondParentWithoutFirstParent(git_hash::Id),
25+ SecondParentWithoutFirstParent(git_hash::ObjectId),
2626 }
2727
2828 // 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+18−13
@@ -19,28 +19,31 @@ pub enum Error<E: std::error::Error + 'static> { · 18 unmodified lines
1919 #[error(transparent)]
2020 Commit(#[from] file::commit::Error),
2121 #[error("commit at file position {pos} has invalid ID {id}")]
22− CommitId { id: git_hash::Id, pos: file::Position },
22+ CommitId {
23+ id: git_hash::ObjectId,
24+ pos: file::Position,
25+ },
2326 #[error("commit at file position {pos} with ID {id} is out of order relative to its predecessor with ID {predecessor_id}")]
2427 CommitsOutOfOrder {
25− id: git_hash::Id,
28+ id: git_hash::ObjectId,
2629 pos: file::Position,
27− predecessor_id: git_hash::Id,
30+ predecessor_id: git_hash::ObjectId,
2831 },
2932 #[error("commit-graph filename should be {0}")]
3033 Filename(String),
3134 #[error("commit {id} has invalid generation {generation}")]
32− Generation { generation: u32, id: git_hash::Id },
35+ Generation { generation: u32, id: git_hash::ObjectId },
3336 #[error("checksum mismatch: expected {expected}, got {actual}")]
3437 Mismatch {
35− actual: git_hash::Id,
36− expected: git_hash::Id,
38+ actual: git_hash::ObjectId,
39+ expected: git_hash::ObjectId,
3740 },
3841 #[error("{0}")]
3942 Processor(#[source] E),
4043 #[error("commit {id} has invalid root tree ID {root_tree_id}")]
4144 RootTreeId {
42− id: git_hash::Id,
43− root_tree_id: git_hash::Id,
45+ id: git_hash::ObjectId,
46+ root_tree_id: git_hash::ObjectId,
4447 },
4548 }
4649
@@ -142,7 +145,7 @@ impl File { · 95 unmodified lines
142145 /// checksum itself.
143146 ///
144147 /// Return the actual checksum on success or `(actual checksum, expected checksum)` if there is a mismatch.
145− pub fn verify_checksum(&self) -> Result<git_hash::Id, (git_hash::Id, git_hash::Id)> {
148+ pub fn verify_checksum(&self) -> Result<git_hash::ObjectId, (git_hash::ObjectId, git_hash::ObjectId)> {
146149 // Even though we could use git_features::hash::bytes_of_file(…), this would require using our own
147150 // Error type to support io::Error and Mismatch. As we only gain progress, there probably isn't much value
148151 // as these files are usually small enough to process them in less than a second, even for the large ones.
@@ -150,7 +153,7 @@ impl File { · 1 unmodified line
150153 let data_len_without_trailer = self.data.len() - SHA1_SIZE;
151154 let mut hasher = git_features::hash::Sha1::default();
152155 hasher.update(&self.data[..data_len_without_trailer]);
153− let actual = git_hash::Id::new_sha1(hasher.digest());
156+ let actual = git_hash::ObjectId::new_sha1(hasher.digest());
154157
155158 let expected = self.checksum();
156159 if actual.to_borrowed() == expected {
@@ -172,8 +175,10 @@ fn verify_split_chain_filename_hash( · 15 unmodified lines
172175 .and_then(|filename| filename.to_str())
173176 .and_then(|filename| filename.strip_suffix(".graph"))
174177 .and_then(|stem| stem.strip_prefix("graph-"))
175− .map_or(Ok(()), |hex| match git_hash::Id::from_40_bytes_in_hex(hex.as_bytes()) {
176− Ok(actual) if actual.to_borrowed() == expected => Ok(()),
177− _ => Err(format!("graph-{}.graph", expected.to_sha1_hex().as_bstr())),
178+ .map_or(Ok(()), |hex| {
179+ match git_hash::ObjectId::from_40_bytes_in_hex(hex.as_bytes()) {
180+ Ok(actual) if actual.to_borrowed() == expected => Ok(()),
181+ _ => Err(format!("graph-{}.graph", expected.to_sha1_hex().as_bstr())),
182+ }
178183 })
179184 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t