github.com/decred/dcrlnd@v0.7.6/build/version_buildinfo.go (about) 1 // Copyright (c) 2021 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 //go:build go1.18 6 // +build go1.18 7 8 package build 9 10 import ( 11 "runtime/debug" 12 ) 13 14 func vcsCommitID() string { 15 bi, ok := debug.ReadBuildInfo() 16 if !ok { 17 return "" 18 } 19 var vcs, revision, dirty string 20 for _, bs := range bi.Settings { 21 switch bs.Key { 22 case "vcs": 23 vcs = bs.Value 24 case "vcs.revision": 25 revision = bs.Value 26 case "vcs.modified": 27 if bs.Value == "true" { 28 dirty = ".dirty" 29 } 30 } 31 } 32 if vcs == "" { 33 return "" 34 } 35 if vcs == "git" && len(revision) > 9 { 36 revision = revision[:9] 37 } 38 return revision + dirty 39 }