Skip to content

Commit ea0671b

Browse files
committed
tag-git: be smarter when determining the base tag
Whether rebasing to, merging-rebasing to, or merging an upstream tag, or not integrating an upstream tag at all, we must figure out the best base tag. So far, I tried several strategies: - `--first-parent`: This works only for merging-rebases - `--exclude='*.windows.*'`: This works if integrating an upstream tag, but not when a `.windows.2` version is desired - calling `git describe` twice: first to figure out the reachable upstream tag that is closest to the revision, and then calling it a second time, this time allowing for a Git for Windows tag. If the two searches came up with different results, pick the most recent one. Unfortunately that did not work. Its logic relies on the date when the Git version the downstream Git for Windows version was tagged. This broke down in the case of v2.50.1, which was tagged before I could release v2.50.0.windows.1. Let's just instead pick the higher version number by leveraging the `version_compare` function I developed in git-for-windows/build-extra@1418ee7e8e (git-update: do not suggest downgrading from an -rc version, 2017-10-26) and that has been subsequently been enhanced in that repository. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent cf4be88 commit ea0671b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

update-scripts/tag-git.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,43 @@ git_rev="$1"
2828
test "refs/heads/$release_branch" = "$(git -C "$build_extra_dir" symbolic-ref HEAD)" ||
2929
die "Need the current branch in '$build_extra_dir' to be '$release_branch'"
3030

31+
# This function was copied from `git-update-git-for-windows` in
32+
# the `mingw-w64-git-extra` package.
33+
version_compare () {
34+
a="$1"
35+
b="$2"
36+
37+
while true
38+
do
39+
test -n "$b" || { echo 1; return; }
40+
test -n "$a" || { echo -1; return; }
41+
42+
# Get the first numbers (if any)
43+
a1="$(expr "$a" : '^\([0-9]*\)')"; a="${a#$a1}"
44+
b1="$(expr "$b" : '^\([0-9]*\)')"; b="${b#$b1}"
45+
46+
if test -z "$b1"
47+
then
48+
test -z "$a1" || { echo 1; return; }
49+
a1=0
50+
b1=0
51+
fi
52+
test -n "$a1" || { echo -1; return; }
53+
test $a1 -le $b1 || { echo 1; return; }
54+
test $b1 -le $a1 || { echo -1; return; }
55+
56+
# Skip non-numeric prefixes
57+
a1="$(expr "$a" : '^\([^0-9]\+\)')"; a="${a#$a1}"
58+
b1="$(expr "$b" : '^\([^0-9]\+\)')"; b="${b#$b1}"
59+
60+
case "$a1,$b1" in
61+
[.-]rc,[.-]rc) ;; # both are -rc versions
62+
[.-]rc,*) echo -1; return;;
63+
*,[.-]rc) echo 1; return;;
64+
esac
65+
done
66+
}
67+
3168
mkdir -p "$artifacts_dir" &&
3269
if test -n "$snapshot_version"
3370
then
@@ -45,6 +82,13 @@ else
4582

4683
desc="$(git --git-dir "$git_git_dir" describe --match 'v[0-9]*[0-9]' --exclude='*-[0-9]*' --exclude='*.windows.*' "$git_rev")" &&
4784
base_tag=${desc%%-[1-9]*} &&
85+
desc2="$(git --git-dir "$git_git_dir" describe --match 'v[0-9]*[0-9]' --exclude='*-[0-9]*' "$git_rev")" &&
86+
base_tag2=${desc2%%-[1-9]*} &&
87+
# If there is a candidate Git tag _and_ a candidate Git for Windows tag, compare versions
88+
if test "$base_tag" != "$base_tag2" && test $(version_compare "$base_tag" "$base_tag2") -lt 0
89+
then
90+
base_tag="$base_tag2"
91+
fi &&
4892
case "$base_tag" in
4993
"$desc") die "Revision '$git_rev' already tagged as $base_tag";;
5094
*.windows.*)

0 commit comments

Comments
 (0)