mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 21:05:48 +02:00
initial support for staging individual lines
This commit is contained in:
parent
99824c8a7b
commit
658e5a9faf
12 changed files with 339 additions and 9 deletions
35
pkg/git/patch_parser.go
Normal file
35
pkg/git/patch_parser.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type PatchParser struct {
|
||||
Log *logrus.Entry
|
||||
}
|
||||
|
||||
// NewPatchParser builds a new branch list builder
|
||||
func NewPatchParser(log *logrus.Entry) (*PatchParser, error) {
|
||||
return &PatchParser{
|
||||
Log: log,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *PatchParser) ParsePatch(patch string) ([]int, []int, error) {
|
||||
lines := strings.Split(patch, "\n")
|
||||
hunkStarts := []int{}
|
||||
stageableLines := []int{}
|
||||
headerLength := 4
|
||||
for offsetIndex, line := range lines[headerLength:] {
|
||||
index := offsetIndex + headerLength
|
||||
if strings.HasPrefix(line, "@@") {
|
||||
hunkStarts = append(hunkStarts, index)
|
||||
}
|
||||
if strings.HasPrefix(line, "-") || strings.HasPrefix(line, "+") {
|
||||
stageableLines = append(stageableLines, index)
|
||||
}
|
||||
}
|
||||
return hunkStarts, stageableLines, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue