History

scripts/setlocalversion: also consider annotated tags of the form vx.y.z-${file_localversion}

Commit 6ab7e1f95e96 ("setlocalversion: use only the correct release tag for git-describe") was absolutely correct to limit which annotated tags would be used to compute the -01234-gabcdef suffix. Otherwise, if some random annotated tag exists closer to HEAD than the vX.Y.Z one, the commit count would be too low. However, since the version string always includes the ${file_localversion} part, now the problem is that the count can be too high. For example, building an 6.4.6-rt8 kernel with a few patches on top, I currently get $ make -s kernelrelease 6.4.6-rt8-00128-gd78b7f406397 But those 128 commits include the 100 commits that are in v6.4.6..v6.4.6-rt8, so this is somewhat misleading. Amend the logic so that, in addition to the linux-next consideration, the script also looks for a tag corresponding to the 6.4.6-rt8 part of what will become the `uname -r` string. With this patch (so 29 patches on top of v6.4.6-rt8), one instead gets $ make -s kernelrelease 6.4.6-rt8-00029-gd533209291a2 While there, note that the line git describe --exact-match --match=$tag $tag 2>/dev/null obviously asks if $tag is an annotated tag, but it does not actually tell if the commit pointed to has any relation to HEAD. So remove both uses of --exact-match, and instead just ask if the description generated is identical to the tag we provided. Since we then already have the result of git describe --match=$tag we also end up reducing the number of times we invoke "git describe".

Rasmus Villemoes committed 3 years ago

Commit 01e89a41 parent 3354c641 file · +26 −10Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/setlocalversion+26−10
@@ -57,21 +57,37 @@ scm_version() · 56 unmodified lines
57 return57 return
58 fi58 fi
59 59
60 # If a localversion*' file and the corresponding annotated tag exist,60 # mainline kernel: 6.2.0-rc5 -> v6.2-rc5
61 # use it. This is the case in linux-next.61 # stable kernel: 6.1.7 -> v6.1.7
62 version_tag=v$(echo "${KERNELVERSION}" | sed -E 's/^([0-9]+\.[0-9]+)\.0(.*)$/\1\2/')
63
64 # If a localversion* file exists, and the corresponding
65 # annotated tag exists and is an ancestor of HEAD, use
66 # it. This is the case in linux-next.
62 tag=${file_localversion#-}67 tag=${file_localversion#-}
63 tag=$(git describe --exact-match --match=$tag $tag 2>/dev/null)68 desc=
69 if [ -n "${tag}" ]; then
70 desc=$(git describe --match=$tag 2>/dev/null)
71 fi
72
73 # Otherwise, if a localversion* file exists, and the tag
74 # obtained by appending it to the tag derived from
75 # KERNELVERSION exists and is an ancestor of HEAD, use
76 # it. This is e.g. the case in linux-rt.
77 if [ -z "${desc}" ] && [ -n "${file_localversion}" ]; then
78 tag="${version_tag}${file_localversion}"
79 desc=$(git describe --match=$tag 2>/dev/null)
80 fi
64 81
65 # Otherwise, default to the annotated tag derived from KERNELVERSION.82 # Otherwise, default to the annotated tag derived from KERNELVERSION.
66 # mainline kernel: 6.2.0-rc5 -> v6.2-rc583 if [ -z "${desc}" ]; then
67 # stable kernel: 6.1.7 -> v6.1.784 tag="${version_tag}"
68 if [ -z "${tag}" ]; then85 desc=$(git describe --match=$tag 2>/dev/null)
69 tag=v$(echo "${KERNELVERSION}" | sed -E 's/^([0-9]+\.[0-9]+)\.0(.*)$/\1\2/')
70 fi86 fi
71 87
72 # If we are at the tagged commit, we ignore it because the version is88 # If we are at the tagged commit, we ignore it because the version is
73 # well-defined.89 # well-defined.
74 if [ -z "$(git describe --exact-match --match=$tag 2>/dev/null)" ]; then90 if [ "${tag}" != "${desc}" ]; then
75 91
76 # If only the short version is requested, don't bother92 # If only the short version is requested, don't bother
77 # running further git commands93 # running further git commands
@@ -81,8 +97,8 @@ scm_version() · 3 unmodified lines
81 fi97 fi
82 # If we are past the tagged commit, we pretty print it.98 # If we are past the tagged commit, we pretty print it.
83 # (like 6.1.0-14595-g292a089d78d3)99 # (like 6.1.0-14595-g292a089d78d3)
84 if atag="$(git describe --match=$tag 2>/dev/null)"; then100 if [ -n "${desc}" ]; then
85 echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'101 echo "${desc}" | awk -F- '{printf("-%05d", $(NF-1))}'
86 fi102 fi
87 103
88 # Add -g and exactly 12 hex chars.104 # Add -g and exactly 12 hex chars.