| @@ -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, |