diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-18 16:30:34 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-18 16:55:09 +1000 |
commit | e73de332a1efcc8f25e5e0f4f9e0a42d7aabb923 (patch) | |
tree | 62ce6b1996894e666940d7b742b54b335d15cf12 /pkg/commands/patch | |
parent | b28b2d05bd26519d61730c6ced0ba61916aeb456 (diff) |
refactor line by line panel
Diffstat (limited to 'pkg/commands/patch')
-rw-r--r-- | pkg/commands/patch/patch_manager.go | 7 | ||||
-rw-r--r-- | pkg/commands/patch/patch_parser.go | 13 |
2 files changed, 7 insertions, 13 deletions
diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_manager.go index 3d6a076e8..6615d831f 100644 --- a/pkg/commands/patch/patch_manager.go +++ b/pkg/commands/patch/patch_manager.go @@ -182,11 +182,8 @@ func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse b if plain { return patch } - parser, err := NewPatchParser(p.Log, patch) - if err != nil { - // swallowing for now - return "" - } + parser := NewPatchParser(p.Log, patch) + // not passing included lines because we don't want to see them in the secondary panel return parser.Render(-1, -1, nil) } diff --git a/pkg/commands/patch/patch_parser.go b/pkg/commands/patch/patch_parser.go index 00eafd995..a5a94964f 100644 --- a/pkg/commands/patch/patch_parser.go +++ b/pkg/commands/patch/patch_parser.go @@ -39,11 +39,8 @@ type PatchParser struct { } // NewPatchParser builds a new branch list builder -func NewPatchParser(log *logrus.Entry, patch string) (*PatchParser, error) { - hunkStarts, stageableLines, patchLines, err := parsePatch(patch) - if err != nil { - return nil, err - } +func NewPatchParser(log *logrus.Entry, patch string) *PatchParser { + hunkStarts, stageableLines, patchLines := parsePatch(patch) patchHunks := GetHunksFromDiff(patch) @@ -53,7 +50,7 @@ func NewPatchParser(log *logrus.Entry, patch string) (*PatchParser, error) { StageableLines: stageableLines, PatchLines: patchLines, PatchHunks: patchHunks, - }, nil + } } // GetHunkContainingLine takes a line index and an offset and finds the hunk @@ -139,7 +136,7 @@ func coloredString(colorAttr color.Attribute, str string, selected bool, include return utils.ColoredStringDirect(str[:1], clIncluded) + utils.ColoredStringDirect(str[1:], cl) } -func parsePatch(patch string) ([]int, []int, []*PatchLine, error) { +func parsePatch(patch string) ([]int, []int, []*PatchLine) { lines := strings.Split(patch, "\n") hunkStarts := []int{} stageableLines := []int{} @@ -185,7 +182,7 @@ func parsePatch(patch string) ([]int, []int, []*PatchLine, error) { } patchLines[index] = &PatchLine{Kind: lineKind, Content: line} } - return hunkStarts, stageableLines, patchLines, nil + return hunkStarts, stageableLines, patchLines } // Render returns the coloured string of the diff with any selected lines highlighted |