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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
//! Core traits for repository operations.
//!
//! # Architecture
//! This module defines the fundamental contracts required to build a functional
//! version control backend. By segregating these traits into a dedicated `core`
//! module, we establish a strict boundary between abstract domain logic and
//! concrete I/O implementations.
//!
//! # Design Rationale: Dependency Inversion
//! The entire crate operates against these traits, never against concrete types.
//! This allows consumers to inject custom backends (in-memory, disk-based, or
//! network-attached) seamlessly. It also simplifies unit testing, as mock
//! implementations can be substituted without altering the core algorithms.
//!
//! # Bounded Contexts
//! Each submodule represents a distinct bounded context within the Git architecture:
//! - **Storage**: [`object_store`], [`pack`]
//! - **State**: [`ref_store`], [`reflog`], [`index`]
//! - **Serialization**: [`encoder`], [`decoder`], [`hasher`]
//! - **Analysis**: [`diff`], [`blame`], [`revwalk`]
//! - **Security**: [`signer`], [`verifier`]
//! - **Networking**: [`remote`], [`transport`]
//! - **Configuration**: [`config`]
//!
//! # Examples
//! *Note: The following example assumes this crate is named `libvctrl_handler`.*
//!
//! ```
//! # use libvctrl_handler::traits::core::{
//! # blame, config, decoder, diff, encoder, hasher, index, object_store,
//! # pack, ref_store, reflog, remote, revwalk, signer, transport, verifier,
//! # };
//! // All core trait modules are publicly accessible.
//! ```
/// Blame computation trait.
///
/// # Why this exists
/// Provides the contract for attributing lines in a file to specific commits.
/// This is separated from standard diffing because blame requires traversing
/// history and tracking line movements across revisions, which is computationally
/// distinct from simple tree-to-tree comparisons.
///
/// # How it works
/// Implementors will analyze the history of a given path and return a sequence
/// of [`BlameEntry`](blame::BlameEntry) items, mapping line ranges to commits.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::blame;
/// // The blame submodule is accessible.
/// ```
/// Configuration store trait.
///
/// # Why this exists
/// Abstracts the reading and writing of repository configuration (e.g., `.git/config`).
/// Decoupling this allows the core engine to query settings (like user name or
/// signing keys) without being tied to a specific file format or key-value backend.
///
/// # How it works
/// Defines a key-value interface segmented by sections, enabling persistent
/// configuration management across different storage mediums.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::config;
/// // The config submodule is accessible.
/// ```
/// Object decoder trait.
///
/// # Why this exists
/// Defines the contract for deserializing raw bytes into strongly-typed Git objects
/// (e.g., [`Blob`](crate::Blob), [`Tree`](crate::Tree)). This abstraction allows
/// the engine to support multiple wire formats or compression algorithms.
///
/// # How it works
/// Implementors read from a generic `std::io::Read` source, parse the headers
/// and payloads, and construct the corresponding domain types, enforcing structural
/// validity during the process.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::decoder;
/// // The decoder submodule is accessible.
/// ```
/// Tree differencing trait.
///
/// # Why this exists
/// Provides the contract for computing the delta between two tree objects.
/// Separating this logic allows for different diffing algorithms (e.g., Myers,
/// patience) to be plugged in without modifying the core comparison logic.
///
/// # How it works
/// Accepts two tree identifiers and returns a [`TreeDelta`](crate::TreeDelta),
/// enumerating all added, deleted, or modified entries between the two states.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::diff;
/// // The diff submodule is accessible.
/// ```
/// Object encoder trait.
///
/// # Why this exists
/// Defines the contract for serializing strongly-typed Git objects into raw bytes.
/// This is the inverse of the [`decoder`] module, ensuring that objects can be
/// written to disk or transmitted over the network in a standardized format.
///
/// # How it works
/// Implementors write the canonical Git representation of the object to a generic
/// `std::io::Write` destination, handling headers and payload formatting.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::encoder;
/// // The encoder submodule is accessible.
/// ```
/// Hashing trait.
///
/// # Why this exists
/// Abstracts the cryptographic hashing mechanism. While Git traditionally uses
/// SHA-1 or SHA-256, this trait allows the engine to support arbitrary hash
/// functions or custom hashing contexts.
///
/// # How it works
/// Reads data from a generic `std::io::Read` source and computes the final
/// [`Hash`](crate::Hash) digest, ensuring that the object's content matches its
/// identifier.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::hasher;
/// // The hasher submodule is accessible.
/// ```
/// Index (staging area) trait.
///
/// # Why this exists
/// Defines the contract for managing the staging area between the working directory
/// and the object database. This abstraction is crucial for orchestrating commits
/// and tracking file states.
///
/// # How it works
/// Provides methods to add, remove, and query entries by path, and to serialize
/// the staged state into a tree object ready for committing.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::index;
/// // The index submodule is accessible.
/// ```
/// Object storage trait.
///
/// # Why this exists
/// Provides the fundamental contract for storing and retrieving content-addressed
/// objects. This is the backbone of the version control system, allowing backends
/// to use plain directories, packed files, or databases.
///
/// # How it works
/// Defines `put`, `get`, `delete`, and `exists` operations keyed by [`Hash`](crate::Hash),
/// ensuring that object retrieval is opaque to the caller.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::object_store;
/// // The object_store submodule is accessible.
/// ```
/// Pack file reader/writer traits.
///
/// # Why this exists
/// Packfiles are Git's compressed archive format for objects. This module defines
/// contracts for both writing and reading packfiles, isolating the complex
/// delta-compression and indexing logic from the standard object store.
///
/// # How it works
/// The writer trait handles object insertion and finalization, while the reader
/// trait provides random access to objects within the pack via their identifiers.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::pack;
/// // The pack submodule is accessible.
/// ```
/// Reference store trait.
///
/// # Why this exists
/// Abstracts the management of symbolic references (branches, tags, HEAD).
/// Decoupling this allows the engine to manage mutable state independently of
/// the immutable object database.
///
/// # How it works
/// Defines operations to set, get, delete, and list references, mapping human-readable
/// names to [`Hash`](crate::Hash) values.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::ref_store;
/// // The ref_store submodule is accessible.
/// ```
/// Reflog store trait.
///
/// # Why this exists
/// Provides the contract for recording the history of reference updates.
/// Reflogs are essential for recovering from mistakes and tracking branch movement.
///
/// # How it works
/// Appends timestamped entries to a reference's log and retrieves them, ensuring
/// that the chronological history of repository mutations is preserved.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::reflog;
/// // The reflog submodule is accessible.
/// ```
/// Remote repository trait.
///
/// # Why this exists
/// Defines the contract for interacting with remote repositories.
/// This abstraction normalizes operations like fetching and pushing across
/// different protocols (e.g., HTTP, SSH, Git).
///
/// # How it works
/// Manages refspecs and remote references, coordinating the transfer of objects
/// and updates between local and remote states.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::remote;
/// // The remote submodule is accessible.
/// ```
/// Revision walking trait.
///
/// # Why this exists
/// Provides the contract for traversing the commit graph.
/// Walking history is a fundamental operation for log generation, bisecting,
/// and ancestry queries.
///
/// # How it works
/// Returns a lazy iterator over commit identifiers starting from a given point,
/// allowing efficient traversal without loading the entire graph into memory.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::revwalk;
/// // The revwalk submodule is accessible.
/// ```
/// Signing trait.
///
/// # Why this exists
/// Abstracts the cryptographic signing of data (e.g., commits or tags).
/// This allows the engine to support various signing backends (GPG, SSH, X.509)
/// without hardcoding the cryptographic primitives.
///
/// # How it works
/// Accepts a key identifier and raw data, returning a cryptographic signature
/// that can be appended to the object.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::signer;
/// // The signer submodule is accessible.
/// ```
/// Transport trait.
///
/// # Why this exists
/// Defines the low-level contract for sending and receiving raw Git objects
/// over a network. This is distinct from the [`remote`] module, which handles
/// higher-level repository semantics.
///
/// # How it works
/// Provides simple fetch and push primitives based on object hashes, acting as
/// the pipe between local and remote object stores.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::transport;
/// // The transport submodule is accessible.
/// ```
/// Verification trait.
///
/// # Why this exists
/// Abstracts the verification of cryptographic signatures. It is the counterpart
/// to the [`signer`] module, ensuring that objects can be authenticated against
/// trusted keys.
///
/// # How it works
/// Accepts a key identifier, raw data, and a signature, returning a boolean
/// indicating the validity of the signature.
///
/// # Examples
///
/// ```
/// # use libvctrl_handler::traits::core::verifier;
/// // The verifier submodule is accessible.
/// ```