MCPcopy Create free account
hub / github.com/jesseduffield/lazygit / transformHunkHeader

Method transformHunkHeader

pkg/commands/patch/transform.go:207–227  ·  view source on GitHub ↗
(newBodyLines []*PatchLine, oldStart int, startOffset int)

Source from the content-addressed store, hash-verified

205}
206
207func (self *patchTransformer) transformHunkHeader(newBodyLines []*PatchLine, oldStart int, startOffset int) (int, int) {
208 oldLength := nLinesWithKind(newBodyLines, []PatchLineKind{CONTEXT, DELETION})
209 newLength := nLinesWithKind(newBodyLines, []PatchLineKind{CONTEXT, ADDITION})
210
211 var newStartOffset int
212 // if the hunk went from zero to positive length, we need to increment the starting point by one
213 // if the hunk went from positive to zero length, we need to decrement the starting point by one
214 if oldLength == 0 {
215 newStartOffset = 1
216 } else if newLength == 0 {
217 newStartOffset = -1
218 } else {
219 newStartOffset = 0
220 }
221
222 newStart := oldStart + startOffset + newStartOffset
223
224 newStartOffset = startOffset + newLength - oldLength
225
226 return newStart, newStartOffset
227}

Callers 1

transformHunkMethod · 0.95

Calls 1

nLinesWithKindFunction · 0.85

Tested by

no test coverage detected