1use std::collections::BTreeMap;
4use std::path::PathBuf;
5
6use cadvm_store::{BlobRef, ObjectId};
7use serde::{Deserialize, Serialize};
8
9use crate::format::CadFormat;
10use crate::mesh::MeshMetadata;
11use crate::step::StepMetadata;
12
13pub const MANIFEST_VERSION: u32 = 1;
15
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18pub struct Author {
19 pub name: String,
20 pub email: String,
21}
22
23impl Author {
24 pub fn display(&self) -> String {
26 if self.email.is_empty() {
27 self.name.clone()
28 } else {
29 format!("{} <{}>", self.name, self.email)
30 }
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38pub struct FileEntry {
39 pub path: PathBuf,
41 pub format: CadFormat,
42 pub raw_hash: ObjectId,
44 pub blob_ref: BlobRef,
46 pub size_bytes: u64,
47 pub line_count: Option<u64>,
48 #[serde(default)]
50 pub step_metadata: Option<StepMetadata>,
51 #[serde(default)]
53 pub mesh_metadata: Option<MeshMetadata>,
54}
55
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
58pub struct Manifest {
59 pub version: u32,
60 pub files: BTreeMap<PathBuf, FileEntry>,
61}
62
63impl Manifest {
64 pub fn empty() -> Self {
66 Manifest {
67 version: MANIFEST_VERSION,
68 files: BTreeMap::new(),
69 }
70 }
71
72 pub fn file_count(&self) -> usize {
74 self.files.len()
75 }
76}
77
78#[derive(Debug, Clone, PartialEq, Eq)]
84pub struct Commit {
85 pub id: ObjectId,
86 pub parents: Vec<ObjectId>,
87 pub manifest: ObjectId,
88 pub message: String,
89 pub timestamp_unix: i64,
90 pub author: Option<Author>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96pub struct CommitBody {
97 pub parents: Vec<ObjectId>,
98 pub manifest: ObjectId,
99 pub message: String,
100 pub timestamp_unix: i64,
101 #[serde(default)]
103 pub author: Option<Author>,
104}
105
106impl Commit {
107 pub fn body(&self) -> CommitBody {
109 CommitBody {
110 parents: self.parents.clone(),
111 manifest: self.manifest.clone(),
112 message: self.message.clone(),
113 timestamp_unix: self.timestamp_unix,
114 author: self.author.clone(),
115 }
116 }
117
118 pub fn from_body(id: ObjectId, body: CommitBody) -> Self {
120 Commit {
121 id,
122 parents: body.parents,
123 manifest: body.manifest,
124 message: body.message,
125 timestamp_unix: body.timestamp_unix,
126 author: body.author,
127 }
128 }
129}