Showing the changes to git-commitgraph/src (5 of 5 files). Show all
Unified · Split
| @@ -1,15 +1,15 @@ | |||
| 1 | use crate::graph::GraphPosition; | 1 | use crate::graph::GraphPosition; |
| 2 | use crate::graph_file::{GraphFile, LexPosition}; | 2 | use crate::graph_file::{GraphFile, LexPosition}; |
| 3 | use crate::{CommitData, Graph}; | 3 | use crate::{Commit, Graph}; |
| 4 | use git_object::borrowed; | 4 | use git_object::borrowed; |
| 5 | 5 | ||
| 6 | impl Graph { | 6 | impl Graph { |
| 7 | pub fn commit_at(&self, pos: GraphPosition) -> CommitData<'_> { | 7 | pub fn commit_at(&self, pos: GraphPosition) -> Commit<'_> { |
| 8 | let r = self.lookup_by_pos(pos); | 8 | let r = self.lookup_by_pos(pos); |
| 9 | r.file.commit_at(r.lex_pos) | 9 | r.file.commit_at(r.lex_pos) |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | pub fn commit_by_id(&self, id: borrowed::Id<'_>) -> Option<CommitData<'_>> { | 12 | pub fn commit_by_id(&self, id: borrowed::Id<'_>) -> Option<Commit<'_>> { |
| 13 | let r = self.lookup_by_id(id)?; | 13 | let r = self.lookup_by_id(id)?; |
| 14 | Some(r.file.commit_at(r.lex_pos)) | 14 | Some(r.file.commit_at(r.lex_pos)) |
| 15 | } | 15 | } |
| @@ -20,7 +20,7 @@ impl Graph { · 4 unmodified lines | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | /// Iterate over commits in unsorted order. | 22 | /// Iterate over commits in unsorted order. |
| 23 | pub fn iter_commits(&self) -> impl Iterator<Item = CommitData<'_>> { | 23 | pub fn iter_commits(&self) -> impl Iterator<Item = Commit<'_>> { |
| 24 | self.files.iter().flat_map(|file| file.iter_commits()) | 24 | self.files.iter().flat_map(|file| file.iter_commits()) |
| 25 | } | 25 | } |
| 26 | 26 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::graph_file::{GraphFile, LexPosition, COMMIT_DATA_ENTRY_SIZE}; | 1 | use crate::graph_file::{GraphFile, LexPosition, COMMIT_DATA_ENTRY_SIZE}; |
| 2 | use crate::CommitData; | 2 | use crate::Commit; |
| 3 | use git_object::{borrowed, HashKind, SHA1_SIZE}; | 3 | use git_object::{borrowed, HashKind, SHA1_SIZE}; |
| 4 | use std::convert::{TryFrom, TryInto}; | 4 | use std::convert::{TryFrom, TryInto}; |
| 5 | use std::fmt::{Debug, Formatter}; | 5 | use std::fmt::{Debug, Formatter}; |
| @@ -13,8 +13,8 @@ impl GraphFile { · 7 unmodified lines | |||
| 13 | /// # Panics | 13 | /// # Panics |
| 14 | /// | 14 | /// |
| 15 | /// Panics if `pos` is out of bounds. | 15 | /// Panics if `pos` is out of bounds. |
| 16 | pub fn commit_at(&self, pos: LexPosition) -> CommitData<'_> { | 16 | pub fn commit_at(&self, pos: LexPosition) -> Commit<'_> { |
| 17 | CommitData::new(self, pos) | 17 | Commit::new(self, pos) |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | pub fn hash_kind(&self) -> HashKind { | 20 | pub fn hash_kind(&self) -> HashKind { |
| @@ -49,7 +49,7 @@ impl GraphFile { · 28 unmodified lines | |||
| 49 | .map(|bytes| borrowed::Id::try_from(bytes).expect("20 bytes SHA1 to be alright")) | 49 | .map(|bytes| borrowed::Id::try_from(bytes).expect("20 bytes SHA1 to be alright")) |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | pub fn iter_commits(&self) -> impl Iterator<Item = CommitData<'_>> { | 52 | pub fn iter_commits(&self) -> impl Iterator<Item = Commit<'_>> { |
| 53 | (0..self.num_commits()).map(move |i| self.commit_at(LexPosition(i))) | 53 | (0..self.num_commits()).map(move |i| self.commit_at(LexPosition(i))) |
| 54 | } | 54 | } |
| 55 | 55 | ||
| @@ -39,7 +39,7 @@ quick_error! { · 38 unmodified lines | |||
| 39 | const NO_PARENT: u32 = 0x7000_0000; | 39 | const NO_PARENT: u32 = 0x7000_0000; |
| 40 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; | 40 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; |
| 41 | 41 | ||
| 42 | pub struct CommitData<'a> { | 42 | pub struct Commit<'a> { |
| 43 | file: &'a GraphFile, | 43 | file: &'a GraphFile, |
| 44 | lex_pos: LexPosition, | 44 | lex_pos: LexPosition, |
| 45 | // We can parse the below fields lazily if needed. | 45 | // We can parse the below fields lazily if needed. |
| @@ -50,10 +50,10 @@ pub struct CommitData<'a> { · 4 unmodified lines | |||
| 50 | root_tree_id: borrowed::Id<'a>, | 50 | root_tree_id: borrowed::Id<'a>, |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | impl<'a> CommitData<'a> { | 53 | impl<'a> Commit<'a> { |
| 54 | pub(crate) fn new(file: &'a GraphFile, pos: LexPosition) -> Self { | 54 | pub(crate) fn new(file: &'a GraphFile, pos: LexPosition) -> Self { |
| 55 | let bytes = file.commit_data_bytes(pos); | 55 | let bytes = file.commit_data_bytes(pos); |
| 56 | CommitData { | 56 | Commit { |
| 57 | file, | 57 | file, |
| 58 | lex_pos: pos, | 58 | lex_pos: pos, |
| 59 | root_tree_id: borrowed::Id::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"), | 59 | root_tree_id: borrowed::Id::try_from(&bytes[..SHA1_SIZE]).expect("20 bytes SHA1 to be alright"), |
| @@ -102,11 +102,11 @@ impl<'a> CommitData<'a> { · 42 unmodified lines | |||
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | impl<'a> Debug for CommitData<'a> { | 105 | impl<'a> Debug for Commit<'a> { |
| 106 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | 106 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 107 | write!( | 107 | write!( |
| 108 | f, | 108 | f, |
| 109 | "CommitData {{ id: {}, lex_pos: {}, generation: {}, root_tree_oid: {}, parent1: {:?}, parent2: {:?} }}", | 109 | "Commit {{ id: {}, lex_pos: {}, generation: {}, root_tree_id: {}, parent1: {:?}, parent2: {:?} }}", |
| 110 | self.id(), | 110 | self.id(), |
| 111 | self.lex_pos, | 111 | self.lex_pos, |
| 112 | self.generation(), | 112 | self.generation(), |
| @@ -117,16 +117,16 @@ impl<'a> Debug for CommitData<'a> { · 4 unmodified lines | |||
| 117 | } | 117 | } |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | impl<'a> Eq for CommitData<'a> {} | 120 | impl<'a> Eq for Commit<'a> {} |
| 121 | 121 | ||
| 122 | impl<'a> PartialEq for CommitData<'a> { | 122 | impl<'a> PartialEq for Commit<'a> { |
| 123 | fn eq(&self, other: &Self) -> bool { | 123 | fn eq(&self, other: &Self) -> bool { |
| 124 | self.file as *const GraphFile == other.file as *const GraphFile && self.lex_pos == other.lex_pos | 124 | self.file as *const GraphFile == other.file as *const GraphFile && self.lex_pos == other.lex_pos |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | pub struct ParentIterator<'a> { | 128 | pub struct ParentIterator<'a> { |
| 129 | commit_data: &'a CommitData<'a>, | 129 | commit_data: &'a Commit<'a>, |
| 130 | state: ParentIteratorState<'a>, | 130 | state: ParentIteratorState<'a>, |
| 131 | } | 131 | } |
| 132 | 132 | ||
| @@ -4,7 +4,7 @@ use std::ops::Range; · 3 unmodified lines | |||
| 4 | use std::path::PathBuf; | 4 | use std::path::PathBuf; |
| 5 | 5 | ||
| 6 | mod access; | 6 | mod access; |
| 7 | pub mod commit_data; | 7 | pub mod commit; |
| 8 | mod init; | 8 | mod init; |
| 9 | 9 | ||
| 10 | pub use init::Error; | 10 | pub use init::Error; |
| @@ -5,6 +5,6 @@ pub mod graph; · 4 unmodified lines | |||
| 5 | pub mod graph_file; | 5 | pub mod graph_file; |
| 6 | 6 | ||
| 7 | pub use graph::{Graph, GraphPosition}; | 7 | pub use graph::{Graph, GraphPosition}; |
| 8 | pub use graph_file::commit_data::CommitData; | 8 | pub use graph_file::commit::Commit; |
| 9 | 9 | ||
| 10 | pub const MAX_COMMITS: u32 = (1 << 30) + (1 << 29) + (1 << 28) - 1; | 10 | pub const MAX_COMMITS: u32 = (1 << 30) + (1 << 29) + (1 << 28) - 1; |