MCPcopy Create free account
hub / github.com/cwarden/git-add--interactive / parseHunks

Method parseHunks

internal/git/patch.go:175–217  ·  view source on GitHub ↗
(diffLines, coloredLines []string)

Source from the content-addressed store, hash-verified

173}
174
175func (r *Repository) parseHunks(diffLines, coloredLines []string) ([]Hunk, error) {
176 var hunks []Hunk
177 currentHunk := Hunk{
178 Type: HunkTypeHeader,
179 Text: []string{},
180 Display: []string{},
181 }
182
183 for i, line := range diffLines {
184 displayLine := line
185 if i < len(coloredLines) {
186 displayLine = coloredLines[i]
187 }
188
189 if strings.HasPrefix(line, "@@ ") {
190 if len(currentHunk.Text) > 0 {
191 hunks = append(hunks, currentHunk)
192 }
193 currentHunk = Hunk{
194 Type: HunkTypeHunk,
195 Text: []string{},
196 Display: []string{},
197 }
198 }
199
200 currentHunk.Text = append(currentHunk.Text, line)
201 currentHunk.Display = append(currentHunk.Display, displayLine)
202 }
203
204 if len(currentHunk.Text) > 0 {
205 hunks = append(hunks, currentHunk)
206 }
207
208 for i := range hunks {
209 if hunks[i].Type == HunkTypeHunk && len(hunks[i].Text) > 0 {
210 if err := r.parseHunkHeader(&hunks[i]); err != nil {
211 return nil, err
212 }
213 }
214 }
215
216 return hunks, nil
217}
218
219func (r *Repository) parseHunkHeader(hunk *Hunk) error {
220 if len(hunk.Text) == 0 {

Callers 2

TestParseHunksFunction · 0.95
ParseDiffMethod · 0.95

Calls 1

parseHunkHeaderMethod · 0.95

Tested by 1

TestParseHunksFunction · 0.76