Skip to content

Commit

Permalink
Remove unnecessary SourceRelPaths type
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 15, 2021
1 parent 9fbaba1 commit df0ea51
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/chezmoi/chezmoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var modeTypeNames = map[os.FileMode]string{

type errDuplicateTarget struct {
targetRelPath RelPath
sourceRelPaths SourceRelPaths
sourceRelPaths []SourceRelPath
}

func (e *errDuplicateTarget) Error() string {
Expand Down
7 changes: 0 additions & 7 deletions internal/chezmoi/sourcerelpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ type SourceRelPath struct {
isDir bool
}

// SourceRelPaths is a slice of SourceRelPaths that implements sort.Interface.
type SourceRelPaths []SourceRelPath

func (ps SourceRelPaths) Len() int { return len(ps) }
func (ps SourceRelPaths) Less(i, j int) bool { return string(ps[i].relPath) < string(ps[j].relPath) }
func (ps SourceRelPaths) Swap(i, j int) { ps[i], ps[j] = ps[j], ps[i] }

// NewSourceRelDirPath returns a new SourceRelPath for a directory.
func NewSourceRelDirPath(relPath RelPath) SourceRelPath {
return SourceRelPath{
Expand Down
10 changes: 6 additions & 4 deletions internal/chezmoi/sourcestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (s *SourceState) Add(sourceSystem System, persistentState PersistentState,
type update struct {
destAbsPath AbsPath
entryState *EntryState
sourceRelPaths SourceRelPaths
sourceRelPaths []SourceRelPath
}

destAbsPaths := make([]AbsPath, 0, len(destAbsPathInfos))
Expand Down Expand Up @@ -192,7 +192,7 @@ DESTABSPATH:
update := update{
destAbsPath: destAbsPath,
entryState: entryState,
sourceRelPaths: SourceRelPaths{sourceEntryRelPath},
sourceRelPaths: []SourceRelPath{sourceEntryRelPath},
}

if oldSourceStateEntry, ok := s.entries[targetRelPath]; ok {
Expand Down Expand Up @@ -699,11 +699,13 @@ func (s *SourceState) Read() error {
if len(sourceStateEntries) == 1 {
continue
}
sourceRelPaths := make(SourceRelPaths, 0, len(sourceStateEntries))
sourceRelPaths := make([]SourceRelPath, 0, len(sourceStateEntries))
for _, sourceStateEntry := range sourceStateEntries {
sourceRelPaths = append(sourceRelPaths, sourceStateEntry.SourceRelPath())
}
sort.Sort(sourceRelPaths)
sort.Slice(sourceRelPaths, func(i, j int) bool {
return sourceRelPaths[i].relPath < sourceRelPaths[j].relPath
})
err = multierr.Append(err, &errDuplicateTarget{
targetRelPath: targetRelPath,
sourceRelPaths: sourceRelPaths,
Expand Down

0 comments on commit df0ea51

Please sign in to comment.