MCPcopy Index your code
hub / github.com/go-git/go-git / processHunk

Method processHunk

plumbing/format/diff/unified_encoder.go:228–254  ·  view source on GitHub ↗
(i int, op Operation)

Source from the content-addressed store, hash-verified

226}
227
228func (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.
257func (g *hunksGenerator) addLineNumbers(la, lb int, linesBefore int, i int, op Operation) (cla, clb int) {

Callers 1

GenerateMethod · 0.95

Calls 2

addLineNumbersMethod · 0.95
AddOpMethod · 0.80

Tested by

no test coverage detected