summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-03-31 22:39:55 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-04-02 11:00:15 +1100
commit54910fdb76f8a699d2cfb96459b75b60485fd3f7 (patch)
treec015840a1338db2976058f080346821d7f6dfc4b /pkg/commands
parent332a3c4cbfd263c34d5f53dd971701d2ca69ab4e (diff)
refactor
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/loading_commit_files.go12
-rw-r--r--pkg/commands/models/commit_file.go3
-rw-r--r--pkg/commands/patch/patch_manager.go30
3 files changed, 21 insertions, 24 deletions
diff --git a/pkg/commands/loading_commit_files.go b/pkg/commands/loading_commit_files.go
index 1b5dc02d4..d0f8406b8 100644
--- a/pkg/commands/loading_commit_files.go
+++ b/pkg/commands/loading_commit_files.go
@@ -4,11 +4,10 @@ import (
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
- "github.com/jesseduffield/lazygit/pkg/commands/patch"
)
// GetFilesInDiff get the specified commit files
-func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool, patchManager *patch.PatchManager) ([]*models.CommitFile, error) {
+func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool) ([]*models.CommitFile, error) {
reverseFlag := ""
if reverse {
reverseFlag = " -R "
@@ -19,11 +18,11 @@ func (c *GitCommand) GetFilesInDiff(from string, to string, reverse bool, patchM
return nil, err
}
- return c.getCommitFilesFromFilenames(filenames, to, patchManager), nil
+ return c.getCommitFilesFromFilenames(filenames), nil
}
// filenames string is something like "file1\nfile2\nfile3"
-func (c *GitCommand) getCommitFilesFromFilenames(filenames string, parent string, patchManager *patch.PatchManager) []*models.CommitFile {
+func (c *GitCommand) getCommitFilesFromFilenames(filenames string) []*models.CommitFile {
commitFiles := make([]*models.CommitFile, 0)
lines := strings.Split(strings.TrimRight(filenames, "\x00"), "\x00")
@@ -32,15 +31,10 @@ func (c *GitCommand) getCommitFilesFromFilenames(filenames string, parent string
// typical result looks like 'A my_file' meaning my_file was added
changeStatus := lines[i]
name := lines[i+1]
- status := patch.UNSELECTED
- if patchManager != nil && patchManager.To == parent {
- status = patchManager.GetFileStatus(name)
- }
commitFiles = append(commitFiles, &models.CommitFile{
Name: name,
ChangeStatus: changeStatus,
- PatchStatus: status,
})
}
diff --git a/pkg/commands/models/commit_file.go b/pkg/commands/models/commit_file.go
index 57a766a46..b6028e221 100644
--- a/pkg/commands/models/commit_file.go
+++ b/pkg/commands/models/commit_file.go
@@ -4,9 +4,6 @@ package models
type CommitFile struct {
Name string
- // PatchStatus tells us whether the file has been wholly or partially added to a patch. We might want to pull this logic up into the gui package and make it a map like we do with cherry picked commits
- PatchStatus int // one of 'WHOLE' 'PART' 'NONE'
-
ChangeStatus string // e.g. 'A' for added or 'M' for modified. This is based on the result from git diff --name-status
}
diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_manager.go
index 2c08da67a..ccb2a1081 100644
--- a/pkg/commands/patch/patch_manager.go
+++ b/pkg/commands/patch/patch_manager.go
@@ -1,7 +1,6 @@
package patch
import (
- "errors"
"sort"
"strings"
@@ -9,9 +8,11 @@ import (
"github.com/sirupsen/logrus"
)
+type PatchStatus int
+
const (
// UNSELECTED is for when the commit file has not been added to the patch in any way
- UNSELECTED = iota
+ UNSELECTED PatchStatus = iota
// WHOLE is for when you want to add the whole diff of a file to the patch,
// including e.g. if it was deleted
WHOLE
@@ -20,7 +21,7 @@ const (
)
type fileInfo struct {
- mode int // one of WHOLE/PART
+ mode PatchStatus
includedLineIndices []int
diff string
}
@@ -81,20 +82,25 @@ func (p *PatchManager) removeFile(info *fileInfo) {
info.includedLineIndices = nil
}
-func (p *PatchManager) ToggleFileWhole(filename string) error {
+func (p *PatchManager) AddFileWhole(filename string) error {
info, err := p.getFileInfo(filename)
if err != nil {
return err
}
- switch info.mode {
- case UNSELECTED, PART:
- p.addFileWhole(info)
- case WHOLE:
- p.removeFile(info)
- default:
- return errors.New("unknown file mode")
+
+ p.addFileWhole(info)
+
+ return nil
+}
+
+func (p *PatchManager) RemoveFile(filename string) error {
+ info, err := p.getFileInfo(filename)
+ if err != nil {
+ return err
}
+ p.removeFile(info)
+
return nil
}
@@ -216,7 +222,7 @@ func (p *PatchManager) RenderAggregatedPatchColored(plain bool) string {
return result
}
-func (p *PatchManager) GetFileStatus(filename string) int {
+func (p *PatchManager) GetFileStatus(filename string) PatchStatus {
info, ok := p.fileInfoMap[filename]
if !ok {
return UNSELECTED