git_internal/internal/pack/
entry.rs1use std::hash::{Hash, Hasher};
2
3use serde::{Deserialize, Serialize};
4
5use crate::hash::ObjectHash;
6use crate::internal::object::ObjectTrait;
7use crate::internal::object::blob::Blob;
8use crate::internal::object::commit::Commit;
9use crate::internal::object::tag::Tag;
10use crate::internal::object::tree::Tree;
11use crate::internal::object::types::ObjectType;
12
13#[derive(Eq, Clone, Debug, Serialize, Deserialize)]
17pub struct Entry {
18 pub obj_type: ObjectType,
19 pub data: Vec<u8>,
20 pub hash: ObjectHash,
21 pub chain_len: usize,
22}
23
24impl PartialEq for Entry {
25 fn eq(&self, other: &Self) -> bool {
26 self.obj_type == other.obj_type && self.hash == other.hash
28 }
29}
30
31impl Hash for Entry {
32 fn hash<H: Hasher>(&self, state: &mut H) {
33 self.obj_type.hash(state);
34 self.hash.hash(state);
35 }
36}
37
38impl From<Blob> for Entry {
39 fn from(value: Blob) -> Self {
40 Self {
41 obj_type: ObjectType::Blob,
42 data: value.data,
43 hash: value.id,
44 chain_len: 0,
45 }
46 }
47}
48
49impl From<Commit> for Entry {
50 fn from(value: Commit) -> Self {
51 Self {
52 obj_type: ObjectType::Commit,
53 data: value.to_data().unwrap(),
54 hash: value.id,
55 chain_len: 0,
56 }
57 }
58}
59
60impl From<Tree> for Entry {
61 fn from(value: Tree) -> Self {
62 Self {
63 obj_type: ObjectType::Tree,
64 data: value.to_data().unwrap(),
65 hash: value.id,
66 chain_len: 0,
67 }
68 }
69}
70
71impl From<Tag> for Entry {
72 fn from(value: Tag) -> Self {
73 Self {
74 obj_type: ObjectType::Tag,
75 data: value.to_data().unwrap(),
76 hash: value.id,
77 chain_len: 0,
78 }
79 }
80}