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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//! Builder patterns for constructing version control objects.
//!
//! # Purpose
//! This module aggregates the builder implementations for the core version
//! control objects: [`Blob`](libvctrl_handler::Blob), [`Tree`](libvctrl_handler::Tree),
//! [`Commit`](libvctrl_handler::Commit), and [`Tag`](libvctrl_handler::Tag).
//! Builders provide a fluent, ergonomic interface for assembling complex objects
//! step-by-step.
//!
//! # Design rationale
//! - **Telescoping Constructor Avoidance**: VCS objects like `Commit` and `Tag`
//! have many fields, some required and some optional. Using standard
//! constructors would lead to a combinatorial explosion of `new` methods.
//! The builder pattern defers validation to a single `build()` method.
//! - **Deferred Validation**: Builders accumulate state without performing
//! heavy validation. When `build()` is called, the final structural invariants
//! (e.g., tree entries being sorted) are enforced centrally by the
//! [`libvctrl_handler`] types.
//! - **Ownership Transfer**: The builders consume `self` and return it by value
//! during configuration. This allows method chaining and ensures that the
//! underlying data (like `Vec<u8>` or `String`) is moved directly into the
//! final object with zero heap allocations or cloning overhead.
//!
//! # Internal mechanism
//! Each builder holds intermediate state (usually `Option` or `Vec` wrappers).
//! When [`build`](libvctrl_core::object::CommitBuilder::build) is invoked, the
//! builder extracts the raw fields, checks for missing required data, and passes
//! them to the constructor of the corresponding [`libvctrl_handler`] type.
/// Module containing the [`BlobBuilder`](crate::object::BlobBuilder) implementation.
///
/// # Purpose
/// Provides a fluent API for constructing [`Blob`](libvctrl_handler::Blob) objects.
///
/// # Examples
///
/// ```
/// use libvctrl_core::object::blob::BlobBuilder;
///
/// let blob = BlobBuilder::new()
/// .with_data(b"hello".to_vec())
/// .build();
///
/// assert_eq!(blob.size(), 5);
/// ```
/// Module containing the [`CommitBuilder`](crate::object::CommitBuilder) implementation.
///
/// # Purpose
/// Provides a fluent API for constructing [`Commit`](libvctrl_handler::Commit) objects.
///
/// # Examples
///
/// ```
/// use libvctrl_core::object::commit::CommitBuilder;
/// use libvctrl_handler::{Hash, UserID};
///
/// let tree = Hash::from_bytes(&[0u8; 64]).unwrap();
/// let user = UserID::new("Alice".to_string(), "a@b.com".to_string()).unwrap();
///
/// let commit = CommitBuilder::new()
/// .tree(tree)
/// .author(user.clone())
/// .committer(user)
/// .message("Initial commit")
/// .build()
/// .unwrap();
///
/// assert_eq!(commit.message(), "Initial commit");
/// ```
/// Module containing the [`TagBuilder`](crate::object::TagBuilder) implementation.
///
/// # Purpose
/// Provides a fluent API for constructing [`Tag`](libvctrl_handler::Tag) objects.
///
/// # Examples
///
/// ```
/// use libvctrl_core::object::tag::TagBuilder;
/// use libvctrl_handler::Hash;
///
/// let target = Hash::from_bytes(&[0u8; 64]).unwrap();
/// let tag = TagBuilder::new()
/// .name("v1.0")
/// .target(target)
/// .build()
/// .unwrap();
///
/// assert_eq!(tag.name(), "v1.0");
/// ```
/// Module containing the [`TreeBuilder`](crate::object::TreeBuilder) and
/// [`TreeEntryBuilder`](crate::object::TreeEntryBuilder) implementations.
///
/// # Purpose
/// Provides fluent APIs for constructing [`Tree`](libvctrl_handler::Tree) and
/// [`TreeEntry`](libvctrl_handler::TreeEntry) objects.
///
/// # Examples
///
/// ```
/// use libvctrl_core::object::tree::TreeBuilder;
/// use libvctrl_handler::{EntryKind, Hash};
///
/// let hash = Hash::from_bytes(&[0u8; 64]).unwrap();
/// let tree = TreeBuilder::new()
/// .add_entry("file.txt".to_string(), EntryKind::Blob, hash)?
/// .build()
/// .unwrap();
///
/// assert_eq!(tree.entries().len(), 1);
/// # Ok::<(), libvctrl_handler::VctrlError>(())
/// ```
/// Re-export of the [`BlobBuilder`](crate::object::BlobBuilder) struct.
///
/// # Purpose
/// Flattens the module path so users can simply import
/// `libvctrl_core::object::BlobBuilder`.
///
/// # Examples
///
/// ```
/// use libvctrl_core::object::BlobBuilder;
///
/// let blob = BlobBuilder::default().build();
/// assert!(blob.is_empty());
/// ```
pub use BlobBuilder;
/// Re-export of the [`CommitBuilder`](crate::object::CommitBuilder) struct.
///
/// # Purpose
/// Flattens the module path so users can simply import
/// `libvctrl_core::object::CommitBuilder`.
///
/// # Examples
///
/// ```
/// use libvctrl_core::object::CommitBuilder;
/// use libvctrl_handler::{Hash, UserID};
///
/// let tree = Hash::from_bytes(&[0u8; 64]).unwrap();
/// let user = UserID::new("A".to_string(), "a@a.com".to_string()).unwrap();
///
/// let commit = CommitBuilder::new()
/// .tree(tree)
/// .author(user.clone())
/// .committer(user)
/// .message("msg")
/// .build()
/// .unwrap();
///
/// assert_eq!(commit.parents().len(), 0);
/// ```
pub use CommitBuilder;
/// Re-export of the [`TagBuilder`](crate::object::TagBuilder) struct.
///
/// # Purpose
/// Flattens the module path so users can simply import
/// `libvctrl_core::object::TagBuilder`.
///
/// # Examples
///
/// ```
/// use libvctrl_core::object::TagBuilder;
/// use libvctrl_handler::Hash;
///
/// let target = Hash::from_bytes(&[0u8; 64]).unwrap();
/// let tag = TagBuilder::new()
/// .name("v2.0")
/// .target(target)
/// .build()
/// .unwrap();
///
/// assert_eq!(tag.name(), "v2.0");
/// ```
pub use TagBuilder;
/// Re-export of the [`TreeBuilder`](crate::object::TreeBuilder) and
/// [`TreeEntryBuilder`](crate::object::TreeEntryBuilder) structs.
///
/// # Purpose
/// Flattens the module path so users can simply import
/// `libvctrl_core::object::TreeBuilder` and `TreeEntryBuilder`.
///
/// # Examples
///
/// ```
/// use libvctrl_core::object::{TreeBuilder, TreeEntryBuilder};
/// use libvctrl_handler::{EntryKind, Hash};
///
/// let hash = Hash::from_bytes(&[0u8; 64]).unwrap();
/// let entry = TreeEntryBuilder::new("dir".to_string(), EntryKind::Tree, hash)
/// .build()
/// .unwrap();
///
/// let tree = TreeBuilder::new()
/// .entry(entry)
/// .build()
/// .unwrap();
///
/// assert_eq!(tree.entries().len(), 1);
/// ```
pub use ;