MCPcopy
hub / github.com/go-git/go-git / Generate

Method Generate

plumbing/format/diff/unified_encoder.go:193–226  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

191}
192
193func (g *hunksGenerator) Generate() []*hunk {
194 for i, chunk := range g.chunks {
195 lines := splitLines(chunk.Content())
196 nLines := len(lines)
197
198 switch chunk.Type() {
199 case Equal:
200 g.fromLine += nLines
201 g.toLine += nLines
202 g.processEqualsLines(lines, i)
203 case Delete:
204 if nLines != 0 {
205 g.fromLine++
206 }
207
208 g.processHunk(i, chunk.Type())
209 g.fromLine += nLines - 1
210 g.current.AddOp(chunk.Type(), lines...)
211 case Add:
212 if nLines != 0 {
213 g.toLine++
214 }
215 g.processHunk(i, chunk.Type())
216 g.toLine += nLines - 1
217 g.current.AddOp(chunk.Type(), lines...)
218 }
219
220 if i == len(g.chunks)-1 && g.current != nil {
221 g.hunks = append(g.hunks, g.current)
222 }
223 }
224
225 return g.hunks
226}
227
228func (g *hunksGenerator) processHunk(i int, op Operation) {
229 if g.current != nil {

Callers 1

EncodeMethod · 0.80

Calls 6

processEqualsLinesMethod · 0.95
processHunkMethod · 0.95
splitLinesFunction · 0.85
AddOpMethod · 0.80
ContentMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected