Showing the changes to git-object/src/commit (2 of 10 files). Show all
Unified · Split
| @@ -1,9 +1,7 @@ | |||
| 1 | use bstr::{BStr, ByteSlice}; | 1 | use bstr::{BStr, ByteSlice}; |
| 2 | 2 | ||
| 3 | pub use ref_iter::RefIter; | 3 | pub use crate::CommitRefIter; |
| 4 | 4 | use crate::{immutable, immutable::object, CommitRef, TagRef}; | |
| 5 | use crate::{immutable, TagRef}; | ||
| 6 | use crate::{immutable::object, CommitRef}; | ||
| 7 | 5 | ||
| 8 | mod decode; | 6 | mod decode; |
| 9 | 7 | ||
| @@ -1,6 +1,7 @@ | |||
| 1 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
| 2 | 2 | ||
| 3 | use bstr::BStr; | 3 | use bstr::BStr; |
| 4 | use git_hash::{oid, ObjectId}; | ||
| 4 | use nom::{ | 5 | use nom::{ |
| 5 | branch::alt, | 6 | branch::alt, |
| 6 | bytes::complete::is_not, | 7 | bytes::complete::is_not, |
| @@ -8,21 +9,20 @@ use nom::{ · 1 unmodified line | |||
| 8 | error::context, | 9 | error::context, |
| 9 | }; | 10 | }; |
| 10 | 11 | ||
| 11 | use git_hash::{oid, ObjectId}; | ||
| 12 | |||
| 13 | use crate::commit::decode; | ||
| 14 | use crate::{ | 12 | use crate::{ |
| 15 | bstr::ByteSlice, | 13 | bstr::ByteSlice, |
| 14 | commit::decode, | ||
| 16 | immutable::{object, parse, parse::NL}, | 15 | immutable::{object, parse, parse::NL}, |
| 16 | CommitRefIter, | ||
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | #[derive(Copy, Clone)] | 19 | #[derive(Copy, Clone)] |
| 20 | enum SignatureKind { | 20 | pub(crate) enum SignatureKind { |
| 21 | Author, | 21 | Author, |
| 22 | Committer, | 22 | Committer, |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | enum State { | 25 | pub(crate) enum State { |
| 26 | Tree, | 26 | Tree, |
| 27 | Parents, | 27 | Parents, |
| 28 | Signature { of: SignatureKind }, | 28 | Signature { of: SignatureKind }, |
| @@ -37,13 +37,6 @@ impl Default for State { · 8 unmodified lines | |||
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | /// Like [`CommitRef`][crate::CommitRef], but as `Iterator` to support (up to) entirely allocation free parsing. | ||
| 41 | /// It's particularly useful to traverse the commit graph without ever allocating arrays for parents. | ||
| 42 | pub struct CommitRefIter<'a> { | ||
| 43 | data: &'a [u8], | ||
| 44 | state: State, | ||
| 45 | } | ||
| 46 | |||
| 47 | impl<'a> CommitRefIter<'a> { | 40 | impl<'a> CommitRefIter<'a> { |
| 48 | /// Create a commit iterator from data. | 41 | /// Create a commit iterator from data. |
| 49 | pub fn from_bytes(data: &'a [u8]) -> CommitRefIter<'a> { | 42 | pub fn from_bytes(data: &'a [u8]) -> CommitRefIter<'a> { |
| @@ -198,7 +191,7 @@ impl<'a> Iterator for CommitRefIter<'a> { · 148 unmodified lines | |||
| 198 | } | 191 | } |
| 199 | } | 192 | } |
| 200 | 193 | ||
| 201 | /// A token returned by the [commit iterator][RefIter]. | 194 | /// A token returned by the [commit iterator][CommitRefIter]. |
| 202 | #[allow(missing_docs)] | 195 | #[allow(missing_docs)] |
| 203 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] | 196 | #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] |
| 204 | pub enum Token<'a> { | 197 | pub enum Token<'a> { |