ParseDiffText splits the unified diff text into per-file Diff structs. ref, if non-empty, is a git ref used to read new-file content via git show instead of reading from the working tree. runner, if non-nil, is used to execute git subprocesses through a shared concurrency limiter.
(ctx context.Context, diffText string, repoDir string, ref string, runner *gitcmd.Runner)
| 96 | // runner, if non-nil, is used to execute git subprocesses through a |
| 97 | // shared concurrency limiter. |
| 98 | func ParseDiffText(ctx context.Context, diffText string, repoDir string, ref string, runner *gitcmd.Runner) ([]model.Diff, error) { |
| 99 | ctx, cancel := context.WithTimeout(ctx, 2*time.Minute) |
| 100 | defer cancel() |
| 101 | diffs := ParsePatch(diffText) |
| 102 | for index := range diffs { |
| 103 | finalizeDiff(ctx, &diffs[index], repoDir, ref, runner) |
| 104 | } |
| 105 | return diffs, nil |
| 106 | } |
| 107 | |
| 108 | func ParsePatch(diffText string) []model.Diff { |
| 109 | lines := splitDiffLines(diffText) |