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

Function parseDiffHeaderLine

internal/diff/parser.go:61–71  ·  view source on GitHub ↗

parseDiffHeaderLine extracts the two pathnames from a "diff --git" line, preferring the split a bare header names twice and falling back to parseQuotedDiffHeader when git has quoted a side (see there). The two sides are separated by the same " b/" a pathname can contain, and git does not quote a sp

(line string)

Source from the content-addressed store, hash-verified

59// operands agree. Renames and copies can also admit an equal split, so their
60// extended headers remain authoritative over these provisional paths.
61func parseDiffHeaderLine(line string) (oldPath string, newPath string, ok bool) {
62 if rest, isHeader := strings.CutPrefix(line, "diff --git "); isHeader {
63 if sameOld, sameNew, ok := splitSamePathHeader(rest); ok {
64 return sameOld, sameNew, true
65 }
66 }
67 if m := diffHeaderRe.FindStringSubmatch(line); m != nil {
68 return m[1], m[2], true
69 }
70 return parseQuotedDiffHeader(line)
71}
72
73// splitSamePathHeader reports the split of a bare operand pair whose two sides
74// are the same pathname, which is the shape git writes for every header that is

Callers 2

ParseDiffTextFunction · 0.85

Calls 2

splitSamePathHeaderFunction · 0.85
parseQuotedDiffHeaderFunction · 0.85