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

Method commitParents

internal/diff/git.go:512–522  ·  view source on GitHub ↗

commitParents returns the parent commit SHAs of ref: zero for a root commit, one for an ordinary commit, and 2+ for a merge. It uses `rev-list --parents -n 1`, whose single line is " …" — the leading commit token is dropped, the rest are the parents. `rev-list` (unlike `re

(ctx context.Context, ref string)

Source from the content-addressed store, hash-verified

510// looks like an option. An error yields nil so the caller treats it as "no
511// unique base".
512func (p *Provider) commitParents(ctx context.Context, ref string) []string {
513 out, err := p.runGit(ctx, "rev-list", "--parents", "-n", "1", "--end-of-options", ref)
514 if err != nil {
515 return nil
516 }
517 fields := strings.Fields(firstLine(out))
518 if len(fields) <= 1 {
519 return nil // root commit (only the commit itself, no parents) or empty
520 }
521 return fields[1:]
522}
523
524// firstLine returns the first non-empty trimmed line of git output, so a stray
525// trailing newline or an unexpected second line never pollutes a resolved SHA.

Callers 1

ResolveInputMethod · 0.95

Calls 2

runGitMethod · 0.95
firstLineFunction · 0.85

Tested by

no test coverage detected