1 use std
::convert
::TryFrom
;
3 use crate::{tree, Blob, BlobRef, Commit, CommitRef, Object, ObjectRef, Tag, TagRef, Tree, TreeRef}
;
5 impl From
<TagRef
<'_
>> for Tag
{
6 fn from(other
: TagRef
<'_
>) -> Tag
{
16 target
: gix_hash
::ObjectId
::from_hex(target
).expect("prior parser validation"),
17 name
: name
.to_owned(),
19 message
: message
.to_owned(),
20 tagger
: signature
.map(Into
::into
),
21 pgp_signature
: pgp_signature
.map(ToOwned
::to_owned
),
26 impl From
<CommitRef
<'_
>> for Commit
{
27 fn from(other
: CommitRef
<'_
>) -> Commit
{
38 tree
: gix_hash
::ObjectId
::from_hex(tree
).expect("prior parser validation"),
41 .map(|parent
| gix_hash
::ObjectId
::from_hex(parent
).expect("prior parser validation"))
43 author
: author
.into(),
44 committer
: committer
.into(),
45 encoding
: encoding
.map(ToOwned
::to_owned
),
46 message
: message
.to_owned(),
47 extra_headers
: extra_headers
49 .map(|(k
, v
)| (k
.into(), v
.into_owned()))
55 impl<'a
> From
<BlobRef
<'a
>> for Blob
{
56 fn from(v
: BlobRef
<'a
>) -> Self {
58 data
: v
.data
.to_owned(),
63 impl From
<TreeRef
<'_
>> for Tree
{
64 fn from(other
: TreeRef
<'_
>) -> Tree
{
65 let TreeRef { entries }
= other
;
67 entries
: entries
.into_iter().map(Into
::into
).collect(),
72 impl From
<tree
::EntryRef
<'_
>> for tree
::Entry
{
73 fn from(other
: tree
::EntryRef
<'_
>) -> tree
::Entry
{
74 let tree
::EntryRef { mode, filename, oid }
= other
;
77 filename
: filename
.to_owned(),
83 impl<'a
> From
<ObjectRef
<'a
>> for Object
{
84 fn from(v
: ObjectRef
<'_
>) -> Self {
86 ObjectRef
::Tree(v
) => Object
::Tree(v
.into()),
87 ObjectRef
::Blob(v
) => Object
::Blob(v
.into()),
88 ObjectRef
::Commit(v
) => Object
::Commit(v
.into()),
89 ObjectRef
::Tag(v
) => Object
::Tag(v
.into()),
94 impl From
<Tag
> for Object
{
95 fn from(v
: Tag
) -> Self {
100 impl From
<Commit
> for Object
{
101 fn from(v
: Commit
) -> Self {
106 impl From
<Tree
> for Object
{
107 fn from(v
: Tree
) -> Self {
112 impl From
<Blob
> for Object
{
113 fn from(v
: Blob
) -> Self {
118 impl TryFrom
<Object
> for Tag
{
121 fn try_from(value
: Object
) -> Result
<Self, Self::Error
> {
124 _
=> return Err(value
),
129 impl TryFrom
<Object
> for Commit
{
132 fn try_from(value
: Object
) -> Result
<Self, Self::Error
> {
134 Object
::Commit(v
) => v
,
135 _
=> return Err(value
),
140 impl TryFrom
<Object
> for Tree
{
143 fn try_from(value
: Object
) -> Result
<Self, Self::Error
> {
145 Object
::Tree(v
) => v
,
146 _
=> return Err(value
),
151 impl TryFrom
<Object
> for Blob
{
154 fn try_from(value
: Object
) -> Result
<Self, Self::Error
> {
156 Object
::Blob(v
) => v
,
157 _
=> return Err(value
),
162 impl<'a
> From
<TagRef
<'a
>> for ObjectRef
<'a
> {
163 fn from(v
: TagRef
<'a
>) -> Self {
168 impl<'a
> From
<CommitRef
<'a
>> for ObjectRef
<'a
> {
169 fn from(v
: CommitRef
<'a
>) -> Self {
174 impl<'a
> From
<TreeRef
<'a
>> for ObjectRef
<'a
> {
175 fn from(v
: TreeRef
<'a
>) -> Self {
180 impl<'a
> From
<BlobRef
<'a
>> for ObjectRef
<'a
> {
181 fn from(v
: BlobRef
<'a
>) -> Self {
186 impl<'a
> TryFrom
<ObjectRef
<'a
>> for TagRef
<'a
> {
187 type Error
= ObjectRef
<'a
>;
189 fn try_from(value
: ObjectRef
<'a
>) -> Result
<Self, Self::Error
> {
191 ObjectRef
::Tag(v
) => v
,
192 _
=> return Err(value
),
197 impl<'a
> TryFrom
<ObjectRef
<'a
>> for CommitRef
<'a
> {
198 type Error
= ObjectRef
<'a
>;
200 fn try_from(value
: ObjectRef
<'a
>) -> Result
<Self, Self::Error
> {
202 ObjectRef
::Commit(v
) => v
,
203 _
=> return Err(value
),
208 impl<'a
> TryFrom
<ObjectRef
<'a
>> for TreeRef
<'a
> {
209 type Error
= ObjectRef
<'a
>;
211 fn try_from(value
: ObjectRef
<'a
>) -> Result
<Self, Self::Error
> {
213 ObjectRef
::Tree(v
) => v
,
214 _
=> return Err(value
),
219 impl<'a
> TryFrom
<ObjectRef
<'a
>> for BlobRef
<'a
> {
220 type Error
= ObjectRef
<'a
>;
222 fn try_from(value
: ObjectRef
<'a
>) -> Result
<Self, Self::Error
> {
224 ObjectRef
::Blob(v
) => v
,
225 _
=> return Err(value
),