History

[commitgraph] Rename LexPosition to 'file::Position'

That way it's in line with 'graph::Position'

Sebastian Thiel committed 6 years ago

Commit 6f90bee1 parent d2eec1d6 files · +72 −55Browse files

Showing the changes to git-commitgraph/src/file/commit.rs (1 of 6 files). Show all

Unified · Split

git-commitgraph/src/file/commit.rs+20−16
@@ -1,11 +1,15 @@
1use crate::file::{File, LexPosition};1use crate::{
2use crate::graph::Position;2 file::{self, File},
3 graph,
4};
3use byteorder::{BigEndian, ByteOrder};5use byteorder::{BigEndian, ByteOrder};
4use git_object::{borrowed, owned, SHA1_SIZE};6use git_object::{borrowed, owned, SHA1_SIZE};
5use quick_error::quick_error;7use quick_error::quick_error;
6use std::convert::{TryFrom, TryInto};8use std::{
7use std::fmt::{Debug, Formatter};9 convert::{TryFrom, TryInto},
8use std::slice::Chunks;10 fmt::{Debug, Formatter},
11 slice::Chunks,
12};
9 13
10quick_error! {14quick_error! {
11 #[derive(Debug)]15 #[derive(Debug)]
@@ -41,7 +45,7 @@ const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; · 29 unmodified lines
41 45
42pub struct Commit<'a> {46pub struct Commit<'a> {
43 file: &'a File,47 file: &'a File,
44 lex_pos: LexPosition,48 lex_pos: file::Position,
45 // We can parse the below fields lazily if needed.49 // We can parse the below fields lazily if needed.
46 commit_timestamp: u64,50 commit_timestamp: u64,
47 generation: u32,51 generation: u32,
@@ -51,7 +55,7 @@ pub struct Commit<'a> { · 3 unmodified lines
51}55}
52 56
53impl<'a> Commit<'a> {57impl<'a> Commit<'a> {
54 pub(crate) fn new(file: &'a File, pos: LexPosition) -> Self {58 pub(crate) fn new(file: &'a File, pos: file::Position) -> Self {
55 let bytes = file.commit_data_bytes(pos);59 let bytes = file.commit_data_bytes(pos);
56 Commit {60 Commit {
57 file,61 file,
@@ -79,7 +83,7 @@ impl<'a> Commit<'a> { · 21 unmodified lines
79 self.generation83 self.generation
80 }84 }
81 85
82 pub fn iter_parents(&'a self) -> impl Iterator<Item = Result<Position, Error>> + 'a {86 pub fn iter_parents(&'a self) -> impl Iterator<Item = Result<graph::Position, Error>> + 'a {
83 // I didn't find a combinator approach that a) was as strict as ParentIterator, b) supported87 // I didn't find a combinator approach that a) was as strict as ParentIterator, b) supported
84 // fuse-after-first-error behavior, and b) was significantly shorter or more understandable88 // fuse-after-first-error behavior, and b) was significantly shorter or more understandable
85 // than ParentIterator. So here we are.89 // than ParentIterator. So here we are.
@@ -93,7 +97,7 @@ impl<'a> Commit<'a> { · 7 unmodified lines
93 self.file.id_at(self.lex_pos)97 self.file.id_at(self.lex_pos)
94 }98 }
95 99
96 pub fn parent1(&self) -> Result<Option<Position>, Error> {100 pub fn parent1(&self) -> Result<Option<graph::Position>, Error> {
97 self.iter_parents().next().transpose()101 self.iter_parents().next().transpose()
98 }102 }
99 103
@@ -131,7 +135,7 @@ pub struct ParentIterator<'a> { · 31 unmodified lines
131}135}
132 136
133impl<'a> Iterator for ParentIterator<'a> {137impl<'a> Iterator for ParentIterator<'a> {
134 type Item = Result<Position, Error>;138 type Item = Result<graph::Position, Error>;
135 139
136 fn next(&mut self) -> Option<Self::Item> {140 fn next(&mut self) -> Option<Self::Item> {
137 let state = std::mem::replace(&mut self.state, ParentIteratorState::Exhausted);141 let state = std::mem::replace(&mut self.state, ParentIteratorState::Exhausted);
@@ -219,7 +223,7 @@ enum ParentIteratorState<'a> { · 81 unmodified lines
219#[derive(Clone, Copy, Debug)]223#[derive(Clone, Copy, Debug)]
220enum ParentEdge {224enum ParentEdge {
221 None,225 None,
222 GraphPosition(Position),226 GraphPosition(graph::Position),
223 ExtraEdgeIndex(u32),227 ExtraEdgeIndex(u32),
224}228}
225 229
@@ -231,7 +235,7 @@ impl ParentEdge { · 5 unmodified lines
231 if raw & EXTENDED_EDGES_MASK != 0 {235 if raw & EXTENDED_EDGES_MASK != 0 {
232 ParentEdge::ExtraEdgeIndex(raw & !EXTENDED_EDGES_MASK)236 ParentEdge::ExtraEdgeIndex(raw & !EXTENDED_EDGES_MASK)
233 } else {237 } else {
234 ParentEdge::GraphPosition(Position(raw))238 ParentEdge::GraphPosition(graph::Position(raw))
235 }239 }
236 }240 }
237}241}
@@ -239,16 +243,16 @@ impl ParentEdge { · 1 unmodified line
239const LAST_EXTENDED_EDGE_MASK: u32 = 0x8000_0000;243const LAST_EXTENDED_EDGE_MASK: u32 = 0x8000_0000;
240 244
241enum ExtraEdge {245enum ExtraEdge {
242 Internal(Position),246 Internal(graph::Position),
243 Last(Position),247 Last(graph::Position),
244}248}
245 249
246impl ExtraEdge {250impl ExtraEdge {
247 pub fn from_raw(raw: u32) -> Self {251 pub fn from_raw(raw: u32) -> Self {
248 if raw & LAST_EXTENDED_EDGE_MASK != 0 {252 if raw & LAST_EXTENDED_EDGE_MASK != 0 {
249 Self::Last(Position(raw & !LAST_EXTENDED_EDGE_MASK))253 Self::Last(graph::Position(raw & !LAST_EXTENDED_EDGE_MASK))
250 } else {254 } else {
251 Self::Internal(Position(raw))255 Self::Internal(graph::Position(raw))
252 }256 }
253 }257 }
254}258}