github.com/rivy-go/git-changelog@v0.0.0-20240424224517-b86e6ab57773/cmd/git-changelog/version.go (about) 1 package main 2 3 const Version = "1.2.0" 4 5 var VersionFromBuilder string // set by the build system, when needed (ie, for earlier golang versions) 6 7 // FnVersionOptions ~ optional arguments for `version()` 8 // * `HashAbbrevLength` ~ target length of VCS revision hash abbreviation string (default: 8) 9 type FnVersionOptions struct { 10 HashAbbrevLength int 11 } 12 13 // version() 14 // : RETURNS the version string (eg, '1.1.1', '1.1.1-abcdef01', or '1.1.1+') for the current build 15 // * for `go install ...@VERSION`, the returned version string will be the published VERSION tag 16 // * for local builds with VCS info, the returned version string will be [Version] with a VCS revision hash suffix 17 // * for local builds w/o build info, the returned version string will be [Version] with a '+' suffix 18 // 19 // The returned version string will be as un-ambiguous as possible, exact/precise for remote builds and when VCS info is available. 20 func version(options ...FnVersionOptions) string { 21 // risk of hash collision between commits: 22 // 7-hex-character (28 bit) length: 1% at 3,000 commits, 17% at 10,000 commits 23 // 8-hex-character (32 bit) length: 0.1% at 3,000 commits, 1% at 10,000 commits 24 // 10-hex-character (40 bit) length: 0.1% at 47,000 commits, 1% at 150,000 commits 25 // ref: <https://en.wikipedia.org/wiki/Birthday_problem> @@ <https://archive.is/sqPqu> 26 var option = FnVersionOptions{ HashAbbrevLength: 8 } 27 if len(options) > 0 { 28 // option = options[0] 29 option = options[len(options)-1] 30 } 31 return version_impl(option) 32 }