Merge ~nicolasbock/git-build-recipe:long into git-build-recipe:master

Proposed by Nicolas Bock
Status: Needs review
Proposed branch: ~nicolasbock/git-build-recipe:long
Merge into: git-build-recipe:master
Diff against target: 51 lines (+19/-0)
2 files modified
gitbuildrecipe/deb_version.py (+4/-0)
gitbuildrecipe/recipe.py (+15/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Needs Information
Review via email: mp+447167@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

It's generally a mistake (though a very tempting one) to put git commit IDs in package version numbers, which is what this would do. Git commit IDs aren't ordered in the sense of Debian version comparison. Now, `git describe --tags --abbrev=7` does include the number of commits on top of the latest tag, which mitigates that problem; but the commit ID part is rather unusable.

There's also a non-obvious syntactic problem here. `git describe --tags --abbrev=7` outputs something like "2.11.2-16-gf6fbdf8". But in a Debian version, the "Debian revision" part of the version is defined as the part to the right of the _rightmost_ "-" character (see https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-version); that means that a package using such a version would parse as having an upstream version of "2.11.2-16" and a Debian revision of "gf6fbdf8", which is unlikely to be quite correct and which can cause subtle problems.

I recommend instead using some form of the `{revno}` variable (perhaps in addition to `{latest-tag}`) to build up the version of your recipe. This gives you something that fulfils the same purpose as the usable part of `git describe --tags --abbrev=7`, but without the confusing pitfalls. Have you tried that?

review: Needs Information
Revision history for this message
Nicolas Bock (nicolasbock) wrote :

Thanks for your comments. I think the main information we are interested in the number of commits after the latest tag. I'll remove the commit SHA.

Revision history for this message
Colin Watson (cjwatson) wrote :

Right, but then you can just use the existing `{revno}`. (Admittedly this gives you the number of first-parent commits since the start of the history, not the number of commits since the latest tag; but in my experience that's just as good for including in autogenerated versions, since the important thing is just that each segment of the version is ordered sensibly.)

Unmerged commits

cafac46... by Nicolas Bock

Added new variable `{latest-tag-long}`

This variable expands using

  git describe --tags --abbrev=7

To include the number of commits past the latest tag.

Signed-off-by: Nicolas Bock <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitbuildrecipe/deb_version.py b/gitbuildrecipe/deb_version.py
2index f70bc49..b0dc038 100644
3--- a/gitbuildrecipe/deb_version.py
4+++ b/gitbuildrecipe/deb_version.py
5@@ -25,6 +25,7 @@ from gitbuildrecipe.recipe import (
6 FormattedError,
7 GitCommitVariable,
8 LatestTagVariable,
9+ LatestTagLongVariable,
10 RevdateVariable,
11 RevnoVariable,
12 RevtimeVariable,
13@@ -199,6 +200,9 @@ def substitute_branch_vars(base_branch, child_branch):
14 base_branch.deb_version = git_commit_var.replace(base_branch.deb_version)
15 latest_tag_var = LatestTagVariable(child_branch)
16 base_branch.deb_version = latest_tag_var.replace(base_branch.deb_version)
17+ latest_tag_long_var = LatestTagLongVariable(child_branch)
18+ base_branch.deb_version = latest_tag_long_var.replace(
19+ base_branch.deb_version)
20 revdate_var = RevdateVariable(child_branch)
21 base_branch.deb_version = revdate_var.replace(base_branch.deb_version)
22 revtime_var = RevtimeVariable(child_branch)
23diff --git a/gitbuildrecipe/recipe.py b/gitbuildrecipe/recipe.py
24index f932ca7..ee29ae5 100644
25--- a/gitbuildrecipe/recipe.py
26+++ b/gitbuildrecipe/recipe.py
27@@ -238,9 +238,24 @@ class LatestTagVariable(RevisionVariable):
28 stderr=subprocess.STDOUT).rstrip("\n")
29
30
31+class LatestTagLongVariable(RevisionVariable):
32+
33+ basename = "latest-tag-long"
34+
35+ minimum_format = 0.4
36+
37+ def get(self):
38+ # Capture stderr so that exceptions are useful. We know that git
39+ # describe does not write to stderr on success.
40+ return self.branch.git_output(
41+ "describe", "--tags", "--abbrev=7", self.commit,
42+ stderr=subprocess.STDOUT).rstrip("\n")
43+
44+
45 branch_vars = [
46 GitCommitVariable,
47 LatestTagVariable,
48+ LatestTagLongVariable,
49 RevdateVariable,
50 RevtimeVariable,
51 ]

Subscribers

People subscribed via source and target branches