(hunk *Hunk)
| 217 | } |
| 218 | |
| 219 | func (r *Repository) parseHunkHeader(hunk *Hunk) error { |
| 220 | if len(hunk.Text) == 0 { |
| 221 | return fmt.Errorf("empty hunk") |
| 222 | } |
| 223 | |
| 224 | hunkHeaderRe := regexp.MustCompile(`^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@`) |
| 225 | matches := hunkHeaderRe.FindStringSubmatch(hunk.Text[0]) |
| 226 | if len(matches) < 4 { |
| 227 | return fmt.Errorf("invalid hunk header: %s", hunk.Text[0]) |
| 228 | } |
| 229 | |
| 230 | oldLine, _ := strconv.Atoi(matches[1]) |
| 231 | oldCnt := 1 |
| 232 | if matches[2] != "" { |
| 233 | oldCnt, _ = strconv.Atoi(matches[2]) |
| 234 | } |
| 235 | |
| 236 | newLine, _ := strconv.Atoi(matches[3]) |
| 237 | newCnt := 1 |
| 238 | if matches[4] != "" { |
| 239 | newCnt, _ = strconv.Atoi(matches[4]) |
| 240 | } |
| 241 | |
| 242 | hunk.OldLine = oldLine |
| 243 | hunk.OldCnt = oldCnt |
| 244 | hunk.NewLine = newLine |
| 245 | hunk.NewCnt = newCnt |
| 246 | |
| 247 | return nil |
| 248 | } |
| 249 | |
| 250 | func (r *Repository) ApplyPatch(patch []byte, mode PatchMode) error { |
| 251 | cmd := append(mode.ApplyCmd, "--allow-overlap") |
no outgoing calls