Showing the changes to git-commitgraph/src (5 of 8 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use crate::file::{File, LexPosition}; |
| 2 | −use crate::graph::GraphPosition; | |
| 2 | +use crate::graph::Position; | |
| 3 | 3 | use byteorder::{BigEndian, ByteOrder}; |
| 4 | 4 | use git_object::{borrowed, owned, SHA1_SIZE}; |
| 5 | 5 | use quick_error::quick_error; |
| @@ -79,7 +79,7 @@ impl<'a> Commit<'a> { · 73 unmodified lines | ||
| 79 | 79 | self.generation |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | − pub fn iter_parents(&'a self) -> impl Iterator<Item = Result<GraphPosition, Error>> + 'a { | |
| 82 | + pub fn iter_parents(&'a self) -> impl Iterator<Item = Result<Position, Error>> + 'a { | |
| 83 | 83 | // I didn't find a combinator approach that a) was as strict as ParentIterator, b) supported |
| 84 | 84 | // fuse-after-first-error behavior, and b) was significantly shorter or more understandable |
| 85 | 85 | // than ParentIterator. So here we are. |
| @@ -93,7 +93,7 @@ impl<'a> Commit<'a> { · 7 unmodified lines | ||
| 93 | 93 | self.file.id_at(self.lex_pos) |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | − pub fn parent1(&self) -> Result<Option<GraphPosition>, Error> { | |
| 96 | + pub fn parent1(&self) -> Result<Option<Position>, Error> { | |
| 97 | 97 | self.iter_parents().next().transpose() |
| 98 | 98 | } |
| 99 | 99 | |
| @@ -131,7 +131,7 @@ pub struct ParentIterator<'a> { · 31 unmodified lines | ||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | impl<'a> Iterator for ParentIterator<'a> { |
| 134 | − type Item = Result<GraphPosition, Error>; | |
| 134 | + type Item = Result<Position, Error>; | |
| 135 | 135 | |
| 136 | 136 | fn next(&mut self) -> Option<Self::Item> { |
| 137 | 137 | let state = std::mem::replace(&mut self.state, ParentIteratorState::Exhausted); |
| @@ -219,7 +219,7 @@ enum ParentIteratorState<'a> { · 81 unmodified lines | ||
| 219 | 219 | #[derive(Clone, Copy, Debug)] |
| 220 | 220 | enum ParentEdge { |
| 221 | 221 | None, |
| 222 | − GraphPosition(GraphPosition), | |
| 222 | + GraphPosition(Position), | |
| 223 | 223 | ExtraEdgeIndex(u32), |
| 224 | 224 | } |
| 225 | 225 | |
| @@ -231,7 +231,7 @@ impl ParentEdge { · 5 unmodified lines | ||
| 231 | 231 | if raw & EXTENDED_EDGES_MASK != 0 { |
| 232 | 232 | ParentEdge::ExtraEdgeIndex(raw & !EXTENDED_EDGES_MASK) |
| 233 | 233 | } else { |
| 234 | − ParentEdge::GraphPosition(GraphPosition(raw)) | |
| 234 | + ParentEdge::GraphPosition(Position(raw)) | |
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | } |
| @@ -239,16 +239,16 @@ impl ParentEdge { · 1 unmodified line | ||
| 239 | 239 | const LAST_EXTENDED_EDGE_MASK: u32 = 0x8000_0000; |
| 240 | 240 | |
| 241 | 241 | enum ExtraEdge { |
| 242 | − Internal(GraphPosition), | |
| 243 | − Last(GraphPosition), | |
| 242 | + Internal(Position), | |
| 243 | + Last(Position), | |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | impl ExtraEdge { |
| 247 | 247 | pub fn from_raw(raw: u32) -> Self { |
| 248 | 248 | if raw & LAST_EXTENDED_EDGE_MASK != 0 { |
| 249 | − Self::Last(GraphPosition(raw & !LAST_EXTENDED_EDGE_MASK)) | |
| 249 | + Self::Last(Position(raw & !LAST_EXTENDED_EDGE_MASK)) | |
| 250 | 250 | } else { |
| 251 | − Self::Internal(GraphPosition(raw)) | |
| 251 | + Self::Internal(Position(raw)) | |
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | } |
| @@ -1,9 +1,12 @@ | ||
| 1 | −use crate::file::{Commit, File, LexPosition}; | |
| 2 | −use crate::graph::{Graph, GraphPosition}; | |
| 1 | +use crate::{ | |
| 2 | + file::{Commit, File, LexPosition}, | |
| 3 | + graph::{Graph, Position}, | |
| 4 | +}; | |
| 3 | 5 | use git_object::borrowed; |
| 4 | 6 | |
| 7 | +/// Access convenience | |
| 5 | 8 | impl Graph { |
| 6 | − pub fn commit_at(&self, pos: GraphPosition) -> Commit<'_> { | |
| 9 | + pub fn commit_at(&self, pos: Position) -> Commit<'_> { | |
| 7 | 10 | let r = self.lookup_by_pos(pos); |
| 8 | 11 | r.file.commit_at(r.lex_pos) |
| 9 | 12 | } |
| @@ -13,7 +16,7 @@ impl Graph { · 3 unmodified lines | ||
| 13 | 16 | Some(r.file.commit_at(r.lex_pos)) |
| 14 | 17 | } |
| 15 | 18 | |
| 16 | − pub fn id_at(&self, pos: GraphPosition) -> borrowed::Id<'_> { | |
| 19 | + pub fn id_at(&self, pos: Position) -> borrowed::Id<'_> { | |
| 17 | 20 | let r = self.lookup_by_pos(pos); |
| 18 | 21 | r.file.id_at(r.lex_pos) |
| 19 | 22 | } |
| @@ -28,7 +31,7 @@ impl Graph { · 8 unmodified lines | ||
| 28 | 31 | self.files.iter().flat_map(|file| file.iter_ids()) |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | − pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<GraphPosition> { | |
| 34 | + pub fn lookup(&self, id: borrowed::Id<'_>) -> Option<Position> { | |
| 32 | 35 | Some(self.lookup_by_id(id)?.graph_pos) |
| 33 | 36 | } |
| 34 | 37 | |
| @@ -37,15 +40,16 @@ impl Graph { · 2 unmodified lines | ||
| 37 | 40 | } |
| 38 | 41 | } |
| 39 | 42 | |
| 43 | +/// Access fundamentals | |
| 40 | 44 | impl Graph { |
| 41 | 45 | fn lookup_by_id(&self, id: borrowed::Id<'_>) -> Option<LookupByIdResult<'_>> { |
| 42 | 46 | let mut current_file_start = 0; |
| 43 | − for file in self.files.iter() { | |
| 47 | + for file in &self.files { | |
| 44 | 48 | if let Some(lex_pos) = file.lookup(id) { |
| 45 | 49 | return Some(LookupByIdResult { |
| 46 | 50 | file, |
| 47 | 51 | lex_pos, |
| 48 | − graph_pos: GraphPosition(current_file_start + lex_pos.0), | |
| 52 | + graph_pos: Position(current_file_start + lex_pos.0), | |
| 49 | 53 | }); |
| 50 | 54 | } |
| 51 | 55 | current_file_start += file.num_commits(); |
| @@ -53,9 +57,9 @@ impl Graph { · 1 unmodified line | ||
| 53 | 57 | None |
| 54 | 58 | } |
| 55 | 59 | |
| 56 | − fn lookup_by_pos(&self, pos: GraphPosition) -> LookupByPositionResult<'_> { | |
| 60 | + fn lookup_by_pos(&self, pos: Position) -> LookupByPositionResult<'_> { | |
| 57 | 61 | let mut remaining = pos.0; |
| 58 | − for file in self.files.iter() { | |
| 62 | + for file in &self.files { | |
| 59 | 63 | match remaining.checked_sub(file.num_commits()) { |
| 60 | 64 | Some(v) => remaining = v, |
| 61 | 65 | None => { |
| @@ -70,12 +74,14 @@ impl Graph { · 8 unmodified lines | ||
| 70 | 74 | } |
| 71 | 75 | } |
| 72 | 76 | |
| 77 | +#[derive(Clone)] | |
| 73 | 78 | struct LookupByIdResult<'a> { |
| 74 | 79 | pub file: &'a File, |
| 75 | − pub graph_pos: GraphPosition, | |
| 80 | + pub graph_pos: Position, | |
| 76 | 81 | pub lex_pos: LexPosition, |
| 77 | 82 | } |
| 78 | 83 | |
| 84 | +#[derive(Clone)] | |
| 79 | 85 | struct LookupByPositionResult<'a> { |
| 80 | 86 | pub file: &'a File, |
| 81 | 87 | pub lex_pos: LexPosition, |
| @@ -1,9 +1,13 @@ | ||
| 1 | −use crate::file::File; | |
| 2 | −use crate::{file, Graph, MAX_COMMITS}; | |
| 1 | +use crate::{ | |
| 2 | + file::{self, File}, | |
| 3 | + Graph, MAX_COMMITS, | |
| 4 | +}; | |
| 3 | 5 | use git_object::HashKind; |
| 4 | 6 | use quick_error::quick_error; |
| 5 | −use std::io::{BufRead, BufReader}; | |
| 6 | −use std::path::{Path, PathBuf}; | |
| 7 | +use std::{ | |
| 8 | + io::{BufRead, BufReader}, | |
| 9 | + path::{Path, PathBuf}, | |
| 10 | +}; | |
| 7 | 11 | |
| 8 | 12 | quick_error! { |
| 9 | 13 | #[derive(Debug)] |
| @@ -3,7 +3,7 @@ mod access; · 2 unmodified lines | ||
| 3 | 3 | mod init; |
| 4 | 4 | |
| 5 | 5 | use crate::file::File; |
| 6 | −use std::fmt::{Display, Formatter}; | |
| 6 | +use std::fmt; | |
| 7 | 7 | |
| 8 | 8 | /// A complete commit graph. |
| 9 | 9 | /// |
| @@ -14,11 +14,11 @@ pub struct Graph { · 4 unmodified lines | ||
| 14 | 14 | files: Vec<File>, |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | −#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] | |
| 18 | −pub struct GraphPosition(pub u32); | |
| 17 | +#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] | |
| 18 | +pub struct Position(pub u32); | |
| 19 | 19 | |
| 20 | −impl Display for GraphPosition { | |
| 21 | − fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | |
| 20 | +impl fmt::Display for Position { | |
| 21 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 22 | 22 | self.0.fmt(f) |
| 23 | 23 | } |
| 24 | 24 | } |
| @@ -4,7 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | pub mod file; |
| 5 | 5 | pub mod graph; |
| 6 | 6 | |
| 7 | −pub use graph::{Graph, GraphPosition}; | |
| 7 | +pub use graph::Graph; | |
| 8 | 8 | |
| 9 | 9 | /// The maximum number of commits that can be stored in a commit graph. |
| 10 | 10 | pub const MAX_COMMITS: u32 = (1 << 30) + (1 << 29) + (1 << 28) - 1; |