1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
use crate::{borrowed, owned}; impl From<borrowed::Signature<'_>> for owned::Signature { fn from(other: borrowed::Signature<'_>) -> owned::Signature { let borrowed::Signature { name, email, time } = other; owned::Signature { name: name.to_owned(), email: email.to_owned(), time, } } } impl From<borrowed::Tag<'_>> for owned::Tag { fn from(other: borrowed::Tag<'_>) -> owned::Tag { let borrowed::Tag { target, name, target_kind, message, signature, pgp_signature, } = other; owned::Tag { target: git_hash::ObjectId::from_hex(&target).expect("40 bytes hex sha1"), name: name.to_owned(), target_kind, message: message.to_owned(), signature: signature.map(Into::into), pgp_signature: pgp_signature.map(ToOwned::to_owned), } } } impl From<borrowed::Commit<'_>> for owned::Commit { fn from(other: borrowed::Commit<'_>) -> owned::Commit { let borrowed::Commit { tree, parents, author, committer, encoding, message, extra_headers, } = other; owned::Commit { tree: git_hash::ObjectId::from_hex(&tree).expect("40 bytes hex sha1"), parents: parents .iter() .map(|parent| git_hash::ObjectId::from_hex(parent).expect("40 bytes hex sha1")) .collect(), author: author.into(), committer: committer.into(), encoding: encoding.map(ToOwned::to_owned), message: message.to_owned(), extra_headers: extra_headers .into_iter() .map(|(k, v)| (k.into(), v.into_owned())) .collect(), } } } impl<'a> From<borrowed::Blob<'a>> for owned::Blob { fn from(v: borrowed::Blob<'a>) -> Self { owned::Blob { data: v.data.to_owned(), } } } impl From<borrowed::Tree<'_>> for owned::Tree { fn from(other: borrowed::Tree<'_>) -> owned::Tree { let borrowed::Tree { entries } = other; owned::Tree { entries: entries.into_iter().map(Into::into).collect(), } } } impl From<borrowed::tree::Entry<'_>> for owned::tree::Entry { fn from(other: borrowed::tree::Entry<'_>) -> owned::tree::Entry { let borrowed::tree::Entry { mode, filename, oid } = other; owned::tree::Entry { mode, filename: filename.to_owned(), oid: oid.into(), } } } impl<'a> From<borrowed::Object<'a>> for owned::Object { fn from(v: borrowed::Object<'_>) -> Self { match v { borrowed::Object::Tree(v) => owned::Object::Tree(v.into()), borrowed::Object::Blob(v) => owned::Object::Blob(v.into()), borrowed::Object::Commit(v) => owned::Object::Commit(v.into()), borrowed::Object::Tag(v) => owned::Object::Tag(v.into()), } } }