Expand description
Parse and encode Git LFS pointer files.
A pointer is a small UTF-8 text file that stands in for a large file in a git repository. It carries the file’s SHA-256 OID, its size, and an optional list of extension records. This crate handles parsing and encoding of that format, with no I/O, no network, and no git dependency.
The format is a sorted sequence of key value lines: the
version URL always first, then optional extension records
sorted by single-digit priority, then the oid and size
lines. The whole file must be under 1024 bytes (see
docs/spec.md for the full grammar).
Pointer::parse is permissive (CRLF line endings, trailing
whitespace, unsorted extensions, and older version URLs all
parse cleanly), while Pointer::encode always emits the
canonical form. Each parsed pointer carries a canonical flag
so callers like the smudge filter can pass the original bytes
through verbatim when they already match; re-encoding a
non-canonical pointer would change its git blob hash.
Parse errors split into DecodeError::NotAPointer (input
bears no LFS markers; callers should treat the bytes as opaque
content) and DecodeError::Malformed (input has pointer
shape but invalid contents; callers should surface the error).
DecodeError::is_not_a_pointer is the predicate test.
use git_lfs_pointer::{Oid, Pointer};
let oid: Oid = "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393"
.parse()
.unwrap();
let pointer = Pointer::new(oid, 12345);
let encoded = pointer.encode();
let parsed = Pointer::parse(encoded.as_bytes()).unwrap();
assert_eq!(parsed.oid, oid);
assert_eq!(parsed.size, 12345);
assert!(parsed.canonical);Structs§
Enums§
- Decode
Error - Why a
Pointer::parsecall failed. - Malformed
Reason - Specific reason a
DecodeError::Malformedwas returned. - NotA
Pointer Reason - Specific reason a
DecodeError::NotAPointerwas returned. - OidParse
Error - Why
Oid::from_hex(orOid::from_str) failed.
Constants§
- EMPTY_
HEX - Hex form of the SHA-256 of the empty input.
- MAX_
POINTER_ SIZE - Hard cap on pointer file size.
- VERSION_
LATEST - The version URL we always emit. Older aliases parse but re-encode to this.