mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-17 01:42:45 +02:00
simplify patch modifier interface
This commit is contained in:
@ -23,7 +23,7 @@ type PatchManager struct {
|
|||||||
ApplyPatch applyPatchFunc
|
ApplyPatch applyPatchFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPatchManager returns a new PatchModifier
|
// NewPatchManager returns a new PatchManager
|
||||||
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager {
|
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager {
|
||||||
return &PatchManager{
|
return &PatchManager{
|
||||||
Log: log,
|
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) {
|
func (p *PatchManager) Start(commitSha string, diffMap map[string]string) {
|
||||||
p.CommitSha = commitSha
|
p.CommitSha = commitSha
|
||||||
p.fileInfoMap = map[string]*fileInfo{}
|
p.fileInfoMap = map[string]*fileInfo{}
|
||||||
@ -101,8 +101,7 @@ func (p *PatchManager) RenderPlainPatchForFile(filename string, reverse bool, ke
|
|||||||
return info.diff
|
return info.diff
|
||||||
case PART:
|
case PART:
|
||||||
// generate a new diff with just the selected lines
|
// generate a new diff with just the selected lines
|
||||||
m := NewPatchModifier(p.Log, filename, info.diff)
|
return ModifiedPatchForLines(p.Log, filename, info.diff, info.includedLineIndices, reverse, keepOriginalHeader)
|
||||||
return m.ModifiedPatchForLines(info.includedLineIndices, reverse, keepOriginalHeader)
|
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -258,3 +258,8 @@ func ModifiedPatchForRange(log *logrus.Entry, filename string, diffText string,
|
|||||||
p := NewPatchModifier(log, filename, diffText)
|
p := NewPatchModifier(log, filename, diffText)
|
||||||
return p.ModifiedPatchForRange(firstLineIdx, lastLineIdx, reverse, keepOriginalHeader)
|
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)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user