Skip to content

Commit 0ddcabe

Browse files
authored
Merge pull request #946 from ViktorTigerstrom/2025-05-update-getinfo-response
Update commit_hash field to GetInfo response
2 parents 48a5f46 + 3aaef99 commit 0ddcabe

File tree

7 files changed

+45
-17
lines changed

7 files changed

+45
-17
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ GOBUILD := GO111MODULE=on go build -v
1515
GOINSTALL := GO111MODULE=on go install -v
1616
GOMOD := GO111MODULE=on go mod
1717

18-
COMMIT := $(shell git describe --abbrev=40 --dirty | sed -E 's/.*-g([0-9a-f]{40})(-dirty)?/\1\2/')
19-
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT)"
18+
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
19+
COMMIT_HASH := $(shell git rev-parse HEAD)
20+
DIRTY := $(shell git diff-index --quiet HEAD -- || echo dirty)
21+
LDFLAGS := -ldflags "-X $(PKG).Commit=$(COMMIT) -X $(PKG).CommitHash=$(COMMIT_HASH) -X $(PKG).Dirty=$(DIRTY)"
2022
DEV_TAGS = dev
2123

2224
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -name "*pb.go" -not -name "*pb.gw.go" -not -name "*.pb.json.go")

loopd/swapclient_server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,9 +1249,16 @@ func (s *swapClientServer) GetInfo(ctx context.Context,
12491249
}
12501250
}
12511251

1252+
commitHash := loop.CommitHash
1253+
if loop.Dirty != "" {
1254+
// If the build was dirty, we add a "-dirty" suffix to the
1255+
// commit hash.
1256+
commitHash += "-" + loop.Dirty
1257+
}
1258+
12521259
return &looprpc.GetInfoResponse{
12531260
Version: loop.Version(),
1254-
CommitHash: loop.CommitHash(),
1261+
CommitHash: commitHash,
12551262
Network: s.config.Network,
12561263
RpcListen: s.config.RPCListen,
12571264
RestListen: s.config.RESTListen,

looprpc/client.pb.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,9 @@ message GetInfoResponse {
10561056
LoopStats loop_in_stats = 8;
10571057

10581058
/*
1059-
The git commit hash of the loopd binary.
1059+
The Git commit hash the Loop binary build was based on. If the build had
1060+
uncommited changes, this field will contain the most recent commit hash,
1061+
suffixed by "-dirty".
10601062
*/
10611063
string commit_hash = 9;
10621064
}

looprpc/client.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@
986986
},
987987
"commit_hash": {
988988
"type": "string",
989-
"description": "The git commit hash of the loopd binary."
989+
"description": "The Git commit hash the Loop binary build was based on. If the build had\nuncommited changes, this field will contain the most recent commit hash,\nsuffixed by \"-dirty\"."
990990
}
991991
}
992992
},

release_notes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ This file tracks release notes for the loop client.
1818

1919
#### Breaking Changes
2020

21+
* The content of the `commit_hash` field of the `GetInfo` response has been updated so that it contains the Git commit
22+
hash the Loop binary build was based on. If the build had uncommited changes, this field will contain the most recent
23+
commit hash, suffixed by "-dirty".
24+
* The `Commit` part of the `--version` command output has been updated to contain the most recent git commit tag.
25+
2126
#### Bug Fixes
2227

2328
#### Maintenance

version.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ import (
1212
"strings"
1313
)
1414

15-
// Commit stores the current commit hash of this build, this should be set
16-
// using the -ldflags during compilation.
15+
// Commit stores the current git tag of this build, when the build is based on
16+
// a tagged commit. If the build is based on an untagged commit or is a dirty
17+
// build, the Commit field stores the most recent tag suffixed by the commit
18+
// hash, and/or "-dirty". This should be set using the -ldflags during
19+
// compilation.
1720
var Commit string
1821

22+
// CommitHash stores the current git commit hash of this build. This should be
23+
// set using the -ldflags during compilation.
24+
var CommitHash string
25+
26+
// Dirty stores a "dirty" string, if the build had uncommitted changes when
27+
// being built. This should be set using the -ldflags during compilation.
28+
var Dirty string
29+
1930
// semanticAlphabet is the allowed characters from the semantic versioning
2031
// guidelines for pre-release version and build metadata strings. In particular
2132
// they MUST only contain characters in semanticAlphabet.
@@ -52,16 +63,15 @@ func Version() string {
5263
}
5364

5465
// RichVersion returns the application version as a properly formed string
55-
// per the semantic versioning 2.0.0 spec (http://semver.org/) and the commit
56-
// it was built on.
66+
// per the semantic versioning 2.0.0 spec (http://semver.org/), followed by the
67+
// most recent git tag and commit hash the build was built on.
5768
func RichVersion() string {
58-
// Append commit hash of current build to version.
59-
return fmt.Sprintf("%s commit=%s", semanticVersion(), Commit)
60-
}
61-
62-
// CommitHash returns the commit hash of the current build.
63-
func CommitHash() string {
64-
return Commit
69+
// Append the most recent git tag and commit hash of the current build
70+
// to version.
71+
return fmt.Sprintf(
72+
"%s commit=%s commit_hash=%s", semanticVersion(), Commit,
73+
CommitHash,
74+
)
6575
}
6676

6777
// UserAgent returns the full user agent string that identifies the software

0 commit comments

Comments
 (0)