pub struct PackedRefs { /* private fields */ }Expand description
A one-time, in-memory snapshot of a ref store’s packed-refs file.
Bulk ref operations — notably fetch’s apply phase — resolve and write
thousands of refs back-to-back. Going through resolve_ref / write_ref
for each one re-reads and re-scans the entire packed-refs file on every
call, making the apply O(refs × packed-refs size). On a repository with tens
of thousands of packed refs that dominates the whole fetch even when no
objects are transferred. Loading the file once into this snapshot and using
resolve_ref_cached / write_ref_cached makes the apply linear.
The snapshot reflects packed-refs at load time. write_ref_cached may
update the snapshot in place so later namespace checks in the same apply batch
see loose refs without reloading the file. Otherwise
treat it as read-only: stale packed data only omits refs that were loose on
disk (resolved outside the snapshot) to begin with.
Implementations§
Source§impl PackedRefs
impl PackedRefs
Sourcepub fn load(git_dir: &Path) -> Result<Self>
pub fn load(git_dir: &Path) -> Result<Self>
Load the packed-refs snapshot for the ref store backing git_dir (the
shared common dir for linked worktrees). A missing file yields an empty
snapshot; reftable repositories also yield an empty snapshot.
§Errors
Returns Error::Io if packed-refs exists but cannot be read, or
Error::PackedRefsUnexpectedLine when the file contains lines Git would reject.
Sourcepub fn get(&self, refname: &str) -> Option<ObjectId>
pub fn get(&self, refname: &str) -> Option<ObjectId>
The packed value recorded for refname, if any.
Sourcepub fn has_namespace_conflict(&self, refname: &str) -> bool
pub fn has_namespace_conflict(&self, refname: &str) -> bool
Whether any packed ref name conflicts with refname as a path prefix
(e.g. an existing refs/heads/x blocks creating refs/heads/x/y).
Mirrors the internal packed_ref_namespace_conflict helper against the snapshot.