diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-21 10:23:14 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-30 21:57:00 +1100 |
commit | 1b94462410daa7424f1d050549d4da278da4a02b (patch) | |
tree | 91004f85f88380c69e040d093256e6dfaea78bda /pkg/commands | |
parent | 120bb443febe96dfb72e6f5859df697e5fb27e0a (diff) |
rename some things
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/files.go | 10 | ||||
-rw-r--r-- | pkg/commands/models/status_line.go | 2 | ||||
-rw-r--r-- | pkg/commands/models/status_line_node.go | 50 | ||||
-rw-r--r-- | pkg/commands/models/status_line_node_test.go | 30 |
4 files changed, 46 insertions, 46 deletions
diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 163e006e1..82d3ae244 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -137,12 +137,12 @@ func (c *GitCommand) DiscardAllFileChanges(file *models.File) error { return c.DiscardUnstagedFileChanges(file) } -func (c *GitCommand) DiscardAllDirChanges(node *models.StatusLineNode) error { +func (c *GitCommand) DiscardAllDirChanges(node *models.FileChangeNode) error { // this could be more efficient but we would need to handle all the edge cases return node.ForEachFile(c.DiscardAllFileChanges) } -func (c *GitCommand) DiscardUnstagedDirChanges(node *models.StatusLineNode) error { +func (c *GitCommand) DiscardUnstagedDirChanges(node *models.FileChangeNode) error { if err := c.RemoveUntrackedDirFiles(node); err != nil { return err } @@ -155,9 +155,9 @@ func (c *GitCommand) DiscardUnstagedDirChanges(node *models.StatusLineNode) erro return nil } -func (c *GitCommand) RemoveUntrackedDirFiles(node *models.StatusLineNode) error { +func (c *GitCommand) RemoveUntrackedDirFiles(node *models.FileChangeNode) error { untrackedFilePaths := node.GetPathsMatching( - func(n *models.StatusLineNode) bool { return n.File != nil && !n.File.GetIsTracked() }, + func(n *models.FileChangeNode) bool { return n.File != nil && !n.File.GetIsTracked() }, ) for _, path := range untrackedFilePaths { @@ -188,7 +188,7 @@ func (c *GitCommand) WorktreeFileDiff(file *models.File, plain bool, cached bool return s } -func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IStatusLine, plain bool, cached bool) string { +func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFileChange, plain bool, cached bool) string { cachedArg := "" trackedArg := "--" colorArg := c.colorArg() diff --git a/pkg/commands/models/status_line.go b/pkg/commands/models/status_line.go index 57a54573c..5413b076f 100644 --- a/pkg/commands/models/status_line.go +++ b/pkg/commands/models/status_line.go @@ -1,6 +1,6 @@ package models -type IStatusLine interface { +type IFileChange interface { GetHasUnstagedChanges() bool GetHasStagedChanges() bool GetIsTracked() bool diff --git a/pkg/commands/models/status_line_node.go b/pkg/commands/models/status_line_node.go index 94527ee9f..9e0f241f3 100644 --- a/pkg/commands/models/status_line_node.go +++ b/pkg/commands/models/status_line_node.go @@ -8,14 +8,14 @@ import ( "strings" ) -type StatusLineNode struct { - Children []*StatusLineNode +type FileChangeNode struct { + Children []*FileChangeNode File *File Path string // e.g. '/path/to/mydir' Collapsed bool } -func (s *StatusLineNode) GetHasUnstagedChanges() bool { +func (s *FileChangeNode) GetHasUnstagedChanges() bool { if s.IsLeaf() { return s.File.HasUnstagedChanges } @@ -29,7 +29,7 @@ func (s *StatusLineNode) GetHasUnstagedChanges() bool { return false } -func (s *StatusLineNode) GetHasStagedChanges() bool { +func (s *FileChangeNode) GetHasStagedChanges() bool { if s.IsLeaf() { return s.File.HasStagedChanges } @@ -43,13 +43,13 @@ func (s *StatusLineNode) GetHasStagedChanges() bool { return false } -func (s *StatusLineNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *StatusLineNode { +func (s *FileChangeNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *FileChangeNode { node, _ := s.getNodeAtIndexAux(index, collapsedPaths) return node } -func (s *StatusLineNode) getNodeAtIndexAux(index int, collapsedPaths map[string]bool) (*StatusLineNode, int) { +func (s *FileChangeNode) getNodeAtIndexAux(index int, collapsedPaths map[string]bool) (*FileChangeNode, int) { offset := 1 if index == 0 { @@ -69,11 +69,11 @@ func (s *StatusLineNode) getNodeAtIndexAux(index int, collapsedPaths map[string] return nil, offset } -func (s *StatusLineNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) { +func (s *FileChangeNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) { return s.getIndexForPathAux(path, collapsedPaths) } -func (s *StatusLineNode) getIndexForPathAux(path string, collapsedPaths map[string]bool) (int, bool) { +func (s *FileChangeNode) getIndexForPathAux(path string, collapsedPaths map[string]bool) (int, bool) { offset := 0 if s.Path == path { @@ -93,11 +93,11 @@ func (s *StatusLineNode) getIndexForPathAux(path string, collapsedPaths map[stri return offset, false } -func (s *StatusLineNode) IsLeaf() bool { +func (s *FileChangeNode) IsLeaf() bool { return len(s.Children) == 0 } -func (s *StatusLineNode) Size(collapsedPaths map[string]bool) int { +func (s *FileChangeNode) Size(collapsedPaths map[string]bool) int { output := 1 if !collapsedPaths[s.GetPath()] { @@ -109,8 +109,8 @@ func (s *StatusLineNode) Size(collapsedPaths map[string]bool) int { return output } -func (s *StatusLineNode) Flatten(collapsedPaths map[string]bool) []*StatusLineNode { - arr := []*StatusLineNode{s} +func (s *FileChangeNode) Flatten(collapsedPaths map[string]bool) []*FileChangeNode { + arr := []*FileChangeNode{s} if !collapsedPaths[s.GetPath()] { for _, child := range s.Children { @@ -121,7 +121,7 @@ func (s *StatusLineNode) Flatten(collapsedPaths map[string]bool) []*StatusLineNo return arr } -func (s *StatusLineNode) Sort() { +func (s *FileChangeNode) Sort() { s.sortChildren() for _, child := range s.Children { @@ -129,12 +129,12 @@ func (s *StatusLineNode) Sort() { } } -func (s *StatusLineNode) sortChildren() { +func (s *FileChangeNode) sortChildren() { if s.IsLeaf() { return } - sortedChildren := make([]*StatusLineNode, len(s.Children)) + sortedChildren := make([]*FileChangeNode, len(s.Children)) copy(sortedChildren, s.Children) sort.Slice(sortedChildren, func(i, j int) bool { @@ -153,7 +153,7 @@ func (s *StatusLineNode) sortChildren() { } // returns true if any descendant file is tracked -func (s *StatusLineNode) GetIsTracked() bool { +func (s *FileChangeNode) GetIsTracked() bool { if s.File != nil { return s.File.GetIsTracked() } @@ -167,11 +167,11 @@ func (s *StatusLineNode) GetIsTracked() bool { return false } -func (s *StatusLineNode) GetPath() string { +func (s *FileChangeNode) GetPath() string { return s.Path } -func (s *StatusLineNode) Compress() { +func (s *FileChangeNode) Compress() { if s == nil { return } @@ -179,7 +179,7 @@ func (s *StatusLineNode) Compress() { s.compressAux() } -func (s *StatusLineNode) compressAux() *StatusLineNode { +func (s *FileChangeNode) compressAux() *FileChangeNode { if s.IsLeaf() { return s } @@ -198,12 +198,12 @@ func (s *StatusLineNode) compressAux() *StatusLineNode { return s } -func (s *StatusLineNode) HasExactlyOneChild() bool { +func (s *FileChangeNode) HasExactlyOneChild() bool { return len(s.Children) == 1 } // This ignores the root -func (s *StatusLineNode) GetPathsMatching(test func(*StatusLineNode) bool) []string { +func (s *FileChangeNode) GetPathsMatching(test func(*FileChangeNode) bool) []string { paths := []string{} if test(s) { @@ -217,15 +217,15 @@ func (s *StatusLineNode) GetPathsMatching(test func(*StatusLineNode) bool) []str return paths } -func (s *StatusLineNode) ID() string { +func (s *FileChangeNode) ID() string { return s.GetPath() } -func (s *StatusLineNode) Description() string { +func (s *FileChangeNode) Description() string { return s.GetPath() } -func (s *StatusLineNode) ForEachFile(cb func(*File) error) error { +func (s *FileChangeNode) ForEachFile(cb func(*File) error) error { if s.File != nil { if err := cb(s.File); err != nil { return err @@ -241,7 +241,7 @@ func (s *StatusLineNode) ForEachFile(cb func(*File) error) error { return nil } -func (s *StatusLineNode) NameAtDepth(depth int) string { +func (s *FileChangeNode) NameAtDepth(depth int) string { splitName := strings.Split(s.Path, string(os.PathSeparator)) name := filepath.Join(splitName[depth:]...) diff --git a/pkg/commands/models/status_line_node_test.go b/pkg/commands/models/status_line_node_test.go index 5f0a1a853..0f0f95ce5 100644 --- a/pkg/commands/models/status_line_node_test.go +++ b/pkg/commands/models/status_line_node_test.go @@ -9,8 +9,8 @@ import ( func TestCompress(t *testing.T) { scenarios := []struct { name string - root *StatusLineNode - expected *StatusLineNode + root *FileChangeNode + expected *FileChangeNode }{ { name: "nil node", @@ -19,28 +19,28 @@ func TestCompress(t *testing.T) { }, { name: "leaf node", - root: &StatusLineNode{ + root: &FileChangeNode{ Name: "", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ {File: &File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Name: "test"}, }, }, - expected: &StatusLineNode{ + expected: &FileChangeNode{ Name: "", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ {File: &File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Name: "test"}, }, }, }, { name: "big example", - root: &StatusLineNode{ + root: &FileChangeNode{ Name: "", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { Name: "dir1", Path: "dir1", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { File: &File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, Name: "file2", @@ -51,7 +51,7 @@ func TestCompress(t *testing.T) { { Name: "dir2", Path: "dir2", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { File: &File{Name: "file3", ShortStatus: " M", HasStagedChanges: true}, Name: "file3", @@ -67,11 +67,11 @@ func TestCompress(t *testing.T) { { Name: "dir3", Path: "dir3", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { Name: "dir3-1", Path: "dir3/dir3-1", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { File: &File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true}, Name: "file5", @@ -88,9 +88,9 @@ func TestCompress(t *testing.T) { }, }, }, - expected: &StatusLineNode{ + expected: &FileChangeNode{ Name: "", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { Name: "dir1/file2", File: &File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, @@ -99,7 +99,7 @@ func TestCompress(t *testing.T) { { Name: "dir2", Path: "dir2", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { File: &File{Name: "file3", ShortStatus: " M", HasStagedChanges: true}, Name: "file3", |