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

Function splitSamePathHeader

internal/diff/parser.go:80–91  ·  view source on GitHub ↗

splitSamePathHeader reports the split of a bare operand pair whose two sides are the same pathname, which is the shape git writes for every header that is not a rename or a copy. rest is the line after "diff --git ". An equal split can only be the separator: at a " b/" inside the pathname of such a

(rest string)

Source from the content-addressed store, hash-verified

78// such a header the two sides differ by an odd number of bytes, so they never
79// match, and the separator is the only split that can.
80func splitSamePathHeader(rest string) (oldPath string, newPath string, ok bool) {
81 for i := 0; i+3 <= len(rest); i++ {
82 if rest[i] != ' ' || rest[i+1] != 'b' || rest[i+2] != '/' {
83 continue
84 }
85 stripped, isOld := strings.CutPrefix(rest[:i], "a/")
86 if newPath = rest[i+3:]; isOld && stripped == newPath {
87 return stripped, newPath, true
88 }
89 }
90 return "", "", false
91}
92
93// ParseDiffText splits the unified diff text into per-file Diff structs.
94// ref, if non-empty, is a git ref used to read new-file content via

Callers 1

parseDiffHeaderLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected