|
1 |
| -use crate::Time; |
2 |
| -use bstr::BStr; |
3 |
| - |
4 | 1 | mod commit;
|
5 |
| -mod tag; |
6 |
| -mod tree; |
7 |
| -mod util; |
8 |
| - |
9 | 2 | pub use commit::Commit;
|
| 3 | + |
| 4 | +mod tag; |
10 | 5 | pub use tag::Tag;
|
| 6 | + |
| 7 | +mod tree; |
11 | 8 | //FIXME: keep tree mode and entry in tree export it from there? Alternatively rename to TreeMode, TreeEntry?
|
12 | 9 | pub use tree::{Entry, Mode, Tree};
|
13 | 10 |
|
14 |
| -mod error { |
15 |
| - use nom::error::ParseError; |
16 |
| - use quick_error::quick_error; |
17 |
| - quick_error! { |
18 |
| - #[derive(Debug)] |
19 |
| - pub enum Error { |
20 |
| - ParseIntegerError(msg: &'static str, number: bstr::BString, err: btoi::ParseIntegerError) { |
21 |
| - display("{}: {:?}", msg, number) |
22 |
| - cause(err) |
23 |
| - } |
24 |
| - Nom(err_msg: String) { |
25 |
| - display("{}", err_msg) |
26 |
| - } |
27 |
| - NomDetail(input: bstr::BString, msg: &'static str) { |
28 |
| - display("{}: '{}' could not be parsed", msg, input) |
29 |
| - } |
30 |
| - ParseKindError(err: crate::types::Error) { |
31 |
| - display("{}", err) |
32 |
| - cause(err) |
33 |
| - } |
34 |
| - ObjectKind(err: crate::Error) { |
35 |
| - from() |
36 |
| - cause(err) |
| 11 | +mod util; |
| 12 | + |
| 13 | +mod object { |
| 14 | + use crate::Time; |
| 15 | + use bstr::BStr; |
| 16 | + |
| 17 | + mod error { |
| 18 | + use nom::error::ParseError; |
| 19 | + use quick_error::quick_error; |
| 20 | + quick_error! { |
| 21 | + #[derive(Debug)] |
| 22 | + pub enum Error { |
| 23 | + ParseIntegerError(msg: &'static str, number: bstr::BString, err: btoi::ParseIntegerError) { |
| 24 | + display("{}: {:?}", msg, number) |
| 25 | + cause(err) |
| 26 | + } |
| 27 | + Nom(err_msg: String) { |
| 28 | + display("{}", err_msg) |
| 29 | + } |
| 30 | + NomDetail(input: bstr::BString, msg: &'static str) { |
| 31 | + display("{}: '{}' could not be parsed", msg, input) |
| 32 | + } |
| 33 | + ParseKindError(err: crate::types::Error) { |
| 34 | + display("{}", err) |
| 35 | + cause(err) |
| 36 | + } |
| 37 | + ObjectKind(err: crate::Error) { |
| 38 | + from() |
| 39 | + cause(err) |
| 40 | + } |
37 | 41 | }
|
38 | 42 | }
|
39 |
| - } |
40 | 43 |
|
41 |
| - impl Error { |
42 |
| - fn set_parse_context(mut self, ctx: &'static str) -> Self { |
43 |
| - match self { |
44 |
| - Error::NomDetail(_, ref mut message) => *message = ctx, |
45 |
| - _ => {} |
46 |
| - }; |
47 |
| - self |
48 |
| - } |
| 44 | + impl Error { |
| 45 | + fn set_parse_context(mut self, ctx: &'static str) -> Self { |
| 46 | + match self { |
| 47 | + Error::NomDetail(_, ref mut message) => *message = ctx, |
| 48 | + _ => {} |
| 49 | + }; |
| 50 | + self |
| 51 | + } |
49 | 52 |
|
50 |
| - pub(crate) fn context(msg: &'static str) -> impl Fn(nom::Err<Self>) -> nom::Err<Self> { |
51 |
| - move |e: nom::Err<Self>| e.map(|e| e.set_parse_context(msg)) |
| 53 | + pub(crate) fn context(msg: &'static str) -> impl Fn(nom::Err<Self>) -> nom::Err<Self> { |
| 54 | + move |e: nom::Err<Self>| e.map(|e| e.set_parse_context(msg)) |
| 55 | + } |
52 | 56 | }
|
53 |
| - } |
54 | 57 |
|
55 |
| - impl ParseError<&[u8]> for Error { |
56 |
| - fn from_error_kind(input: &[u8], _kind: nom::error::ErrorKind) -> Self { |
57 |
| - Error::NomDetail(input.into(), "parse error") |
58 |
| - } |
| 58 | + impl ParseError<&[u8]> for Error { |
| 59 | + fn from_error_kind(input: &[u8], _kind: nom::error::ErrorKind) -> Self { |
| 60 | + Error::NomDetail(input.into(), "parse error") |
| 61 | + } |
59 | 62 |
|
60 |
| - fn append(_: &[u8], _: nom::error::ErrorKind, other: Self) -> Self { |
61 |
| - other |
| 63 | + fn append(_: &[u8], _: nom::error::ErrorKind, other: Self) -> Self { |
| 64 | + other |
| 65 | + } |
62 | 66 | }
|
63 |
| - } |
64 | 67 |
|
65 |
| - impl From<nom::Err<Error>> for Error { |
66 |
| - fn from(e: nom::Err<Error>) -> Self { |
67 |
| - match e { |
68 |
| - nom::Err::Error(err) | nom::Err::Failure(err) => Error::Nom(err.to_string()), |
69 |
| - nom::Err::Incomplete(_) => unreachable!("we do not implement streaming parsers"), |
| 68 | + impl From<nom::Err<Error>> for Error { |
| 69 | + fn from(e: nom::Err<Error>) -> Self { |
| 70 | + match e { |
| 71 | + nom::Err::Error(err) | nom::Err::Failure(err) => Error::Nom(err.to_string()), |
| 72 | + nom::Err::Incomplete(_) => { |
| 73 | + unreachable!("we do not implement streaming parsers") |
| 74 | + } |
| 75 | + } |
70 | 76 | }
|
71 | 77 | }
|
72 | 78 | }
|
73 |
| -} |
74 | 79 |
|
75 |
| -pub use error::Error; |
| 80 | + use crate::borrowed::{Commit, Tag, Tree}; |
| 81 | + pub use error::Error; |
76 | 82 |
|
77 |
| -#[derive(PartialEq, Eq, Debug, Hash)] |
78 |
| -pub struct Signature<'data> { |
79 |
| - pub name: &'data BStr, |
80 |
| - pub email: &'data BStr, |
81 |
| - pub time: Time, |
82 |
| -} |
| 83 | + #[derive(PartialEq, Eq, Debug, Hash)] |
| 84 | + pub struct Signature<'data> { |
| 85 | + pub name: &'data BStr, |
| 86 | + pub email: &'data BStr, |
| 87 | + pub time: Time, |
| 88 | + } |
83 | 89 |
|
84 |
| -#[derive(PartialEq, Eq, Debug, Hash)] |
85 |
| -pub enum Object<'data> { |
86 |
| - Tag(Tag<'data>), |
87 |
| - Commit(Commit<'data>), |
88 |
| - Tree(Tree<'data>), |
89 |
| -} |
| 90 | + #[derive(PartialEq, Eq, Debug, Hash)] |
| 91 | + pub enum Object<'data> { |
| 92 | + Tag(Tag<'data>), |
| 93 | + Commit(Commit<'data>), |
| 94 | + Tree(Tree<'data>), |
| 95 | + } |
90 | 96 |
|
91 |
| -impl<'data> Object<'data> { |
92 |
| - pub fn kind(&self) -> crate::Kind { |
93 |
| - match self { |
94 |
| - Object::Tag(_) => crate::Kind::Tag, |
95 |
| - Object::Commit(_) => crate::Kind::Commit, |
96 |
| - Object::Tree(_) => crate::Kind::Tree, |
| 97 | + impl<'data> Object<'data> { |
| 98 | + pub fn kind(&self) -> crate::Kind { |
| 99 | + match self { |
| 100 | + Object::Tag(_) => crate::Kind::Tag, |
| 101 | + Object::Commit(_) => crate::Kind::Commit, |
| 102 | + Object::Tree(_) => crate::Kind::Tree, |
| 103 | + } |
97 | 104 | }
|
98 | 105 | }
|
99 |
| -} |
100 | 106 |
|
101 |
| -mod convert { |
102 |
| - use crate::borrowed::{Commit, Object, Tag, Tree}; |
103 |
| - use std::convert::TryFrom; |
| 107 | + mod convert { |
| 108 | + use crate::borrowed::{Commit, Object, Tag, Tree}; |
| 109 | + use std::convert::TryFrom; |
104 | 110 |
|
105 |
| - impl<'data> From<Tag<'data>> for Object<'data> { |
106 |
| - fn from(v: Tag<'data>) -> Self { |
107 |
| - Object::Tag(v) |
| 111 | + impl<'data> From<Tag<'data>> for Object<'data> { |
| 112 | + fn from(v: Tag<'data>) -> Self { |
| 113 | + Object::Tag(v) |
| 114 | + } |
108 | 115 | }
|
109 |
| - } |
110 | 116 |
|
111 |
| - impl<'data> From<Commit<'data>> for Object<'data> { |
112 |
| - fn from(v: Commit<'data>) -> Self { |
113 |
| - Object::Commit(v) |
| 117 | + impl<'data> From<Commit<'data>> for Object<'data> { |
| 118 | + fn from(v: Commit<'data>) -> Self { |
| 119 | + Object::Commit(v) |
| 120 | + } |
114 | 121 | }
|
115 |
| - } |
116 | 122 |
|
117 |
| - impl<'data> From<Tree<'data>> for Object<'data> { |
118 |
| - fn from(v: Tree<'data>) -> Self { |
119 |
| - Object::Tree(v) |
| 123 | + impl<'data> From<Tree<'data>> for Object<'data> { |
| 124 | + fn from(v: Tree<'data>) -> Self { |
| 125 | + Object::Tree(v) |
| 126 | + } |
120 | 127 | }
|
121 |
| - } |
122 | 128 |
|
123 |
| - impl<'data> TryFrom<Object<'data>> for Tag<'data> { |
124 |
| - type Error = Object<'data>; |
| 129 | + impl<'data> TryFrom<Object<'data>> for Tag<'data> { |
| 130 | + type Error = Object<'data>; |
125 | 131 |
|
126 |
| - fn try_from(value: Object<'data>) -> Result<Self, Self::Error> { |
127 |
| - Ok(match value { |
128 |
| - Object::Tag(v) => v, |
129 |
| - _ => return Err(value), |
130 |
| - }) |
| 132 | + fn try_from(value: Object<'data>) -> Result<Self, Self::Error> { |
| 133 | + Ok(match value { |
| 134 | + Object::Tag(v) => v, |
| 135 | + _ => return Err(value), |
| 136 | + }) |
| 137 | + } |
131 | 138 | }
|
132 |
| - } |
133 | 139 |
|
134 |
| - impl<'data> TryFrom<Object<'data>> for Commit<'data> { |
135 |
| - type Error = Object<'data>; |
| 140 | + impl<'data> TryFrom<Object<'data>> for Commit<'data> { |
| 141 | + type Error = Object<'data>; |
136 | 142 |
|
137 |
| - fn try_from(value: Object<'data>) -> Result<Self, Self::Error> { |
138 |
| - Ok(match value { |
139 |
| - Object::Commit(v) => v, |
140 |
| - _ => return Err(value), |
141 |
| - }) |
| 143 | + fn try_from(value: Object<'data>) -> Result<Self, Self::Error> { |
| 144 | + Ok(match value { |
| 145 | + Object::Commit(v) => v, |
| 146 | + _ => return Err(value), |
| 147 | + }) |
| 148 | + } |
142 | 149 | }
|
143 |
| - } |
144 | 150 |
|
145 |
| - impl<'data> TryFrom<Object<'data>> for Tree<'data> { |
146 |
| - type Error = Object<'data>; |
| 151 | + impl<'data> TryFrom<Object<'data>> for Tree<'data> { |
| 152 | + type Error = Object<'data>; |
147 | 153 |
|
148 |
| - fn try_from(value: Object<'data>) -> Result<Self, Self::Error> { |
149 |
| - Ok(match value { |
150 |
| - Object::Tree(v) => v, |
151 |
| - _ => return Err(value), |
152 |
| - }) |
| 154 | + fn try_from(value: Object<'data>) -> Result<Self, Self::Error> { |
| 155 | + Ok(match value { |
| 156 | + Object::Tree(v) => v, |
| 157 | + _ => return Err(value), |
| 158 | + }) |
| 159 | + } |
153 | 160 | }
|
154 | 161 | }
|
155 | 162 | }
|
| 163 | + |
| 164 | +pub use object::*; |
0 commit comments