Skip to content

Commit 33f0f45

Browse files
gluk256dshulyak
authored andcommitted
swarm/version: commit version added (ethereum#18510)
(cherry picked from commit ad13d2d)
1 parent 72e46df commit 33f0f45

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

cmd/swarm/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ OPTIONS:
6666
{{end}}{{end}}
6767
`
6868

69-
var (
70-
gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
71-
)
69+
// Git SHA1 commit hash of the release (set via linker flags)
70+
// this variable will be assigned if corresponding parameter is passed with install, but not with test
71+
// e.g.: go install -ldflags "-X main.gitCommit=ed1312d01b19e04ef578946226e5d8069d5dfd5a" ./cmd/swarm
72+
var gitCommit string
7273

7374
//declare a few constant error messages, useful for later error check comparisons in test
7475
var (
@@ -89,6 +90,7 @@ var defaultNodeConfig = node.DefaultConfig
8990

9091
// This init function sets defaults so cmd/swarm can run alongside geth.
9192
func init() {
93+
sv.GitCommit = gitCommit
9294
defaultNodeConfig.Name = clientIdentifier
9395
defaultNodeConfig.Version = sv.VersionWithCommit(gitCommit)
9496
defaultNodeConfig.P2P.ListenAddr = ":30399"

swarm/network/kademlia.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/ethereum/go-ethereum/common"
2828
"github.com/ethereum/go-ethereum/swarm/log"
2929
"github.com/ethereum/go-ethereum/swarm/pot"
30+
sv "github.com/ethereum/go-ethereum/swarm/version"
3031
)
3132

3233
/*
@@ -552,6 +553,9 @@ func (k *Kademlia) string() string {
552553
var rows []string
553554

554555
rows = append(rows, "=========================================================================")
556+
if len(sv.GitCommit) > 0 {
557+
rows = append(rows, fmt.Sprintf("commit hash: %s", sv.GitCommit))
558+
}
555559
rows = append(rows, fmt.Sprintf("%v KΛÐΞMLIΛ hive: queen's address: %x", time.Now().UTC().Format(time.UnixDate), k.BaseAddr()[:3]))
556560
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))
557561

swarm/version/version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ var VersionWithMeta = func() string {
4141
return v
4242
}()
4343

44+
// Git SHA1 commit hash of the release, will be set by main.init() function
45+
var GitCommit string
46+
4447
// ArchiveVersion holds the textual version string used for Swarm archives.
4548
// e.g. "0.3.0-dea1ce05" for stable releases, or
4649
// "0.3.1-unstable-21c059b6" for unstable releases

0 commit comments

Comments
 (0)