summaryrefslogtreecommitdiffstats
path: root/pkg/commands/patch_manager.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/commands/patch_manager.go')
-rw-r--r--pkg/commands/patch_manager.go32
1 files changed, 22 insertions, 10 deletions
diff --git a/pkg/commands/patch_manager.go b/pkg/commands/patch_manager.go
index 1c747c33d..4abf737a0 100644
--- a/pkg/commands/patch_manager.go
+++ b/pkg/commands/patch_manager.go
@@ -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
+}