Skip to main content

Module pack

Module pack 

Source
Expand description

Packfiles — git’s compressed, delta-encoded object container.

A packfile (objects/pack/pack-*.pack) stores many objects back-to-back, each as a small type+size header followed by a zlib stream of either the raw object content or a delta against another object (by in-pack offset for OFS_DELTA, or by object id for REF_DELTA). A sibling pack index (*.idx) maps object ids to their byte offset in the pack so objects can be found without scanning.

This module provides:

  • Pack — random access to objects by offset, resolving delta chains (using a caller-supplied resolver for REF_DELTA bases that live outside the pack).
  • PackIndex — parsing and id→offset lookup for the v2 .idx format.
  • PackWriter — serializing objects into a v2 pack and matching .idx.
  • explode_pack — sequentially decoding a received pack (no index needed) into fully-resolved objects, the ingest path for clone/fetch/push.
  • delta — the delta instruction codec.

Delta compression on write (emitting OFS_DELTA/REF_DELTA rather than one zlib stream per object) is a later optimization; the writer is correct and self-contained today.

Modules§

bitmap
Reachability .bitmap writer.
delta
Git delta encoding (used by OFS_DELTA / REF_DELTA packed objects).
ewah
EWAH bitmap compression — the encoding git’s reachability .bitmap uses.

Structs§

Pack
A packfile loaded into memory, addressable by object offset.
PackIndex
A parsed v2 pack index (*.idx): the id→offset map for a Pack.
PackOutput
The result of PackWriter::finish: the two files and their shared name.
PackVerification
The outcome of verify_pack.
PackWriter
Accumulates objects and emits a packfile plus its index.

Functions§

explode_pack
Sequentially decodes every object in a raw packfile, resolving all deltas, and returns the objects with their ids.
explode_pack_prefix
Like explode_pack, but also returns the number of bytes the packfile occupied (its header, entries, and trailing checksum) — so a caller holding several packfiles concatenated back to back (as a packfile-uris fetch yields: the inline pack followed by each downloaded pack) can decode them in sequence, advancing by the returned length. Trailing bytes beyond the checksum are left for the next call.
pack_frame_end
Returns the offset just past the packfile frame that begins at offset (the start of the next entry), without resolving any delta.
verify_pack
Verifies a packfile against its .idx (git verify-pack).

Type Aliases§

ExplodedObject
A fully-resolved object recovered from a packfile: its id, type, and bytes.
ExternalResolver
Resolves a REF_DELTA base object that is not in the current pack — i.e. a callback into the surrounding object database, returning (type, payload).