From 3d6f32bbd8670785377a8f2dddb61605e4322d4c Mon Sep 17 00:00:00 2001 From: Vlad Date: Wed, 23 Jan 2019 16:34:20 +0400 Subject: [PATCH 1/2] swarm/version: commit version added --- swarm/network/kademlia.go | 4 ++++ swarm/version/version.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index f9b38fc48d07..626085ab000e 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/swarm/log" "github.com/ethereum/go-ethereum/swarm/pot" + sv "github.com/ethereum/go-ethereum/swarm/version" ) /* @@ -552,6 +553,9 @@ func (k *Kademlia) string() string { var rows []string rows = append(rows, "=========================================================================") + if len(sv.GitCommit) > 0 { + rows = append(rows, fmt.Sprintf("commit hash: %s", sv.GitCommit)) + } rows = append(rows, fmt.Sprintf("%v KΛÐΞMLIΛ hive: queen's address: %x", time.Now().UTC().Format(time.UnixDate), k.BaseAddr()[:3])) rows = append(rows, fmt.Sprintf("population: %d (%d), NeighbourhoodSize: %d, MinBinSize: %d, MaxBinSize: %d", k.conns.Size(), k.addrs.Size(), k.NeighbourhoodSize, k.MinBinSize, k.MaxBinSize)) diff --git a/swarm/version/version.go b/swarm/version/version.go index fb4c531110c7..15adf13fb908 100644 --- a/swarm/version/version.go +++ b/swarm/version/version.go @@ -41,6 +41,10 @@ var VersionWithMeta = func() string { return v }() +// this variable will be assigned if corresponding parameter is passed with install, but not with test +// e.g.: go install -ldflags "-X main.gitCommit=ed1312d01b19e04ef578946226e5d8069d5dfd5a" ./cmd/swarm +var GitCommit string + // ArchiveVersion holds the textual version string used for Swarm archives. // e.g. "0.3.0-dea1ce05" for stable releases, or // "0.3.1-unstable-21c059b6" for unstable releases @@ -51,6 +55,7 @@ func ArchiveVersion(gitCommit string) string { } if len(gitCommit) >= 8 { vsn += "-" + gitCommit[:8] + GitCommit = gitCommit[:8] } return vsn } @@ -59,6 +64,7 @@ func VersionWithCommit(gitCommit string) string { vsn := Version if len(gitCommit) >= 8 { vsn += "-" + gitCommit[:8] + GitCommit = gitCommit[:8] } return vsn } From 652395195d3f49d5c60e29f637faf48d0092ba72 Mon Sep 17 00:00:00 2001 From: Vlad Date: Wed, 23 Jan 2019 18:52:33 +0400 Subject: [PATCH 2/2] swarm/version: fixed gitCommit variable --- cmd/swarm/main.go | 8 +++++--- swarm/version/version.go | 5 +---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index ccbb24eec37b..dbb4201eca10 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -66,9 +66,10 @@ OPTIONS: {{end}}{{end}} ` -var ( - gitCommit string // Git SHA1 commit hash of the release (set via linker flags) -) +// Git SHA1 commit hash of the release (set via linker flags) +// this variable will be assigned if corresponding parameter is passed with install, but not with test +// e.g.: go install -ldflags "-X main.gitCommit=ed1312d01b19e04ef578946226e5d8069d5dfd5a" ./cmd/swarm +var gitCommit string //declare a few constant error messages, useful for later error check comparisons in test var ( @@ -89,6 +90,7 @@ var defaultNodeConfig = node.DefaultConfig // This init function sets defaults so cmd/swarm can run alongside geth. func init() { + sv.GitCommit = gitCommit defaultNodeConfig.Name = clientIdentifier defaultNodeConfig.Version = sv.VersionWithCommit(gitCommit) defaultNodeConfig.P2P.ListenAddr = ":30399" diff --git a/swarm/version/version.go b/swarm/version/version.go index 15adf13fb908..9c724811041e 100644 --- a/swarm/version/version.go +++ b/swarm/version/version.go @@ -41,8 +41,7 @@ var VersionWithMeta = func() string { return v }() -// this variable will be assigned if corresponding parameter is passed with install, but not with test -// e.g.: go install -ldflags "-X main.gitCommit=ed1312d01b19e04ef578946226e5d8069d5dfd5a" ./cmd/swarm +// Git SHA1 commit hash of the release, will be set by main.init() function var GitCommit string // ArchiveVersion holds the textual version string used for Swarm archives. @@ -55,7 +54,6 @@ func ArchiveVersion(gitCommit string) string { } if len(gitCommit) >= 8 { vsn += "-" + gitCommit[:8] - GitCommit = gitCommit[:8] } return vsn } @@ -64,7 +62,6 @@ func VersionWithCommit(gitCommit string) string { vsn := Version if len(gitCommit) >= 8 { vsn += "-" + gitCommit[:8] - GitCommit = gitCommit[:8] } return vsn }