Showing the changes to git-commitgraph (7 of 60 files). Show all
Unified · Split
| @@ -13,11 +13,10 @@ include = ["src/**/*"] · 12 unmodified lines | |||
| 13 | doctest = false | 13 | doctest = false |
| 14 | 14 | ||
| 15 | [features] | 15 | [features] |
| 16 | serde1 = ["serde", "git-object/serde1"] | 16 | serde1 = ["serde", "git-hash/serde1"] |
| 17 | 17 | ||
| 18 | [dependencies] | 18 | [dependencies] |
| 19 | git-features = { version = "^0.11.0", path = "../git-features" } | 19 | git-features = { version = "^0.11.0", path = "../git-features" } |
| 20 | git-object = { version = "^0.6.0", path = "../git-object" } | ||
| 21 | git-hash = { version = "^0.1.0", path = "../git-hash" } | 20 | git-hash = { version = "^0.1.0", path = "../git-hash" } |
| 22 | 21 | ||
| 23 | bstr = { version = "0.2.13", default-features = false, features = ["std"] } | 22 | bstr = { version = "0.2.13", default-features = false, features = ["std"] } |
| @@ -1,6 +1,5 @@ | |||
| 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 git_object::HashKind; | ||
| 4 | use std::{ | 3 | use 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::Sha1 | 31 | 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. |
| @@ -5,7 +5,6 @@ use crate::{ · 4 unmodified lines | |||
| 5 | }; | 5 | }; |
| 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 git_object::owned; | ||
| 9 | use std::{ | 8 | use 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)] |
| 18 | pub enum Error { | 17 | pub 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 for | 28 | // Note that git's commit-graph-format.txt as of v2.28.0 gives an incorrect value 0x0700_0000 for |
| @@ -5,7 +5,6 @@ use crate::{ · 4 unmodified lines | |||
| 5 | }; | 5 | }; |
| 6 | use bstr::ByteSlice; | 6 | use bstr::ByteSlice; |
| 7 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; | 7 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; |
| 8 | use git_object::owned; | ||
| 9 | use std::{ | 8 | use 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 own | 146 | // 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 value | 147 | // 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 | }) |
| @@ -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 | }; |
| 5 | use git_object::HashKind; | ||
| 6 | use std::{ | 5 | use 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), |
| @@ -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 | }; |
| 6 | use git_object::owned; | ||
| 7 | use std::{ | 6 | use 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 | }, |
| @@ -1,5 +1,4 @@ | |||
| 1 | use git_commitgraph::{graph::Position as GraphPosition, Graph}; | 1 | use git_commitgraph::{graph::Position as GraphPosition, Graph}; |
| 2 | use git_object::{borrowed, owned}; | ||
| 3 | use std::{ | 2 | use std::{ |
| 4 | collections::{HashMap, HashSet}, | 3 | collections::{HashMap, HashSet}, |
| 5 | convert::{TryFrom, TryInto}, | 4 | convert::{TryFrom, TryInto}, |
| @@ -76,15 +75,15 @@ pub fn fixture_path(path: &str) -> PathBuf { · 70 unmodified lines | |||
| 76 | PathBuf::from("tests").join("fixtures").join(path) | 75 | PathBuf::from("tests").join("fixtures").join(path) |
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | pub fn hex_to_id(hex: &[u8]) -> owned::Id { | 78 | pub fn hex_to_id(hex: &[u8]) -> git_hash::Id { |
| 80 | owned::Id::from_40_bytes_in_hex(hex).expect("40 bytes hex") | 79 | git_hash::Id::from_40_bytes_in_hex(hex).expect("40 bytes hex") |
| 81 | } | 80 | } |
| 82 | 81 | ||
| 83 | pub struct RefInfo { | 82 | pub struct RefInfo { |
| 84 | id: owned::Id, | 83 | id: git_hash::Id, |
| 85 | parent_ids: Vec<owned::Id>, | 84 | parent_ids: Vec<git_hash::Id>, |
| 86 | pos: GraphPosition, | 85 | pos: GraphPosition, |
| 87 | root_tree_id: owned::Id, | 86 | root_tree_id: git_hash::Id, |
| 88 | } | 87 | } |
| 89 | 88 | ||
| 90 | impl RefInfo { | 89 | impl RefInfo { |
| @@ -125,11 +124,11 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 34 unmodified lines | |||
| 125 | let parts = x.trim_end().split(' ').collect::<Vec<_>>(); | 124 | let parts = x.trim_end().split(' ').collect::<Vec<_>>(); |
| 126 | ( | 125 | ( |
| 127 | parts[0].to_string(), | 126 | parts[0].to_string(), |
| 128 | owned::Id::from_40_bytes_in_hex(parts[1].as_bytes()).expect("40 bytes hex"), | 127 | git_hash::Id::from_40_bytes_in_hex(parts[1].as_bytes()).expect("40 bytes hex"), |
| 129 | owned::Id::from_40_bytes_in_hex(parts[2].as_bytes()).expect("40 bytes hex"), | 128 | git_hash::Id::from_40_bytes_in_hex(parts[2].as_bytes()).expect("40 bytes hex"), |
| 130 | parts[3..] | 129 | parts[3..] |
| 131 | .iter() | 130 | .iter() |
| 132 | .map(|x| owned::Id::from_40_bytes_in_hex(x.as_bytes()).expect("40 bytes hex")) | 131 | .map(|x| git_hash::Id::from_40_bytes_in_hex(x.as_bytes()).expect("40 bytes hex")) |
| 133 | .collect(), | 132 | .collect(), |
| 134 | ) | 133 | ) |
| 135 | }) | 134 | }) |