summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-09 15:42:20 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-09 15:42:20 +1000
commit23299f88e9c5da84902cc872772333c4ab755946 (patch)
tree1c588ccac8d8ea2517c63d205af942d9ad4d44d7 /pkg/commands
parentef744e45c1e61a7ed5c492676e232e9060121d29 (diff)
simplify patch modifier interface
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/patch_manager.go7
-rw-r--r--pkg/commands/patch_modifier.go5
2 files changed, 8 insertions, 4 deletions
diff --git a/pkg/commands/patch_manager.go b/pkg/commands/patch_manager.go
index 3cd106fbc..6c1b9ced9 100644
--- a/pkg/commands/patch_manager.go
+++ b/pkg/commands/patch_manager.go
@@ -23,7 +23,7 @@ type PatchManager struct {
ApplyPatch applyPatchFunc
}
-// NewPatchManager returns a new PatchModifier
+// NewPatchManager returns a new PatchManager
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager {
return &PatchManager{
Log: log,
@@ -31,7 +31,7 @@ func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager
}
}
-// NewPatchManager returns a new PatchModifier
+// NewPatchManager returns a new PatchManager
func (p *PatchManager) Start(commitSha string, diffMap map[string]string) {
p.CommitSha = commitSha
p.fileInfoMap = map[string]*fileInfo{}
@@ -101,8 +101,7 @@ func (p *PatchManager) RenderPlainPatchForFile(filename string, reverse bool, ke
return info.diff
case PART:
// generate a new diff with just the selected lines
- m := NewPatchModifier(p.Log, filename, info.diff)
- return m.ModifiedPatchForLines(info.includedLineIndices, reverse, keepOriginalHeader)
+ return ModifiedPatchForLines(p.Log, filename, info.diff, info.includedLineIndices, reverse, keepOriginalHeader)
default:
return ""
}
diff --git a/pkg/commands/patch_modifier.go b/pkg/commands/patch_modifier.go
index e407199c0..092814f90 100644
--- a/pkg/commands/patch_modifier.go
+++ b/pkg/commands/patch_modifier.go
@@ -258,3 +258,8 @@ func ModifiedPatchForRange(log *logrus.Entry, filename string, diffText string,
p := NewPatchModifier(log, filename, diffText)
return p.ModifiedPatchForRange(firstLineIdx, lastLineIdx, reverse, keepOriginalHeader)
}
+
+func ModifiedPatchForLines(log *logrus.Entry, filename string, diffText string, includedLineIndices []int, reverse bool, keepOriginalHeader bool) string {
+ p := NewPatchModifier(log, filename, diffText)
+ return p.ModifiedPatchForLines(includedLineIndices, reverse, keepOriginalHeader)
+}