(i int, op Operation)
| 226 | } |
| 227 | |
| 228 | func (g *hunksGenerator) processHunk(i int, op Operation) { |
| 229 | if g.current != nil { |
| 230 | return |
| 231 | } |
| 232 | |
| 233 | var ctxPrefix string |
| 234 | linesBefore := len(g.beforeContext) |
| 235 | if linesBefore > g.ctxLines { |
| 236 | ctxPrefix = g.beforeContext[linesBefore-g.ctxLines-1] |
| 237 | g.beforeContext = g.beforeContext[linesBefore-g.ctxLines:] |
| 238 | linesBefore = g.ctxLines |
| 239 | } |
| 240 | |
| 241 | g.current = &hunk{ctxPrefix: strings.TrimSuffix(ctxPrefix, "\n")} |
| 242 | g.current.AddOp(Equal, g.beforeContext...) |
| 243 | |
| 244 | switch op { |
| 245 | case Delete: |
| 246 | g.current.fromLine, g.current.toLine = |
| 247 | g.addLineNumbers(g.fromLine, g.toLine, linesBefore, i, Add) |
| 248 | case Add: |
| 249 | g.current.toLine, g.current.fromLine = |
| 250 | g.addLineNumbers(g.toLine, g.fromLine, linesBefore, i, Delete) |
| 251 | } |
| 252 | |
| 253 | g.beforeContext = nil |
| 254 | } |
| 255 | |
| 256 | // addLineNumbers obtains the line numbers in a new chunk. |
| 257 | func (g *hunksGenerator) addLineNumbers(la, lb int, linesBefore int, i int, op Operation) (cla, clb int) { |
no test coverage detected