-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapply_result.go
More file actions
75 lines (64 loc) · 1.81 KB
/
apply_result.go
File metadata and controls
75 lines (64 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package git_diff_parser
import (
"errors"
"fmt"
)
var ErrPatchConflict = errors.New("patch conflict")
// ApplyResult captures the patched content and the type of misses encountered
// while attempting to apply it.
type applyResult struct {
Content []byte
Reject []byte
DirectMisses int
MergeConflicts int
}
type applyOutcome struct {
content []fileLine
conflicts []applyConflict
rejectHead string
}
type applyConflict struct {
offset int
hunk patchHunk
ours []fileLine
theirs []fileLine
}
// applyError reports the aggregate apply outcome.
type applyError struct {
// DirectMisses counts hunks whose preimage could not be located in the
// pristine file during a direct (non-merge) apply. The output content is
// left unchanged for those regions; no conflict markers are emitted.
DirectMisses int
// MergeConflicts counts hunks whose preimage could not be located during
// a merge-mode apply. The output content contains git-style conflict
// markers (<<<<<<<, =======, >>>>>>>) around each affected region.
MergeConflicts int
// ConflictingHunks keeps the legacy count available for callers that still
// reason about conflict hunks rather than the new miss/conflict split.
ConflictingHunks int
}
func (e *applyError) Error() string {
if e == nil {
return "<nil>"
}
if e.MergeConflicts > 0 || e.ConflictingHunks > 0 {
count := e.MergeConflicts
if count == 0 {
count = e.ConflictingHunks
}
if count == 1 {
return "patch conflict in 1 hunk"
}
return fmt.Sprintf("patch conflict in %d hunks", count)
}
if e.DirectMisses > 0 {
if e.DirectMisses == 1 {
return "patch miss in 1 hunk"
}
return fmt.Sprintf("patch miss in %d hunks", e.DirectMisses)
}
return "patch apply failed"
}
func (e *applyError) Is(target error) bool {
return target == ErrPatchConflict
}