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

Method resolveCommit

internal/diff/git.go:527–533  ·  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

525// ^{commit} peel collapses a tag or tree ref to its commit; --verify --quiet
526// makes an unresolvable ref exit non-zero silently rather than printing an error.
527func (p *Provider) resolveCommit(ctx context.Context, ref string) string {
528 out, err := p.runGit(ctx, "rev-parse", "--verify", "--quiet", "--end-of-options", ref+"^{commit}")
529 if err != nil {
530 return ""
531 }
532 return firstLine(out)
533}
534
535// commitParents returns the parent commit SHAs of ref: zero for a root commit,
536// 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