diff options
Diffstat (limited to 'pkg/commands/patch/patch_line.go')
-rw-r--r-- | pkg/commands/patch/patch_line.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/pkg/commands/patch/patch_line.go b/pkg/commands/patch/patch_line.go new file mode 100644 index 000000000..994d7c4e9 --- /dev/null +++ b/pkg/commands/patch/patch_line.go @@ -0,0 +1,30 @@ +package patch + +import "github.com/samber/lo" + +type PatchLineKind int + +const ( + PATCH_HEADER PatchLineKind = iota + HUNK_HEADER + ADDITION + DELETION + CONTEXT + NEWLINE_MESSAGE +) + +type PatchLine struct { + Kind PatchLineKind + Content string // something like '+ hello' (note the first character is not removed) +} + +func (self *PatchLine) isChange() bool { + return self.Kind == ADDITION || self.Kind == DELETION +} + +// Returns the number of lines in the given slice that have one of the given kinds +func nLinesWithKind(lines []*PatchLine, kinds []PatchLineKind) int { + return lo.CountBy(lines, func(line *PatchLine) bool { + return lo.Contains(kinds, line.Kind) + }) +} |