Skip to content

Commit

Permalink
chore: Miscellaneous fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Oct 30, 2021
1 parent 96d7bc4 commit d5398fd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
require (
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/godbus/dbus/v5 v5.0.5 // indirect
github.com/google/gops v0.3.22 // indirect
github.com/google/gops v0.3.22
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/shopspring/decimal v1.3.0 // indirect
github.com/stretchr/objx v0.3.0 // indirect
Expand Down
12 changes: 12 additions & 0 deletions internal/chezmoi/abspath.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ type AbsPath struct {
absPath string
}

// AbsPaths is a slice of RelPaths that implements sort.Interface.
type AbsPaths []AbsPath

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

// NewAbsPath returns a new AbsPath.
func NewAbsPath(absPath string) AbsPath {
return AbsPath{
Expand Down Expand Up @@ -77,6 +84,11 @@ func (p AbsPath) Len() int {
return len(p.absPath)
}

// Less returns if p is less than other.
func (p AbsPath) Less(other AbsPath) bool {
return p.absPath < other.absPath
}

// MarshalText implements encoding.TextMarshaler.MarshalText.
func (p AbsPath) MarshalText() ([]byte, error) {
return []byte(p.absPath), nil
Expand Down
8 changes: 4 additions & 4 deletions internal/chezmoi/relpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type RelPath struct {
// RelPaths is a slice of RelPaths that implements sort.Interface.
type RelPaths []RelPath

func (p RelPaths) Len() int { return len(p) }
func (p RelPaths) Less(i, j int) bool { return p[i].Less(p[j]) }
func (p RelPaths) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (ps RelPaths) Len() int { return len(ps) }
func (ps RelPaths) Less(i, j int) bool { return ps[i].Less(ps[j]) }
func (ps RelPaths) Swap(i, j int) { ps[i], ps[j] = ps[j], ps[i] }

// NewRelPath returns a new RelPath.
func NewRelPath(relPath string) RelPath {
Expand All @@ -31,7 +31,7 @@ func NewRelPath(relPath string) RelPath {
}

// AppendString appends s to p.
func (p *RelPath) AppendString(s string) RelPath {
func (p RelPath) AppendString(s string) RelPath {
return NewRelPath(p.relPath + s)
}

Expand Down
6 changes: 2 additions & 4 deletions internal/chezmoi/sourcestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,11 @@ func (s *SourceState) Add(sourceSystem System, persistentState PersistentState,
sourceRelPaths []SourceRelPath
}

destAbsPaths := make([]AbsPath, 0, len(destAbsPathInfos))
destAbsPaths := make(AbsPaths, 0, len(destAbsPathInfos))
for destAbsPath := range destAbsPathInfos {
destAbsPaths = append(destAbsPaths, destAbsPath)
}
sort.Slice(destAbsPaths, func(i, j int) bool {
return destAbsPaths[i].absPath < destAbsPaths[j].absPath
})
sort.Sort(destAbsPaths)

sourceUpdates := make([]sourceUpdate, 0, len(destAbsPathInfos))
newSourceStateEntries := make(map[SourceRelPath]SourceStateEntry)
Expand Down

0 comments on commit d5398fd

Please sign in to comment.