version.go 861 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import "runtime/debug"
  3. // version is the release number shown on the About page. Bump it in the PR
  4. // that makes a user-visible change.
  5. const version = "0.5.3"
  6. // commitInfo is the git revision `go build` stamped into the binary. Full is
  7. // empty when the binary was built outside a git checkout (for example by
  8. // `go test`); Dirty means the tree had uncommitted changes, so the build
  9. // doesn't match any commit exactly.
  10. type commitInfo struct {
  11. Full, Short string
  12. Dirty bool
  13. }
  14. func buildCommit() commitInfo {
  15. info, ok := debug.ReadBuildInfo()
  16. if !ok {
  17. return commitInfo{}
  18. }
  19. var c commitInfo
  20. for _, s := range info.Settings {
  21. switch s.Key {
  22. case "vcs.revision":
  23. c.Full = s.Value
  24. case "vcs.modified":
  25. c.Dirty = s.Value == "true"
  26. }
  27. }
  28. c.Short = c.Full
  29. if len(c.Short) > 7 {
  30. c.Short = c.Short[:7]
  31. }
  32. return c
  33. }