Skip to main content

commit_ref_spec

Function commit_ref_spec 

Source
pub(crate) async fn commit_ref_spec(
    cwd: &Path,
    sha: &str,
    budget: Duration,
) -> Option<String>
Expand description

Resolve the two-endpoint git diff range for one commit, or None when sha names no commit git can read.

The sha is resolved first, because it is a revision off a wire: the range this builds is handed to git diff as one argv, and an option-shaped sha would be read as an option of the diff’s own - the same gate super::file::resolve_commit applies to the file read, and the same reason. Resolved, it is a commit id, which cannot be a flag.

Uses git rev-list --parents -n 1 <id> (always exits 0, so no spurious non-zero-exit WARN) to detect a parent: <id> <parent…> means a normal commit (<id>^..<id>, first-parent for a merge), a lone <id> means a root commit (diff against the empty tree).