gix_odb/store_impls/loose/mod.rs
1//! An object database storing each object in a zlib compressed file with its hash in the path
2/// The maximum size that an object header can have. `git2` says 64, and `git` says 32 but also mentions it can be larger.
3const HEADER_MAX_SIZE: usize = 64;
4use std::path::{Path, PathBuf};
5
6use gix_features::fs;
7
8/// A database for reading and writing objects to disk, one file per object.
9#[derive(Clone, PartialEq, Eq)]
10pub struct Store {
11 /// The directory in which objects are stored, containing 256 folders representing the hashes first byte.
12 pub(crate) path: PathBuf,
13 /// The kind of hash we should assume during iteration and when writing new objects.
14 pub(crate) object_hash: gix_hash::Kind,
15}
16
17/// Initialization
18impl Store {
19 /// Initialize the Db with the `objects_directory` containing the hexadecimal first byte subdirectories, which in turn
20 /// contain all loose objects.
21 ///
22 /// In a git repository, this would be `.git/objects`.
23 ///
24 /// The `object_hash` determines which hash to use when writing, finding or iterating objects.
25 pub fn at(objects_directory: impl Into<PathBuf>, object_hash: gix_hash::Kind) -> Store {
26 Store {
27 path: objects_directory.into(),
28 object_hash,
29 }
30 }
31
32 /// Return the path to our `objects` directory.
33 pub fn path(&self) -> &Path {
34 &self.path
35 }
36
37 /// Return the kind of hash we would iterate and write.
38 pub fn object_hash(&self) -> gix_hash::Kind {
39 self.object_hash
40 }
41}
42
43fn hash_path(id: &gix_hash::oid, mut root: PathBuf) -> PathBuf {
44 let mut hex = gix_hash::Kind::hex_buf();
45 let hex = id.hex_to_buf(hex.as_mut());
46 root.push(&hex[..2]);
47 root.push(&hex[2..]);
48 root
49}
50
51///
52pub mod find;
53///
54pub mod iter;
55///
56pub mod verify;
57
58/// The type for an iterator over `Result<gix_hash::ObjectId, Error>)`
59pub struct Iter {
60 inner: fs::walkdir::DirEntryIter,
61 hash_hex_len: usize,
62}
63
64///
65pub mod write;