1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-21 00:30:00 +02:00

don't let patch manager ever be nil

This commit is contained in:
Jesse Duffield
2019-11-05 18:10:47 +11:00
parent 10fe88a2cf
commit cd3874ffb7
6 changed files with 48 additions and 33 deletions

View File

@ -25,21 +25,23 @@ type PatchManager struct {
}
// NewPatchManager returns a new PatchModifier
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc, commitSha string, diffMap map[string]string) *PatchManager {
infoMap := map[string]*fileInfo{}
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager {
return &PatchManager{
Log: log,
ApplyPatch: applyPatch,
}
}
// NewPatchManager returns a new PatchModifier
func (p *PatchManager) Start(commitSha string, diffMap map[string]string) {
p.CommitSha = commitSha
p.fileInfoMap = map[string]*fileInfo{}
for filename, diff := range diffMap {
infoMap[filename] = &fileInfo{
p.fileInfoMap[filename] = &fileInfo{
mode: UNSELECTED,
diff: diff,
}
}
return &PatchManager{
Log: log,
fileInfoMap: infoMap,
CommitSha: commitSha,
ApplyPatch: applyPatch,
}
}
func (p *PatchManager) AddFile(filename string) {
@ -200,3 +202,13 @@ func (p *PatchManager) ApplyPatches(reverse bool) error {
return nil
}
// clears the patch
func (p *PatchManager) Reset() {
p.CommitSha = ""
p.fileInfoMap = map[string]*fileInfo{}
}
func (p *PatchManager) IsEmpty() bool {
return p != nil && p.CommitSha == "" || len(p.fileInfoMap) == 0
}