Re: [PATCH] versionsort: support reorder prerelease suffixes
From: Junio C Hamano <hidden>
Date: 2016-06-15 23:03:56
Nguyễn Thái Ngọc Duy [off-list ref] writes:
quoted hunk
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted> --- Second round. Looking better. We can do "1.0-pre12 < 1.0-rc0 < 1.0 < 1.0-post1" too but it relies on config key's loading order, a bit iffy. Documentation/config.txt | 7 +++++++ t/t7004-tag.sh | 28 +++++++++++++++++++++++++++ versioncmp.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+)diff --git a/Documentation/config.txt b/Documentation/config.txt index 04e2a71..8e078df 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt@@ -2539,6 +2539,13 @@ user.signingkey:: This option is passed unchanged to gpg's --local-user parameter, so you may specify a key using any method that gpg supports. +versionsort.prereleaseSuffix:: + When version sort is used in linkgit:git-tag[1], prerelease + tags (e.g. "1.0-rc1") may appear after the main release + "1.0". By specifying the suffix "-rc" in this variable, + "1.0-rc1" will appear before "1.0". One variable assignment + per suffix.
I think the last half-sentence want to mean that
[versionsort]
prereleaseSuffix = -pre
prereleaseSuffix = -rc
is the supported way to write, and not
[versionsort]
prereleaseSuffix = -pre -rc
but it probably is unclear unless the reader already knows what it
is trying to say. The reader also needs to learn somewhere how the
order of the entries affects the result.
+ if (i1 == -1 && i2 == -1) + return 0; + if (i1 >= 0 && i2 >= 0) + *diff = i1 - i2; + else if (i1 >= 0) + *diff = -1;
p1 is a prerelease and p2 is not, so p1 comes before p2.
+ else /* if (i2 >= 0) */ + *diff = 1;
and the other way around. The math makes sense, I think.