aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2024-03-13 11:11:59 +0200
committerTimo Teräs <timo.teras@iki.fi>2024-03-14 16:08:33 +0200
commit5e91e63aede05f80a6abc9d96e0fb05369c5cbda (patch)
tree5427cd88329b99f7d13ccd5c0100d6996403c9b1
parentb59e73e2668f3fcc35414e10f4e085edb2f60bb4 (diff)
version: add support for commit hash component in version stringtt-version-commithash
fixes #10830
-rw-r--r--doc/apk-package.5.scd6
-rw-r--r--src/apk_ctype.h3
-rw-r--r--src/ctype.c33
-rw-r--r--src/version.c10
-rw-r--r--test/version.data9
5 files changed, 42 insertions, 19 deletions
diff --git a/doc/apk-package.5.scd b/doc/apk-package.5.scd
index 932970a..bb669ad 100644
--- a/doc/apk-package.5.scd
+++ b/doc/apk-package.5.scd
@@ -49,7 +49,7 @@ Unfortunately it is not possible to deduce if a given string is of format
followed the Gentoo package version specification.
Currently the APK version specification is as follows:
- *number{.number}...{letter}{\_suffix{number}}...{-r#}*
+ *number{.number}...{letter}{\_suffix{number}}...{~hash}{-r#}*
Each *number* component is a sequence of digits (0-9).
@@ -59,6 +59,10 @@ Unfortunately it is not possible to deduce if a given string is of format
of valid suffixes (and their sorting order) is:
*alpha*, *beta*, *pre*, *rc*, <no suffix>, *cvs*, *svn*, *git*, *hg*, *p*
+ This can be follows with an optional *{~hash}* to indicate a commit
+ hash from where it was built. This can be any length string of
+ lower case hexdecimal digits (0-9a-f).
+
Finally an optional package build component *-r{number}* can follow.
*unique-id* (*C*)
diff --git a/src/apk_ctype.h b/src/apk_ctype.h
index 6379680..b42098e 100644
--- a/src/apk_ctype.h
+++ b/src/apk_ctype.h
@@ -10,7 +10,8 @@
#define APK_CTYPE_H
enum {
- APK_CTYPE_PACKAGE_NAME = 0,
+ APK_CTYPE_HEXDIGIT = 0,
+ APK_CTYPE_PACKAGE_NAME,
APK_CTYPE_VERSION_SUFFIX,
APK_CTYPE_DEPENDENCY_NAME,
APK_CTYPE_DEPENDENCY_COMPARER,
diff --git a/src/ctype.c b/src/ctype.c
index 617fc7b..2cdb30d 100644
--- a/src/ctype.c
+++ b/src/ctype.c
@@ -10,6 +10,7 @@
#include "apk_blob.h"
#include "apk_ctype.h"
+#define HEXDGT BIT(APK_CTYPE_HEXDIGIT)
#define PKGNAME BIT(APK_CTYPE_PACKAGE_NAME)|BIT(APK_CTYPE_DEPENDENCY_NAME)
#define VERSUF BIT(APK_CTYPE_VERSION_SUFFIX)
#define DEPNAME BIT(APK_CTYPE_DEPENDENCY_NAME)
@@ -29,16 +30,16 @@ static uint8_t apk_ctype[128] = {
['='] = DEPCOMP,
['>'] = DEPCOMP,
['/'] = DEPNAME,
- ['0'] = PKGNAME,
- ['1'] = PKGNAME,
- ['2'] = PKGNAME,
- ['3'] = PKGNAME,
- ['4'] = PKGNAME,
- ['5'] = PKGNAME,
- ['6'] = PKGNAME,
- ['7'] = PKGNAME,
- ['8'] = PKGNAME,
- ['9'] = PKGNAME,
+ ['0'] = HEXDGT|PKGNAME,
+ ['1'] = HEXDGT|PKGNAME,
+ ['2'] = HEXDGT|PKGNAME,
+ ['3'] = HEXDGT|PKGNAME,
+ ['4'] = HEXDGT|PKGNAME,
+ ['5'] = HEXDGT|PKGNAME,
+ ['6'] = HEXDGT|PKGNAME,
+ ['7'] = HEXDGT|PKGNAME,
+ ['8'] = HEXDGT|PKGNAME,
+ ['9'] = HEXDGT|PKGNAME,
['A'] = PKGNAME,
['B'] = PKGNAME,
['C'] = PKGNAME,
@@ -66,12 +67,12 @@ static uint8_t apk_ctype[128] = {
['Y'] = PKGNAME,
['Z'] = PKGNAME,
['_'] = PKGNAME,
- ['a'] = VERSUF|PKGNAME,
- ['b'] = VERSUF|PKGNAME,
- ['c'] = VERSUF|PKGNAME,
- ['d'] = VERSUF|PKGNAME,
- ['e'] = VERSUF|PKGNAME,
- ['f'] = VERSUF|PKGNAME,
+ ['a'] = HEXDGT|VERSUF|PKGNAME,
+ ['b'] = HEXDGT|VERSUF|PKGNAME,
+ ['c'] = HEXDGT|VERSUF|PKGNAME,
+ ['d'] = HEXDGT|VERSUF|PKGNAME,
+ ['e'] = HEXDGT|VERSUF|PKGNAME,
+ ['f'] = HEXDGT|VERSUF|PKGNAME,
['g'] = VERSUF|PKGNAME,
['h'] = VERSUF|PKGNAME,
['i'] = VERSUF|PKGNAME,
diff --git a/src/version.c b/src/version.c
index 858c0aa..6e35fa3 100644
--- a/src/version.c
+++ b/src/version.c
@@ -15,7 +15,7 @@
#define DEBUG 0
-/* Alpine version: digit{.digit}...{letter}{_suf{#}}...{-r#} */
+/* Alpine version: digit{.digit}...{letter}{_suf{#}}...{~hash}{-r#} */
enum PARTS {
TOKEN_INITIAL_DIGIT,
@@ -23,6 +23,7 @@ enum PARTS {
TOKEN_LETTER,
TOKEN_SUFFIX,
TOKEN_SUFFIX_NO,
+ TOKEN_COMMIT_HASH,
TOKEN_REVISION_NO,
TOKEN_END,
TOKEN_INVALID,
@@ -183,6 +184,13 @@ static void token_next(struct token_state *t, apk_blob_t *b)
if (t->suffix == SUFFIX_INVALID) goto invalid;
t->token = TOKEN_SUFFIX;
break;
+ case '~':
+ if (t->token >= TOKEN_COMMIT_HASH) goto invalid;
+ b->ptr++, b->len--;
+ apk_blob_spn(*b, APK_CTYPE_HEXDIGIT, &t->value, b);
+ if (t->value.len == 0) goto invalid;
+ t->token = TOKEN_COMMIT_HASH;
+ break;
case '-':
if (t->token >= TOKEN_REVISION_NO) goto invalid;
if (!apk_blob_pull_blob_match(b, APK_BLOB_STRLIT("-r"))) goto invalid;
diff --git a/test/version.data b/test/version.data
index c692c45..b6567db 100644
--- a/test/version.data
+++ b/test/version.data
@@ -734,6 +734,10 @@
8.2.0 < 8.2.001
8.2.0015 < 8.2.002
+1.0~1234 < 1.0~2345
+1.0~1234-r1 < 1.0~2345-r0
+1.0~1234-r1 > 1.0~1234-r0
+
3.6.0 ~ 3.6
3.6.9 ~ 3.6
3.6_pre1 ~ 3.6
@@ -753,6 +757,7 @@
1.2
0.1_pre2
+0.1_pre2~1234abcd
0.1_p1_pre2
0.1_alpha1_pre2
0.1_git20240101_pre1
@@ -761,6 +766,10 @@
!0.1bc1
!0.1a1
!0.1a.1
+!0.1_pre2~
+!0.1_pre2~1234xbcd
+!0.1_pre2~1234abcd_pre1
+!0.1_pre2-r1~1234xbcd
!0.1_foobar
!0.1_foobar1
!0.1-pre1.1