MCPcopy Create free account
hub / github.com/alibaba/open-code-review / resolveCommit

Method resolveCommit

internal/diff/git.go:494–500  ·  view source on GitHub ↗

resolveCommit returns the immutable commit SHA a ref points at, or "" when the ref does not resolve to a commit (e.g. an unborn HEAD, or a bad ref). The ^{commit} peel collapses a tag or tree ref to its commit; --verify --quiet makes an unresolvable ref exit non-zero silently rather than printing an

(ctx context.Context, ref string)

Source from the content-addressed store, hash-verified

492// ^{commit} peel collapses a tag or tree ref to its commit; --verify --quiet
493// makes an unresolvable ref exit non-zero silently rather than printing an error.
494func (p *Provider) resolveCommit(ctx context.Context, ref string) string {
495 out, err := p.runGit(ctx, "rev-parse", "--verify", "--quiet", "--end-of-options", ref+"^{commit}")
496 if err != nil {
497 return ""
498 }
499 return firstLine(out)
500}
501
502// commitParents returns the parent commit SHAs of ref: zero for a root commit,
503// one for an ordinary commit, and 2+ for a merge. It uses `rev-list --parents -n

Callers 1

ResolveInputMethod · 0.95

Calls 2

runGitMethod · 0.95
firstLineFunction · 0.85

Tested by

no test coverage detected