History

[object #177] commit::RefIter -> CommitRefIter

Sebastian Thiel committed 5 years ago

Commit e6033061 parent 45d393410 files · +27 −35Browse files

Showing the changes to git-object/src/commit (2 of 10 files). Show all

Unified · Split

2 files
  1. git-object/src/commit/mod.rs +2 −4
  2. git-object/src/commit/ref_iter.rs +6 −13
git-object/src/commit/mod.rs+2−4
@@ -1,9 +1,7 @@
1use bstr::{BStr, ByteSlice};1use bstr::{BStr, ByteSlice};
2 2
3pub use ref_iter::RefIter;3pub use crate::CommitRefIter;
4 4use crate::{immutable, immutable::object, CommitRef, TagRef};
5use crate::{immutable, TagRef};
6use crate::{immutable::object, CommitRef};
7 5
8mod decode;6mod decode;
9 7
git-object/src/commit/ref_iter.rs+6−13
@@ -1,6 +1,7 @@
1use std::borrow::Cow;1use std::borrow::Cow;
2 2
3use bstr::BStr;3use bstr::BStr;
4use git_hash::{oid, ObjectId};
4use nom::{5use 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
11use git_hash::{oid, ObjectId};
12
13use crate::commit::decode;
14use crate::{12use 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)]
20enum SignatureKind {20pub(crate) enum SignatureKind {
21 Author,21 Author,
22 Committer,22 Committer,
23}23}
24 24
25enum State {25pub(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.
42pub struct CommitRefIter<'a> {
43 data: &'a [u8],
44 state: State,
45}
46
47impl<'a> CommitRefIter<'a> {40impl<'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)]
204pub enum Token<'a> {197pub enum Token<'a> {