-
Couldn't load subscription status.
- Fork 534
git describe #816
git describe #816
Conversation
RFC.
- Functionality is still being developed.
- I don't know how many options are worth implementing. (Any suggestion git-describe #736 ?)
I'll squash at the end. Nothing fancy yet xD
030324a to
0b1ee9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can be implemented at Repository with a function Tag(referenceName), or a helper function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like TagObject but for lightweight tags will be ideal.
Then we just need to walk down the log checking for annotated tags or lw-tags deppending on the --tag option always preferring annotated ones as described in the git documentation. This search algorithm is nicely described doing a git describe --tags --debug:
$ git describe --tags --debug
searching to describe HEAD
lightweight 2 v4.3.1
lightweight 12 v4.3.0
lightweight 18 v4.2.1
lightweight 35 v4.2.0
lightweight 56 v4.1.1
lightweight 77 v4.1.0
lightweight 90 v4.0.0
lightweight 271 v4.0.0-rc15
lightweight 282 v4.0.0-rc14
lightweight 330 v4.0.0-rc13
traversed 393 commits
more than 10 tags found; listed 10 most recent
gave up search at d3c7400c39f86a4c59340c7a9cda8497186e00fc
v4.3.1-2-g87cc819I did not dig into the details of TagObject. I'll check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks ok but requires a lot of more work, git describe is a complex command.
Thanks for contributing.
Indeed! Is more RFC on the feature branch than a production-ready PR. Comments and PRs to the branch are also welcome. :)
bcbda0d to
6104842
Compare
- I was able to replicate the regular output of
git describewith minor deviations in the distance calculated bygo-gitand the distance calculated bygit describe. - The algorithm now tries to closely follow the source of
git describe. - The performance is an average of 3 times slower than
git describe. A good part of the time is expend during thecommitIterator, err := r.Log(&LogOptions ...I didn't dig too much on it but apparentlyr.CommitObject(h)is the slower inside. Of course the majority of the time though goes on the tag map query, but after trying with several different methods (even with go routines) this is, by far, the fastest algorithm.
$ time git describe --tags --debug; time go_git_describe_test
searching to describe HEAD
lightweight 1 v4.3.1
lightweight 11 v4.3.0
lightweight 17 v4.2.1
lightweight 34 v4.2.0
lightweight 55 v4.1.1
lightweight 76 v4.1.0
lightweight 89 v4.0.0
lightweight 270 v4.0.0-rc15
lightweight 281 v4.0.0-rc14
lightweight 329 v4.0.0-rc13
traversed 392 commits
more than 10 tags found; listed 10 most recent
gave up search at d3c7400c39f86a4c59340c7a9cda8497186e00fc
v4.3.1-1-ge99fdcd
real 0m0.027s
user 0m0.022s
sys 0m0.006s
/home/edupo/go/src/gopkg.in/src-d/go-git.v4
searching to describe refs/heads/736-git-describe
lightweight 1 v4.3.1
lightweight 11 v4.3.0
lightweight 17 v4.2.1
lightweight 34 v4.2.0
lightweight 54 v4.1.1
lightweight 76 v4.1.0
lightweight 89 v4.0.0
lightweight 269 v4.0.0-rc15
lightweight 280 v4.0.0-rc14
lightweight 329 v4.0.0-rc13
traversed 391 commits
more than 10 tags found; listed 10 most recent
gave up search at d3c7400c39f86a4c59340c7a9cda8497186e00fc
v4.3.1-1-ge99fdcd
real 0m0.062s
user 0m0.061s
sys 0m0.021s
Still some improvements to do and some more options to enable like All, Match and Always.
9425c85 to
8e14928
Compare
- `Describe` method under repository allows to describe references based on tags. - Options ported from `git describe` as close as possible. - Basic test for `Describe` Signed-off-by: Eduardo Lezcano <eduardo.lezcano@be.atlascopco.com>
8e14928 to
e99fdcd
Compare
Very cool @edupo keep the good work.
Ilyes512
commented
Nov 10, 2018
I was looking at using go-git to fetch tag information using go generate. Are you guys still working on this or is this feature currently abandoned?
(I will just use bash or ldflags to solve my problem for now).
Changdrew
commented
Mar 5, 2019
Have there been any updates for this feature? We'd love to use inbuilt library functions; we were thinking about using this workaround.
Previously the version of the application was determined by calling `git` commands in a new shell process. This works in most cases, but might fail if Git is not installed on the running system. To prevent further enlargement of the required development environment setup dependencies by adding more checks for external dependencies, the `go-git` library v4 [1] (`github.com/src-d/go-git/v4`) has been added: "A highly extensible Git implementation in pure Go" It allows to interact with the project repository and extrac required information like the latest tag and commit of the current branch to assemble the application version. To simplify the processing and parsing of the version, the `semver` library v3 [2] (`github.com/Masterminds/semver/v3`) has also been added. The new `getAppVersionFromGit()` function assembles the version of the application from the metadata of the Git repository. It searches for the latest "SemVer" [3] compatible version tag in the current branch and falls back to the default version from the application configuration if none is found. If at least one tag is found but it is not the latest commit of the current branch, the build metadata will be appended, consisting of the amount of commits ahead and the shortened reference hash (8 digits) of the latest commit from the current branch. The function is a early implementation of the Git `describe` command because support in `go-git` [1] has not been implemented yet. See the full compatibility comparison documentation with Git [4] as well as the proposed Git `describe` command implementation [5] for more details. [1]: https://github.com/src-d/go-git/v4 [2]: https://github.com/Masterminds/semver/v3 [3]: https://semver.org [4]: https://github.com/src-d/go-git/blob/master/COMPATIBILITY.md [5]: src-d/go-git#816 Epic GH-33 GH-92
App version with pure Go Git and SemVer libraries Previously the version of the application was determined by calling `git` commands in a new shell process. This works in most cases, but might fail if Git is not installed on the running system. To prevent further enlargement of the required development environment setup dependencies by adding more checks for external dependencies, the `go-git` library v4 [1] (`github.com/src-d/go-git/v4`) has been added: "A highly extensible Git implementation in pure Go" It allows to interact with the project repository and extrac required information like the latest tag and commit of the current branch to assemble the application version. To simplify the processing and parsing of the version, the `semver` library v3 [2] (`github.com/Masterminds/semver/v3`) has also been added. The new `getAppVersionFromGit()` function assembles the version of the application from the metadata of the Git repository. It searches for the latest "SemVer" [3] compatible version tag in the current branch and falls back to the default version from the application configuration if none is found. If at least one tag is found but it is not the latest commit of the current branch, the build metadata will be appended, consisting of the amount of commits ahead and the shortened reference hash (8 digits) of the latest commit from the current branch. The function is a early implementation of the Git `describe` command because support in `go-git` [1] has not been implemented yet. See the full compatibility comparison documentation with Git [4] as well as the proposed Git `describe` command implementation [5] for more details. The function returned a composed struct to store application version information and metadata that allows to use the version metadata for other tasks. It consists of a embedded `semver.Version` struct and additional fields that stores Git related information: - `GitCommitHash` (type `plumbing.Hash`) - The latest commit hash of the current branch. - `GitCommitsAhead` (type `int`) - The count of commits ahead to the latest Git tag from the current branch. - `GitLatestVersionTag` (type `plumbing.Reference`) - The latest Git version tag in the current branch. [1]: https://github.com/src-d/go-git/v4 [2]: https://github.com/Masterminds/semver/v3 [3]: https://semver.org [4]: https://github.com/src-d/go-git/blob/master/COMPATIBILITY.md [5]: src-d/go-git#816 Epic GH-33 Resolves GH-92
Signed-off-by: Eduardo Lezcano eduardo.lezcano@be.atlascopco.com