Skip to content

Commit

Permalink
Merge pull request #17 from havoc-io/go18
Browse files Browse the repository at this point in the history
Update to Go 1.8 features.
  • Loading branch information
xenoscopic committed Feb 24, 2017
2 parents 862915f + ace3017 commit d082508
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 72 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ os:
# version and because we want broader test coverage.
# NOTE: If you change this version, change its value below in deploy as well.
go:
- 1.7.4
- 1.8.x
- tip

# Allow failure on Go tip, we just want to be able to track behavior there.
matrix:
allow_failures:
- go: tip

# Install third-party dependencies.
# Fetch vendored third-party dependencies.
before_install:
- git submodule init
- git submodule update
Expand Down Expand Up @@ -83,8 +83,8 @@ deploy:
- build/mutagen_windows_amd64.zip
on:
repo: havoc-io/mutagen
condition: "$TRAVIS_OS_NAME = osx"
go: 1.7.4
condition: $TRAVIS_OS_NAME = osx
condition: $TRAVIS_GO_VERSION =~ ^1\.8\.[0-9]+$
tags: true

# Send notifications.
Expand Down
33 changes: 14 additions & 19 deletions agent/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,20 @@ func unameSIsWindowsPosix(unameS string) bool {
}

var unameMToGOARCH = map[string]string{
"i386": "386",
"i486": "386",
"i586": "386",
"i686": "386",
"x86_64": "amd64",
"amd64": "amd64",
"armv5l": "arm",
"armv6l": "arm",
"armv7l": "arm",
"armv8l": "arm64",
"aarch64": "arm64",
// TODO: Add support for 32-bit MIPS architectures (both little-endian and
// big-endian) once the ports are released with Go 1.8 and we add the
// corresponding agent builds.
"mips64": "mips64",
// TODO: Verify that mips64el is the correct Linux uname -m output for
// little-endian MIPS64. Note that there is a difference between "el" and
// "le", and that Linux returns "ppc64le" for 64-bit little-endian PowerPC
// machines, so it's a weird inconsistency.
"i386": "386",
"i486": "386",
"i586": "386",
"i686": "386",
"x86_64": "amd64",
"amd64": "amd64",
"armv5l": "arm",
"armv6l": "arm",
"armv7l": "arm",
"armv8l": "arm64",
"aarch64": "arm64",
"mips": "mips",
"mipsel": "mipsle",
"mips64": "mips64",
"mips64el": "mips64le",
"ppc64": "ppc64",
"ppc64le": "ppc64le",
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ init:
# Disable AppVeyor's default Visual Studio build system.
build: off

# Install third-party dependencies.
# Fetch vendored third-party dependencies.
before_test:
- git submodule init
- git submodule update
Expand Down
1 change: 0 additions & 1 deletion cmd/mutagen/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func promptMain(arguments []string) error {
if messageBase64 == "" {
return errors.New("no message specified")
}
// TODO: In Go 1.8, switch to using the Strict variant of this encoding.
messageBytes, err := base64.StdEncoding.DecodeString(messageBase64)
if err != nil {
return errors.New("unable to decode message")
Expand Down
6 changes: 1 addition & 5 deletions filesystem/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,12 @@ func Normalize(path string) (string, error) {
return "", errors.Wrap(err, "unable to perform tilde expansion")
}

// Convert to an absolute path.
// Convert to an absolute path. This will also invoke filepath.Clean.
path, err = filepath.Abs(path)
if err != nil {
return "", errors.Wrap(err, "unable to compute absolute path")
}

// Clean the path.
// TODO: In Go 1.8, filepath.Abs will call clean, so remove this.
path = filepath.Clean(path)

// Success.
return path, nil
}
6 changes: 4 additions & 2 deletions scripts/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ var targets = []Target{
{"linux", "arm64"},
{"linux", "ppc64"},
{"linux", "ppc64le"},
{"linux", "mips"},
{"linux", "mipsle"},
{"linux", "mips64"},
{"linux", "mips64le"},
// TODO: This combination is valid but not listed on the "Installing Go from
// source" page. Perhaps we should open a pull request to change that?
{"linux", "s390x"},
{"netbsd", "386"},
{"netbsd", "amd64"},
Expand All @@ -185,8 +189,6 @@ var targets = []Target{
{"solaris", "amd64"},
{"windows", "386"},
{"windows", "amd64"},
// TODO: Add builds for 32-bit MIPS architectures (both little-endian and
// big-endian) once the ports are released with Go 1.8.
}

// TODO: Figure out if we should set this on a per-machine basis. This value is
Expand Down
23 changes: 6 additions & 17 deletions session/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,6 @@ func (s *Service) create(stream rpc.HandlerStream) error {
return nil
}

// byCreationTime implements the sort interface for SessionState, sorting
// sessions by creation time.
type byCreationTime []SessionState

func (s byCreationTime) Len() int {
return len(s)
}

func (s byCreationTime) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s byCreationTime) Less(i, j int) bool {
return timestamp.Less(s[i].Session.CreationTime, s[j].Session.CreationTime)
}

func (s *Service) list(stream rpc.HandlerStream) error {
// Receive the request.
var request ListRequest
Expand Down Expand Up @@ -214,7 +198,12 @@ func (s *Service) list(stream rpc.HandlerStream) error {
}

// Sort sessions by creation time.
sort.Sort(byCreationTime(sessions))
sort.Slice(sessions, func(i, j int) bool {
return timestamp.Less(
sessions[i].Session.CreationTime,
sessions[j].Session.CreationTime,
)
})

// Send this response.
if err := stream.Send(ListResponse{Sessions: sessions}); err != nil {
Expand Down
19 changes: 3 additions & 16 deletions session/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,6 @@ import (
"github.com/havoc-io/mutagen/sync"
)

// byName provides the sort interface for StableEntryContent, sorting by name.
type byName []*StableEntryContent

func (n byName) Len() int {
return len(n)
}

func (n byName) Swap(i, j int) {
n[i], n[j] = n[j], n[i]
}

func (n byName) Less(i, j int) bool {
return n[i].Name < n[j].Name
}

func stableCopy(entry *sync.Entry) *StableEntry {
// If the entry is nil, then the copy is nil.
if entry == nil {
Expand All @@ -46,7 +31,9 @@ func stableCopy(entry *sync.Entry) *StableEntry {
}

// Sort contents by name.
sort.Sort(byName(result.Contents))
sort.Slice(result.Contents, func(i, j int) bool {
return result.Contents[i].Name < result.Contents[j].Name
})

// Done.
return result
Expand Down
1 change: 0 additions & 1 deletion ssh/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func prompterEnvironment(prompter, message string) []string {
} else {
// Convert message to base64 encoding so that we can pass it through the
// environment safely.
// TODO: In Go 1.8, switch to using the Strict variant of this encoding.
messageBase64 := base64.StdEncoding.EncodeToString([]byte(message))

// Insert necessary environment variables.
Expand Down
8 changes: 2 additions & 6 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.8

package mutagen

import (
Expand All @@ -6,12 +8,6 @@ import (
"io"
)

// TODO: When Go 1.8 is released, add a build constraint requiring it to this
// file. In addition to features we'll use in 1.8, there's also an important fix
// to the compiler in Go 1.7.3 (https://github.com/golang/go/issues/17318) that
// we require for the rsync package. Unfortunately build constraints aren't
// available for minor releases.

const (
// VersionMajor represents the current major version of Mutagen.
VersionMajor = 0
Expand Down

0 comments on commit d082508

Please sign in to comment.