Skip to main content

Crate git_lfs_pointer

Crate git_lfs_pointer 

Source
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§

Extension
A pointer extension.
Oid
A SHA-256 object identifier.
Pointer
A parsed git-lfs pointer.

Enums§

DecodeError
Why a Pointer::parse call failed.
MalformedReason
Specific reason a DecodeError::Malformed was returned.
NotAPointerReason
Specific reason a DecodeError::NotAPointer was returned.
OidParseError
Why Oid::from_hex (or Oid::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.