History

[commitgraph] Rename CommitData -> Commit.

Conor Davis committed 6 years ago

Commit d8c20071 parent 7c405ab5 files · +18 −18Browse files

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

Unified · Split

5 files
  1. git-commitgraph/src/graph/access.rs +4 −4
  2. git-commitgraph/src/graph_file/access.rs +4 −4
  3. git-commitgraph/src/graph_file/commit.rs +8 −8
  4. git-commitgraph/src/graph_file/mod.rs +1 −1
  5. git-commitgraph/src/lib.rs +1 −1
git-commitgraph/src/graph/access.rs+4−4
@@ -1,15 +1,15 @@
1use crate::graph::GraphPosition;1use crate::graph::GraphPosition;
2use crate::graph_file::{GraphFile, LexPosition};2use crate::graph_file::{GraphFile, LexPosition};
3use crate::{CommitData, Graph};3use crate::{Commit, Graph};
4use git_object::borrowed;4use git_object::borrowed;
5 5
6impl Graph {6impl 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
git-commitgraph/src/graph_file/access.rs+4−4
@@ -1,5 +1,5 @@
1use crate::graph_file::{GraphFile, LexPosition, COMMIT_DATA_ENTRY_SIZE};1use crate::graph_file::{GraphFile, LexPosition, COMMIT_DATA_ENTRY_SIZE};
2use crate::CommitData;2use crate::Commit;
3use git_object::{borrowed, HashKind, SHA1_SIZE};3use git_object::{borrowed, HashKind, SHA1_SIZE};
4use std::convert::{TryFrom, TryInto};4use std::convert::{TryFrom, TryInto};
5use std::fmt::{Debug, Formatter};5use std::fmt::{Debug, Formatter};
@@ -13,8 +13,8 @@ impl GraphFile { · 7 unmodified lines
13 /// # Panics13 /// # 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
git-commitgraph/src/graph_file/commit.rsrenamed from git-commitgraph/src/graph_file/commit_data.rs+8−8
@@ -39,7 +39,7 @@ quick_error! { · 38 unmodified lines
39const NO_PARENT: u32 = 0x7000_0000;39const NO_PARENT: u32 = 0x7000_0000;
40const EXTENDED_EDGES_MASK: u32 = 0x8000_0000;40const EXTENDED_EDGES_MASK: u32 = 0x8000_0000;
41 41
42pub struct CommitData<'a> {42pub 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
53impl<'a> CommitData<'a> {53impl<'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
105impl<'a> Debug for CommitData<'a> {105impl<'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
120impl<'a> Eq for CommitData<'a> {}120impl<'a> Eq for Commit<'a> {}
121 121
122impl<'a> PartialEq for CommitData<'a> {122impl<'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_pos124 self.file as *const GraphFile == other.file as *const GraphFile && self.lex_pos == other.lex_pos
125 }125 }
126}126}
127 127
128pub struct ParentIterator<'a> {128pub 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
git-commitgraph/src/graph_file/mod.rs+1−1
@@ -4,7 +4,7 @@ use std::ops::Range; · 3 unmodified lines
4use std::path::PathBuf;4use std::path::PathBuf;
5 5
6mod access;6mod access;
7pub mod commit_data;7pub mod commit;
8mod init;8mod init;
9 9
10pub use init::Error;10pub use init::Error;
git-commitgraph/src/lib.rs+1−1
@@ -5,6 +5,6 @@ pub mod graph; · 4 unmodified lines
5pub mod graph_file;5pub mod graph_file;
6 6
7pub use graph::{Graph, GraphPosition};7pub use graph::{Graph, GraphPosition};
8pub use graph_file::commit_data::CommitData;8pub use graph_file::commit::Commit;
9 9
10pub const MAX_COMMITS: u32 = (1 << 30) + (1 << 29) + (1 << 28) - 1;10pub const MAX_COMMITS: u32 = (1 << 30) + (1 << 29) + (1 << 28) - 1;