| @@ -1,9 +1,12 @@ |
| 1 | use crate::file::{Commit, File, LexPosition}; | 1 | use crate::{ |
| 2 | use crate::graph::{Graph, GraphPosition}; | 2 | file::{Commit, File, LexPosition}, |
| | 3 | graph::{Graph, Position}, |
| | 4 | }; |
| 3 | use git_object::borrowed; | 5 | use git_object::borrowed; |
| 4 | | 6 | |
| | 7 | /// Access convenience |
| 5 | impl Graph { | 8 | impl Graph { |
| 6 | pub fn commit_at(&self, pos: GraphPosition) -> Commit<'_> { | 9 | pub fn commit_at(&self, pos: Position) -> Commit<'_> { |
| 7 | let r = self.lookup_by_pos(pos); | 10 | let r = self.lookup_by_pos(pos); |
| 8 | r.file.commit_at(r.lex_pos) | 11 | r.file.commit_at(r.lex_pos) |
| 9 | } | 12 | } |
| @@ -13,7 +16,7 @@ impl Graph { · 3 unmodified lines |
| 13 | Some(r.file.commit_at(r.lex_pos)) | 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 | let r = self.lookup_by_pos(pos); | 20 | let r = self.lookup_by_pos(pos); |
| 18 | r.file.id_at(r.lex_pos) | 21 | r.file.id_at(r.lex_pos) |
| 19 | } | 22 | } |
| @@ -28,7 +31,7 @@ impl Graph { · 8 unmodified lines |
| 28 | self.files.iter().flat_map(|file| file.iter_ids()) | 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 | Some(self.lookup_by_id(id)?.graph_pos) | 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 | impl Graph { | 44 | impl Graph { |
| 41 | fn lookup_by_id(&self, id: borrowed::Id<'_>) -> Option<LookupByIdResult<'_>> { | 45 | fn lookup_by_id(&self, id: borrowed::Id<'_>) -> Option<LookupByIdResult<'_>> { |
| 42 | let mut current_file_start = 0; | 46 | let mut current_file_start = 0; |
| 43 | for file in self.files.iter() { | 47 | for file in &self.files { |
| 44 | if let Some(lex_pos) = file.lookup(id) { | 48 | if let Some(lex_pos) = file.lookup(id) { |
| 45 | return Some(LookupByIdResult { | 49 | return Some(LookupByIdResult { |
| 46 | file, | 50 | file, |
| 47 | lex_pos, | 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 | current_file_start += file.num_commits(); | 55 | current_file_start += file.num_commits(); |
| @@ -53,9 +57,9 @@ impl Graph { · 1 unmodified line |
| 53 | None | 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 | let mut remaining = pos.0; | 61 | let mut remaining = pos.0; |
| 58 | for file in self.files.iter() { | 62 | for file in &self.files { |
| 59 | match remaining.checked_sub(file.num_commits()) { | 63 | match remaining.checked_sub(file.num_commits()) { |
| 60 | Some(v) => remaining = v, | 64 | Some(v) => remaining = v, |
| 61 | None => { | 65 | None => { |
| @@ -70,12 +74,14 @@ impl Graph { · 8 unmodified lines |
| 70 | } | 74 | } |
| 71 | } | 75 | } |
| 72 | | 76 | |
| | 77 | #[derive(Clone)] |
| 73 | struct LookupByIdResult<'a> { | 78 | struct LookupByIdResult<'a> { |
| 74 | pub file: &'a File, | 79 | pub file: &'a File, |
| 75 | pub graph_pos: GraphPosition, | 80 | pub graph_pos: Position, |
| 76 | pub lex_pos: LexPosition, | 81 | pub lex_pos: LexPosition, |
| 77 | } | 82 | } |
| 78 | | 83 | |
| | 84 | #[derive(Clone)] |
| 79 | struct LookupByPositionResult<'a> { | 85 | struct LookupByPositionResult<'a> { |
| 80 | pub file: &'a File, | 86 | pub file: &'a File, |
| 81 | pub lex_pos: LexPosition, | 87 | pub lex_pos: LexPosition, |