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

Function matchConsecutive

internal/diff/resolver.go:151–168  ·  view source on GitHub ↗

matchConsecutive scans sideLines for a consecutive run matching all targetLines.

(sideLines []indexedLine, targetLines []string)

Source from the content-addressed store, hash-verified

149
150// matchConsecutive scans sideLines for a consecutive run matching all targetLines.
151func matchConsecutive(sideLines []indexedLine, targetLines []string) (startLine, endLine int, found bool) {
152 if len(targetLines) == 0 || len(sideLines) < len(targetLines) {
153 return 0, 0, false
154 }
155 for i := 0; i <= len(sideLines)-len(targetLines); i++ {
156 matched := true
157 for j, target := range targetLines {
158 if sideLines[i+j].content != target {
159 matched = false
160 break
161 }
162 }
163 if matched {
164 return sideLines[i].lineNum, sideLines[i+len(targetLines)-1].lineNum, true
165 }
166 }
167 return 0, 0, false
168}
169
170// resolveFromFileContent scans the new file content line-by-line for consecutive
171// matches of the normalized existing_code.

Calls

no outgoing calls