| Crates.io | git-internal |
| lib.rs | git-internal |
| version | 0.4.1 |
| created_at | 2025-09-27 13:42:32.092406+00 |
| updated_at | 2026-01-15 17:22:30.849389+00 |
| description | Git-Internal is a high-performance Rust library for encoding and decoding Git internal objects and Pack files. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1857316 |
| size | 1,220,918 |
Git-Internal is a high-performance Rust library for encoding and decoding Git internal objects and Pack files. It provides comprehensive support for Git's internal object storage format with advanced features like delta compression, memory management, and concurrent processing.
This module is designed to handle Git internal objects and Pack files efficiently, supporting both reading and writing operations with optimized memory usage and multi-threaded processing capabilities. The library implements the complete Git Pack format specification with additional optimizations for large-scale Git operations.
Decode a pack (offline):
use std::{fs::File, io::BufReader};
use git_internal::internal::pack::Pack;
use git_internal::hash::{set_hash_kind, HashKind};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// In production, hash kind is configured at the repository level. Set here for demonstration only.
set_hash_kind(HashKind::Sha1);
let f = File::open("tests/data/packs/small-sha1.pack")?;
let mut reader = BufReader::new(f);
let mut pack = Pack::new(None, Some(64 * 1024 * 1024), None, true);
pack.decode(&mut reader, |_entry| {
// Process each decoded object here (MetaAttached<Entry, EntryMeta>).
// For example, index it, persist it, or feed it into your build pipeline.
}, None::<fn(git_internal::hash::ObjectHash)>)?;
Ok(())
}
hash.rs: object IDs and hash algorithm selection (thread-local), set once by your app.internal/object / internal/index / internal/metadata: object parse/serialize, .git/index IO, path/offset/CRC metadata.delta / zstdelta / diff.rs: delta compression, zstd dictionary delta, line-level diff.internal/pack: pack decode/encode, waitlist, cache, idx building.protocol/*: smart protocol + HTTP/SSH adapters, wrapping info-refs/upload-pack/receive-pack.Input Stream → Header Parsing → Object Decoding → Delta Resolution → Cache Storage → Output
↓ ↓ ↓ ↓
Validation Decompression Waitlist Mgmt Memory Mgmt
[!TIP] Here are some performance tips that you can use to significantly improve performance when using
git-internalcrates as a dependency.
In certain versions of Rust, using HashMap on Windows can lead to performance issues. This is due to the allocation strategy of the internal heap memory allocator. To mitigate these performance issues on Windows, you can use mimalloc. (See this issue for more details.)
On other platforms, you can also experiment with jemalloc or mimalloc to potentially improve performance.
A simple approach:
Change Cargo.toml to use mimalloc on Windows and jemalloc on other platforms.
[target.'cfg(not(windows))'.dependencies]
jemallocator = "0.5.4"
[target.'cfg(windows)'.dependencies]
mimalloc = "0.1.43"
Add #[global_allocator] to the main.rs file of the program to specify the allocator.
#[cfg(not(target_os = "windows"))]
#[global_allocator]
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
#[cfg(target_os = "windows")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
TODO
Before submitting a Pull Request, please ensure your code passes the following checks:
# Run clippy with all warnings treated as errors (warnings will be treated as errors)
cargo clippy --all-targets --all-features -- -D warnings
# Check code formatting (requires nightly toolchain)
cargo +nightly fmt --all --check
Both commands must complete without any warnings. The clippy check treats all warnings as errors, and the formatter check ensures code follows the project style guide. Only PRs that pass these checks will be accepted for merge.
If the formatting check fails, you can automatically fix formatting issues by running:
cargo +nightly fmt --all
This project builds with Buck2. Please install both Buck2 and cargo-buckal before development:
# Install buck2: download the latest release tarball from
# https://github.com/facebook/buck2/releases, extract the binary,
# and place it in ~/.cargo/bin (ensure ~/.cargo/bin is on PATH).
# Example (replace <tag> and <platform> with the latest for your OS):
wget https://github.com/facebook/buck2/releases/download/<tag>/buck2-<platform>.tar.gz
tar -xzf buck2-<platform>.tar.gz
mv buck2 ~/.cargo/bin/
# Install cargo-buckal (requires Rust toolchain)
cargo install --git https://github.com/buck2hub/cargo-buckal.git
Pull Requests must also pass the Buck2 build:
cargo buckal build
When you update dependencies in Cargo.toml, regenerate Buck metadata and third-party lockfiles:
cargo buckal migrate