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

Function matchConsecutive

internal/diff/resolver.go:148–165  ·  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

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

Calls

no outgoing calls