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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
//! 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, required fields being
//! present) 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.
//! - **Consistency**: All object types use the same builder pattern, making
//! the construction experience uniform across the crate.
//!
//! # Internal Mechanism
//!
//! Each builder holds intermediate state, typically in `Option` or `Vec`
//! wrappers. When `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 Structure
//!
//! The module is organized into the following submodules:
//!
//! - [`blob`](self::blob): [`BlobBuilder`] for constructing blobs.
//! - [`commit`](self::commit): [`CommitBuilder`] for constructing commits.
//! - [`tag`](self::tag): [`TagBuilder`] for constructing tags.
//! - [`tree`](self::tree): [`TreeBuilder`] and [`TreeEntryBuilder`] for
//! constructing trees and tree entries.
//!
//! Each builder is re-exported at the module root for ergonomic access.
//!
//! # How Builders Relate to Handlers
//!
//! The builders do not replace the constructors provided by
//! `libvctrl_handler`. Instead, they provide a more readable and flexible
//! way to collect values and then delegate to the native constructors. This
//! keeps the handler types pure and immutable while moving the assembly
//! logic to `libvctrl_core`.
//!
//! # Examples
//!
//! Building a commit with the fluent API:
//!
//! ```
//! use libvctrl_core::object::CommitBuilder;
//! use libvctrl_handler::{Hash, UserID};
//!
//! let tree = Hash::from_bytes(&[0u8; 64]).unwrap();
//! let author = UserID::new("Alice".into(), "alice@example.com".into()).unwrap();
//! let committer = UserID::new("Bob".into(), "bob@example.com".into()).unwrap();
//!
//! let commit = CommitBuilder::new()
//! .tree(tree)
//! .author(author)
//! .committer(committer)
//! .message("Initial commit")
//! .build()
//! .unwrap();
//!
//! assert_eq!(commit.message(), "Initial commit");
//! ```
/// Module containing the [`BlobBuilder`](crate::object::BlobBuilder)
/// implementation.
///
/// # Purpose
///
/// Provides a fluent API for constructing [`Blob`](libvctrl_handler::Blob)
/// objects.
///
/// # Design Rationale
///
/// The builder is isolated in its own module to keep the object module
/// organized and to allow future extensions such as optional compression or
/// validation before finalization.
///
/// # 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.
///
/// # Design Rationale
///
/// Commits have several required and optional fields. The builder pattern
/// avoids telescoping constructors and centralizes missing-field validation
/// in the `build()` method.
///
/// # 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.
///
/// # Design Rationale
///
/// Tags have optional tagger and message fields, making the builder pattern
/// ideal for supporting both lightweight and annotated tags.
///
/// # 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.
///
/// # Design Rationale
///
/// Trees require entries to be sorted and validated. The builders allow
/// incremental assembly and delegate final structural validation to
/// [`Tree::new`](libvctrl_handler::Tree::new).
///
/// # 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` instead of the full path.
///
/// # Design Rationale
///
/// Re-exporting at the module root reduces boilerplate and improves the
/// ergonomic experience for consumers of the crate.
///
/// # 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`.
///
/// # Design Rationale
///
/// Re-exporting provides a clean public API surface while maintaining
/// internal modularity.
///
/// # 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`.
///
/// # Design Rationale
///
/// Re-exporting keeps the API ergonomic and consistent with the rest of the
/// crate.
///
/// # 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`.
///
/// # Design Rationale
///
/// Re-exporting both tree builders together simplifies imports and keeps the
/// public API clean.
///
/// # 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 ;