pub struct GitRepo { /* private fields */ }Implementations§
Source§impl GitRepo
impl GitRepo
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open a git repository. path may be the work-tree root (contains .git/)
or the bare .git directory itself.
Sourcepub fn resolve_ref(&self, name: &str) -> Result<GitHash>
pub fn resolve_ref(&self, name: &str) -> Result<GitHash>
Resolve any ref name (e.g. "HEAD", "refs/heads/main", or a bare hex hash).
Sourcepub fn read_object(&self, hash: &GitHash) -> Result<RawObject>
pub fn read_object(&self, hash: &GitHash) -> Result<RawObject>
Read and verify an object by hash, from a loose file or a packfile.
Loose objects are tried first; if absent, every packfile is searched
(resolving OFS_DELTA/REF_DELTA chains). A truly missing object yields
GitError::ObjectNotFound; an unsupported pack index version yields
the distinct GitError::PackfileUnsupported — never a misleading
not-found.
Sourcepub fn read_commit(&self, hash: &GitHash) -> Result<CommitObject>
pub fn read_commit(&self, hash: &GitHash) -> Result<CommitObject>
Read and parse a commit object.
Sourcepub fn read_tree(&self, hash: &GitHash) -> Result<TreeObject>
pub fn read_tree(&self, hash: &GitHash) -> Result<TreeObject>
Read and parse a tree object.
Sourcepub fn read_blob(&self, hash: &GitHash) -> Result<Vec<u8>>
pub fn read_blob(&self, hash: &GitHash) -> Result<Vec<u8>>
Read a blob object and return its raw bytes.
Sourcepub fn walk_commits(
&self,
from: GitHash,
) -> impl Iterator<Item = Result<CommitObject>> + '_
pub fn walk_commits( &self, from: GitHash, ) -> impl Iterator<Item = Result<CommitObject>> + '_
Walk the commit ancestry chain, newest-first (first-parent only).
Sourcepub fn reflog(&self, refname: &str) -> Result<Vec<ReflogEntry>>
pub fn reflog(&self, refname: &str) -> Result<Vec<ReflogEntry>>
Read the reflog for refname (e.g. "HEAD", "refs/heads/main").
Returns an empty vec when the log file is absent (git creates one only after the ref first moves), never an error for mere absence.
§Errors
Propagates a non-NotFound I/O error encountered reading the log file.
Sourcepub fn all_objects(&self) -> Result<Vec<GitHash>>
pub fn all_objects(&self) -> Result<Vec<GitHash>>
Sourcepub fn all_refs(&self) -> Vec<(String, GitHash)>
pub fn all_refs(&self) -> Vec<(String, GitHash)>
Every ref in the repository as (refname, target_hash) pairs (loose
refs/**, packed-refs, and HEAD).
Best-effort: a refs-subsystem I/O failure degrades to fewer refs. Code
that computes reachability from these roots must use Self::all_refs_checked
instead, so a bootstrap failure cannot masquerade as “zero refs”.
Sourcepub fn all_refs_checked(&self) -> Result<Vec<(String, GitHash)>>
pub fn all_refs_checked(&self) -> Result<Vec<(String, GitHash)>>
Like Self::all_refs but surfaces a ref-enumeration I/O failure as an
error instead of silently returning fewer (or zero) refs.
§Errors
GitError::Io if the refs subsystem exists but cannot be enumerated/read.