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

Function parseQuotedDiffHeader

internal/diff/quotedpath.go:140–155  ·  view source on GitHub ↗

parseQuotedDiffHeader extracts the old and new paths from a "diff --git" line in which at least one side is quoted, with the "a/" and "b/" prefixes removed. It reports false for a fully unquoted header, which the plain regex still handles.

(line string)

Source from the content-addressed store, hash-verified

138// removed. It reports false for a fully unquoted header, which the plain
139// regex still handles.
140func parseQuotedDiffHeader(line string) (oldPath string, newPath string, ok bool) {
141 rest, ok := strings.CutPrefix(line, "diff --git ")
142 if !ok {
143 return "", "", false
144 }
145 first, second, ok := splitHeaderPaths(rest)
146 if !ok {
147 return "", "", false
148 }
149 oldPath, okOld := strings.CutPrefix(first, "a/")
150 newPath, okNew := strings.CutPrefix(second, "b/")
151 if !okOld || !okNew {
152 return "", "", false
153 }
154 return oldPath, newPath, true
155}
156
157// unquoteRenamePath decodes a "rename from"/"rename to" operand, which git
158// quotes by the same rule and without any a/ or b/ prefix. A path git left

Callers 1

parseDiffHeaderLineFunction · 0.85

Calls 1

splitHeaderPathsFunction · 0.85

Tested by

no test coverage detected