[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, libq/
commit: 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 15 19:53:43 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Wed Jun 15 19:53:43 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd libq/atom: fix atom_compare for "0" version components Bug: https://bugs.gentoo.org/852197 Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 36 ++-- tests/atom_compare/static.good | 1 + tests/atom_compare/static.tests | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 50e9520..31299f1 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) *ends1 != '_'; ends1++) ; + if (ends1 != s1) + ends1--; for (ends2 = s2; *ends2 != '\0' && *ends2 != '.' && *ends2 != '_'; ends2++) ; - /* 3.3L2-3: remove *trailing* zeros */ - for (ends1--; ends1 > s1 && *ends1 == '0'; ends1--) - ; - for (ends2--; ends2 > s2 && *ends2 == '0'; ends2--) - ; - /* 3.3L4 ASCII stringwise comparison */ - n1 = ends1 - s1; - n2 = ends2 - s2; - n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); - n2 = 0; + if (ends2 != s2) + ends2--; + /* bug 852197: leading 0 means something else +* must follow */ + if (ends1 - s1 > 1 || ends2 - s2 > 1) { + /* 3.3L2-3: remove *trailing* zeros */ + for (; ends1 > s1 && *ends1 == '0'; ends1--) + ; + for (; ends2 > s2 && *ends2 == '0'; ends2--) + ; + /* 3.3L4 ASCII stringwise comparison */ + n1 = ends1 - s1; + n2 = ends2 - s2; + n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); + n2 = 0; + } else { + /* repeat of 3.3#L9 (else case below) */ + n1 = strtoll(s1, &ends1, 10); + if (ends1 == s1) + n1 = -1; + n2 = strtoll(s2, &ends2, 10); + if (ends2 == s2) + n2 = -1; + } } else { /* 3.3#L9 */ n1 = strtoll(s1, &ends1, 10); if (ends1 == s1) diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good index 6da5553..83bf7ec 100644 --- a/tests/atom_compare/static.good +++ b/tests/atom_compare/static.good @@ -52,3 +52,4 @@ a-1 != =a-1.2z* a-1_alpha1 == =a-1* a-1 != =a-1_alpha1* a-1_alpha-r1 == =a-1_alpha* +a-3.10.5 == >=a-3.10.0_p1_r1 diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests index 168f358..213fb5e 100644 --- a/tests/atom_compare/static.tests +++ b/tests/atom_compare/static.tests @@ -52,3 +52,4 @@ a-1 =a-1.2
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/
commit: 7de2f154c775e9de276f2fc1f619922f48a13b90 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 18 09:35:48 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 18 09:35:48 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7de2f154 libq/atom: implement strict PMS 3.3 in atom_compare Version comparisons are complex, stick with strict PMS definition for it, so we produce the same results as Portage. Bug: https://bugs.gentoo.org/838856 Signed-off-by: Fabian Groffen gentoo.org> autogen.sh| 1 + libq/atom.c | 249 -- tests/atom_compare/static.q.good | 3 +- tests/atom_compare/static.q.tests | 1 + 4 files changed, 219 insertions(+), 35 deletions(-) diff --git a/autogen.sh b/autogen.sh index ea564e0..df6e574 100755 --- a/autogen.sh +++ b/autogen.sh @@ -43,6 +43,7 @@ mods=" stat-time strcasestr-simple strncat + strtoll symlinkat sys_stat unlinkat diff --git a/libq/atom.c b/libq/atom.c index 0b5fcdd..d1eb9a4 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2021 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd- @@ -694,41 +694,170 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) /* check version */ if (data->PV && query->PV) { - char *s1, *s2; - uint64_t n1, n2; - /* first we compare the version [1.0]z_alpha1 */ - s1 = data->PV; - s2 = query->PV; - while (s1 || s2) { - if (s1 && s2) { - /* deal with leading zeros */ - while (*s1 == '0' && *s2 == '0') { - ++s1; - ++s2; + char *s1; + char *ends1; + char *s2; + char *ends2; + long long n1; + long long n2; + const atom_suffix *as1; + const atom_suffix *as2; + + /* PMS 3.3 Version Comparison +* +* Algorithm 3.1: Version comparison top-level logic +* 1: let A and B be the versions to be compared +* 2: compare numeric components using Algorithm 3.2 +* 3: compare letter components using Algorithm 3.4 +* 4: compare suffixes using Algorithm 3.5 +* 5: compare revision components using Algorithm 3.7 +* 6: return A = B +*/ + + /* step 2: numeric components +* +* Algorithm 3.2: Version comparison logic for numeric +* components +* 1: define the notations Ank and Bnk to mean the kth numeric +* component of A and B respectively, using 0-based indexing +* 2: if An0 > Bn0 using integer comparison then +* 3:return A > B +* 4: else if An0 < Bn0 using integer comparison then +* 5:return A < B +* 6: end if +* 7: let Ann be the number of numeric components of A +* 8: let Bnn be the number of numeric components of B +* 9: for all i such that i ≥ 1 and i < Ann and i < Bnn, in +* ascending order do +* 10:compare Ani and Bni using Algorithm 3.3 +* 11: end for +* 12: if Ann > Bnn then +* 13:return A > B +* 14: else if Ann < Bnn then +* 15:return A < B +* 16: end if +* +* Algorithm 3.3: Version comparison logic for each numeric +* component after the first +* 1: if either Ani or Bni has a leading 0 then +* 2:let An′i be Ani with any trailing 0s removed +* 3:let Bn′i be Bni with any trailing 0s removed +* 4:if An′i > Bn′i using ASCII stringwise comparison then +* 5: return A > B +* 6:else if An′i < Bn′i using ASCII stringwise comparison then +* 7: return A < B +* 8:end if +* 9: else +* 10:if Ani > Bni using integer comparison then +* 11: return A > B +* 12:else if Ani < Bni using integer comparison then +* 13: return A < B +* 14:end if +* 15: end
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, libq/
commit: 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 15 19:53:43 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Wed Jun 15 19:53:43 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd libq/atom: fix atom_compare for "0" version components Bug: https://bugs.gentoo.org/852197 Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 36 ++-- tests/atom_compare/static.good | 1 + tests/atom_compare/static.tests | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 50e9520..31299f1 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) *ends1 != '_'; ends1++) ; + if (ends1 != s1) + ends1--; for (ends2 = s2; *ends2 != '\0' && *ends2 != '.' && *ends2 != '_'; ends2++) ; - /* 3.3L2-3: remove *trailing* zeros */ - for (ends1--; ends1 > s1 && *ends1 == '0'; ends1--) - ; - for (ends2--; ends2 > s2 && *ends2 == '0'; ends2--) - ; - /* 3.3L4 ASCII stringwise comparison */ - n1 = ends1 - s1; - n2 = ends2 - s2; - n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); - n2 = 0; + if (ends2 != s2) + ends2--; + /* bug 852197: leading 0 means something else +* must follow */ + if (ends1 - s1 > 1 || ends2 - s2 > 1) { + /* 3.3L2-3: remove *trailing* zeros */ + for (; ends1 > s1 && *ends1 == '0'; ends1--) + ; + for (; ends2 > s2 && *ends2 == '0'; ends2--) + ; + /* 3.3L4 ASCII stringwise comparison */ + n1 = ends1 - s1; + n2 = ends2 - s2; + n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); + n2 = 0; + } else { + /* repeat of 3.3#L9 (else case below) */ + n1 = strtoll(s1, &ends1, 10); + if (ends1 == s1) + n1 = -1; + n2 = strtoll(s2, &ends2, 10); + if (ends2 == s2) + n2 = -1; + } } else { /* 3.3#L9 */ n1 = strtoll(s1, &ends1, 10); if (ends1 == s1) diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good index 6da5553..83bf7ec 100644 --- a/tests/atom_compare/static.good +++ b/tests/atom_compare/static.good @@ -52,3 +52,4 @@ a-1 != =a-1.2z* a-1_alpha1 == =a-1* a-1 != =a-1_alpha1* a-1_alpha-r1 == =a-1_alpha* +a-3.10.5 == >=a-3.10.0_p1_r1 diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests index 168f358..213fb5e 100644 --- a/tests/atom_compare/static.tests +++ b/tests/atom_compare/static.tests @@ -52,3 +52,4 @@ a-1 =a-1.2
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, libq/
commit: 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 15 19:53:43 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Wed Jun 15 19:53:43 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd libq/atom: fix atom_compare for "0" version components Bug: https://bugs.gentoo.org/852197 Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 36 ++-- tests/atom_compare/static.good | 1 + tests/atom_compare/static.tests | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 50e9520..31299f1 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) *ends1 != '_'; ends1++) ; + if (ends1 != s1) + ends1--; for (ends2 = s2; *ends2 != '\0' && *ends2 != '.' && *ends2 != '_'; ends2++) ; - /* 3.3L2-3: remove *trailing* zeros */ - for (ends1--; ends1 > s1 && *ends1 == '0'; ends1--) - ; - for (ends2--; ends2 > s2 && *ends2 == '0'; ends2--) - ; - /* 3.3L4 ASCII stringwise comparison */ - n1 = ends1 - s1; - n2 = ends2 - s2; - n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); - n2 = 0; + if (ends2 != s2) + ends2--; + /* bug 852197: leading 0 means something else +* must follow */ + if (ends1 - s1 > 1 || ends2 - s2 > 1) { + /* 3.3L2-3: remove *trailing* zeros */ + for (; ends1 > s1 && *ends1 == '0'; ends1--) + ; + for (; ends2 > s2 && *ends2 == '0'; ends2--) + ; + /* 3.3L4 ASCII stringwise comparison */ + n1 = ends1 - s1; + n2 = ends2 - s2; + n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); + n2 = 0; + } else { + /* repeat of 3.3#L9 (else case below) */ + n1 = strtoll(s1, &ends1, 10); + if (ends1 == s1) + n1 = -1; + n2 = strtoll(s2, &ends2, 10); + if (ends2 == s2) + n2 = -1; + } } else { /* 3.3#L9 */ n1 = strtoll(s1, &ends1, 10); if (ends1 == s1) diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good index 6da5553..83bf7ec 100644 --- a/tests/atom_compare/static.good +++ b/tests/atom_compare/static.good @@ -52,3 +52,4 @@ a-1 != =a-1.2z* a-1_alpha1 == =a-1* a-1 != =a-1_alpha1* a-1_alpha-r1 == =a-1_alpha* +a-3.10.5 == >=a-3.10.0_p1_r1 diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests index 168f358..213fb5e 100644 --- a/tests/atom_compare/static.tests +++ b/tests/atom_compare/static.tests @@ -52,3 +52,4 @@ a-1 =a-1.2
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/
commit: 7de2f154c775e9de276f2fc1f619922f48a13b90 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 18 09:35:48 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 18 09:35:48 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7de2f154 libq/atom: implement strict PMS 3.3 in atom_compare Version comparisons are complex, stick with strict PMS definition for it, so we produce the same results as Portage. Bug: https://bugs.gentoo.org/838856 Signed-off-by: Fabian Groffen gentoo.org> autogen.sh| 1 + libq/atom.c | 249 -- tests/atom_compare/static.q.good | 3 +- tests/atom_compare/static.q.tests | 1 + 4 files changed, 219 insertions(+), 35 deletions(-) diff --git a/autogen.sh b/autogen.sh index ea564e0..df6e574 100755 --- a/autogen.sh +++ b/autogen.sh @@ -43,6 +43,7 @@ mods=" stat-time strcasestr-simple strncat + strtoll symlinkat sys_stat unlinkat diff --git a/libq/atom.c b/libq/atom.c index 0b5fcdd..d1eb9a4 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2021 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd- @@ -694,41 +694,170 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) /* check version */ if (data->PV && query->PV) { - char *s1, *s2; - uint64_t n1, n2; - /* first we compare the version [1.0]z_alpha1 */ - s1 = data->PV; - s2 = query->PV; - while (s1 || s2) { - if (s1 && s2) { - /* deal with leading zeros */ - while (*s1 == '0' && *s2 == '0') { - ++s1; - ++s2; + char *s1; + char *ends1; + char *s2; + char *ends2; + long long n1; + long long n2; + const atom_suffix *as1; + const atom_suffix *as2; + + /* PMS 3.3 Version Comparison +* +* Algorithm 3.1: Version comparison top-level logic +* 1: let A and B be the versions to be compared +* 2: compare numeric components using Algorithm 3.2 +* 3: compare letter components using Algorithm 3.4 +* 4: compare suffixes using Algorithm 3.5 +* 5: compare revision components using Algorithm 3.7 +* 6: return A = B +*/ + + /* step 2: numeric components +* +* Algorithm 3.2: Version comparison logic for numeric +* components +* 1: define the notations Ank and Bnk to mean the kth numeric +* component of A and B respectively, using 0-based indexing +* 2: if An0 > Bn0 using integer comparison then +* 3:return A > B +* 4: else if An0 < Bn0 using integer comparison then +* 5:return A < B +* 6: end if +* 7: let Ann be the number of numeric components of A +* 8: let Bnn be the number of numeric components of B +* 9: for all i such that i ≥ 1 and i < Ann and i < Bnn, in +* ascending order do +* 10:compare Ani and Bni using Algorithm 3.3 +* 11: end for +* 12: if Ann > Bnn then +* 13:return A > B +* 14: else if Ann < Bnn then +* 15:return A < B +* 16: end if +* +* Algorithm 3.3: Version comparison logic for each numeric +* component after the first +* 1: if either Ani or Bni has a leading 0 then +* 2:let An′i be Ani with any trailing 0s removed +* 3:let Bn′i be Bni with any trailing 0s removed +* 4:if An′i > Bn′i using ASCII stringwise comparison then +* 5: return A > B +* 6:else if An′i < Bn′i using ASCII stringwise comparison then +* 7: return A < B +* 8:end if +* 9: else +* 10:if Ani > Bni using integer comparison then +* 11: return A > B +* 12:else if Ani < Bni using integer comparison then +* 13: return A < B +* 14:end if +* 15: end
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/
commit: 7de2f154c775e9de276f2fc1f619922f48a13b90 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 18 09:35:48 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 18 09:35:48 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7de2f154 libq/atom: implement strict PMS 3.3 in atom_compare Version comparisons are complex, stick with strict PMS definition for it, so we produce the same results as Portage. Bug: https://bugs.gentoo.org/838856 Signed-off-by: Fabian Groffen gentoo.org> autogen.sh| 1 + libq/atom.c | 249 -- tests/atom_compare/static.q.good | 3 +- tests/atom_compare/static.q.tests | 1 + 4 files changed, 219 insertions(+), 35 deletions(-) diff --git a/autogen.sh b/autogen.sh index ea564e0..df6e574 100755 --- a/autogen.sh +++ b/autogen.sh @@ -43,6 +43,7 @@ mods=" stat-time strcasestr-simple strncat + strtoll symlinkat sys_stat unlinkat diff --git a/libq/atom.c b/libq/atom.c index 0b5fcdd..d1eb9a4 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2021 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd- @@ -694,41 +694,170 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) /* check version */ if (data->PV && query->PV) { - char *s1, *s2; - uint64_t n1, n2; - /* first we compare the version [1.0]z_alpha1 */ - s1 = data->PV; - s2 = query->PV; - while (s1 || s2) { - if (s1 && s2) { - /* deal with leading zeros */ - while (*s1 == '0' && *s2 == '0') { - ++s1; - ++s2; + char *s1; + char *ends1; + char *s2; + char *ends2; + long long n1; + long long n2; + const atom_suffix *as1; + const atom_suffix *as2; + + /* PMS 3.3 Version Comparison +* +* Algorithm 3.1: Version comparison top-level logic +* 1: let A and B be the versions to be compared +* 2: compare numeric components using Algorithm 3.2 +* 3: compare letter components using Algorithm 3.4 +* 4: compare suffixes using Algorithm 3.5 +* 5: compare revision components using Algorithm 3.7 +* 6: return A = B +*/ + + /* step 2: numeric components +* +* Algorithm 3.2: Version comparison logic for numeric +* components +* 1: define the notations Ank and Bnk to mean the kth numeric +* component of A and B respectively, using 0-based indexing +* 2: if An0 > Bn0 using integer comparison then +* 3:return A > B +* 4: else if An0 < Bn0 using integer comparison then +* 5:return A < B +* 6: end if +* 7: let Ann be the number of numeric components of A +* 8: let Bnn be the number of numeric components of B +* 9: for all i such that i ≥ 1 and i < Ann and i < Bnn, in +* ascending order do +* 10:compare Ani and Bni using Algorithm 3.3 +* 11: end for +* 12: if Ann > Bnn then +* 13:return A > B +* 14: else if Ann < Bnn then +* 15:return A < B +* 16: end if +* +* Algorithm 3.3: Version comparison logic for each numeric +* component after the first +* 1: if either Ani or Bni has a leading 0 then +* 2:let An′i be Ani with any trailing 0s removed +* 3:let Bn′i be Bni with any trailing 0s removed +* 4:if An′i > Bn′i using ASCII stringwise comparison then +* 5: return A > B +* 6:else if An′i < Bn′i using ASCII stringwise comparison then +* 7: return A < B +* 8:end if +* 9: else +* 10:if Ani > Bni using integer comparison then +* 11: return A > B +* 12:else if Ani < Bni using integer comparison then +* 13: return A < B +* 14:end if +* 15: end
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, libq/
commit: 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 15 19:53:43 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Wed Jun 15 19:53:43 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd libq/atom: fix atom_compare for "0" version components Bug: https://bugs.gentoo.org/852197 Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 36 ++-- tests/atom_compare/static.good | 1 + tests/atom_compare/static.tests | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 50e9520..31299f1 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) *ends1 != '_'; ends1++) ; + if (ends1 != s1) + ends1--; for (ends2 = s2; *ends2 != '\0' && *ends2 != '.' && *ends2 != '_'; ends2++) ; - /* 3.3L2-3: remove *trailing* zeros */ - for (ends1--; ends1 > s1 && *ends1 == '0'; ends1--) - ; - for (ends2--; ends2 > s2 && *ends2 == '0'; ends2--) - ; - /* 3.3L4 ASCII stringwise comparison */ - n1 = ends1 - s1; - n2 = ends2 - s2; - n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); - n2 = 0; + if (ends2 != s2) + ends2--; + /* bug 852197: leading 0 means something else +* must follow */ + if (ends1 - s1 > 1 || ends2 - s2 > 1) { + /* 3.3L2-3: remove *trailing* zeros */ + for (; ends1 > s1 && *ends1 == '0'; ends1--) + ; + for (; ends2 > s2 && *ends2 == '0'; ends2--) + ; + /* 3.3L4 ASCII stringwise comparison */ + n1 = ends1 - s1; + n2 = ends2 - s2; + n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); + n2 = 0; + } else { + /* repeat of 3.3#L9 (else case below) */ + n1 = strtoll(s1, &ends1, 10); + if (ends1 == s1) + n1 = -1; + n2 = strtoll(s2, &ends2, 10); + if (ends2 == s2) + n2 = -1; + } } else { /* 3.3#L9 */ n1 = strtoll(s1, &ends1, 10); if (ends1 == s1) diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good index 6da5553..83bf7ec 100644 --- a/tests/atom_compare/static.good +++ b/tests/atom_compare/static.good @@ -52,3 +52,4 @@ a-1 != =a-1.2z* a-1_alpha1 == =a-1* a-1 != =a-1_alpha1* a-1_alpha-r1 == =a-1_alpha* +a-3.10.5 == >=a-3.10.0_p1_r1 diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests index 168f358..213fb5e 100644 --- a/tests/atom_compare/static.tests +++ b/tests/atom_compare/static.tests @@ -52,3 +52,4 @@ a-1 =a-1.2
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/
commit: 7de2f154c775e9de276f2fc1f619922f48a13b90 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 18 09:35:48 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 18 09:35:48 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7de2f154 libq/atom: implement strict PMS 3.3 in atom_compare Version comparisons are complex, stick with strict PMS definition for it, so we produce the same results as Portage. Bug: https://bugs.gentoo.org/838856 Signed-off-by: Fabian Groffen gentoo.org> autogen.sh| 1 + libq/atom.c | 249 -- tests/atom_compare/static.q.good | 3 +- tests/atom_compare/static.q.tests | 1 + 4 files changed, 219 insertions(+), 35 deletions(-) diff --git a/autogen.sh b/autogen.sh index ea564e0..df6e574 100755 --- a/autogen.sh +++ b/autogen.sh @@ -43,6 +43,7 @@ mods=" stat-time strcasestr-simple strncat + strtoll symlinkat sys_stat unlinkat diff --git a/libq/atom.c b/libq/atom.c index 0b5fcdd..d1eb9a4 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2021 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd- @@ -694,41 +694,170 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) /* check version */ if (data->PV && query->PV) { - char *s1, *s2; - uint64_t n1, n2; - /* first we compare the version [1.0]z_alpha1 */ - s1 = data->PV; - s2 = query->PV; - while (s1 || s2) { - if (s1 && s2) { - /* deal with leading zeros */ - while (*s1 == '0' && *s2 == '0') { - ++s1; - ++s2; + char *s1; + char *ends1; + char *s2; + char *ends2; + long long n1; + long long n2; + const atom_suffix *as1; + const atom_suffix *as2; + + /* PMS 3.3 Version Comparison +* +* Algorithm 3.1: Version comparison top-level logic +* 1: let A and B be the versions to be compared +* 2: compare numeric components using Algorithm 3.2 +* 3: compare letter components using Algorithm 3.4 +* 4: compare suffixes using Algorithm 3.5 +* 5: compare revision components using Algorithm 3.7 +* 6: return A = B +*/ + + /* step 2: numeric components +* +* Algorithm 3.2: Version comparison logic for numeric +* components +* 1: define the notations Ank and Bnk to mean the kth numeric +* component of A and B respectively, using 0-based indexing +* 2: if An0 > Bn0 using integer comparison then +* 3:return A > B +* 4: else if An0 < Bn0 using integer comparison then +* 5:return A < B +* 6: end if +* 7: let Ann be the number of numeric components of A +* 8: let Bnn be the number of numeric components of B +* 9: for all i such that i ≥ 1 and i < Ann and i < Bnn, in +* ascending order do +* 10:compare Ani and Bni using Algorithm 3.3 +* 11: end for +* 12: if Ann > Bnn then +* 13:return A > B +* 14: else if Ann < Bnn then +* 15:return A < B +* 16: end if +* +* Algorithm 3.3: Version comparison logic for each numeric +* component after the first +* 1: if either Ani or Bni has a leading 0 then +* 2:let An′i be Ani with any trailing 0s removed +* 3:let Bn′i be Bni with any trailing 0s removed +* 4:if An′i > Bn′i using ASCII stringwise comparison then +* 5: return A > B +* 6:else if An′i < Bn′i using ASCII stringwise comparison then +* 7: return A < B +* 8:end if +* 9: else +* 10:if Ani > Bni using integer comparison then +* 11: return A > B +* 12:else if Ani < Bni using integer comparison then +* 13: return A < B +* 14:end if +* 15: end
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, libq/
commit: 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 15 19:53:43 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Wed Jun 15 19:53:43 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd libq/atom: fix atom_compare for "0" version components Bug: https://bugs.gentoo.org/852197 Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 36 ++-- tests/atom_compare/static.good | 1 + tests/atom_compare/static.tests | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 50e9520..31299f1 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) *ends1 != '_'; ends1++) ; + if (ends1 != s1) + ends1--; for (ends2 = s2; *ends2 != '\0' && *ends2 != '.' && *ends2 != '_'; ends2++) ; - /* 3.3L2-3: remove *trailing* zeros */ - for (ends1--; ends1 > s1 && *ends1 == '0'; ends1--) - ; - for (ends2--; ends2 > s2 && *ends2 == '0'; ends2--) - ; - /* 3.3L4 ASCII stringwise comparison */ - n1 = ends1 - s1; - n2 = ends2 - s2; - n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); - n2 = 0; + if (ends2 != s2) + ends2--; + /* bug 852197: leading 0 means something else +* must follow */ + if (ends1 - s1 > 1 || ends2 - s2 > 1) { + /* 3.3L2-3: remove *trailing* zeros */ + for (; ends1 > s1 && *ends1 == '0'; ends1--) + ; + for (; ends2 > s2 && *ends2 == '0'; ends2--) + ; + /* 3.3L4 ASCII stringwise comparison */ + n1 = ends1 - s1; + n2 = ends2 - s2; + n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); + n2 = 0; + } else { + /* repeat of 3.3#L9 (else case below) */ + n1 = strtoll(s1, &ends1, 10); + if (ends1 == s1) + n1 = -1; + n2 = strtoll(s2, &ends2, 10); + if (ends2 == s2) + n2 = -1; + } } else { /* 3.3#L9 */ n1 = strtoll(s1, &ends1, 10); if (ends1 == s1) diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good index 6da5553..83bf7ec 100644 --- a/tests/atom_compare/static.good +++ b/tests/atom_compare/static.good @@ -52,3 +52,4 @@ a-1 != =a-1.2z* a-1_alpha1 == =a-1* a-1 != =a-1_alpha1* a-1_alpha-r1 == =a-1_alpha* +a-3.10.5 == >=a-3.10.0_p1_r1 diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests index 168f358..213fb5e 100644 --- a/tests/atom_compare/static.tests +++ b/tests/atom_compare/static.tests @@ -52,3 +52,4 @@ a-1 =a-1.2
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/
commit: 7de2f154c775e9de276f2fc1f619922f48a13b90 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 18 09:35:48 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 18 09:35:48 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7de2f154 libq/atom: implement strict PMS 3.3 in atom_compare Version comparisons are complex, stick with strict PMS definition for it, so we produce the same results as Portage. Bug: https://bugs.gentoo.org/838856 Signed-off-by: Fabian Groffen gentoo.org> autogen.sh| 1 + libq/atom.c | 249 -- tests/atom_compare/static.q.good | 3 +- tests/atom_compare/static.q.tests | 1 + 4 files changed, 219 insertions(+), 35 deletions(-) diff --git a/autogen.sh b/autogen.sh index ea564e0..df6e574 100755 --- a/autogen.sh +++ b/autogen.sh @@ -43,6 +43,7 @@ mods=" stat-time strcasestr-simple strncat + strtoll symlinkat sys_stat unlinkat diff --git a/libq/atom.c b/libq/atom.c index 0b5fcdd..d1eb9a4 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2021 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd- @@ -694,41 +694,170 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) /* check version */ if (data->PV && query->PV) { - char *s1, *s2; - uint64_t n1, n2; - /* first we compare the version [1.0]z_alpha1 */ - s1 = data->PV; - s2 = query->PV; - while (s1 || s2) { - if (s1 && s2) { - /* deal with leading zeros */ - while (*s1 == '0' && *s2 == '0') { - ++s1; - ++s2; + char *s1; + char *ends1; + char *s2; + char *ends2; + long long n1; + long long n2; + const atom_suffix *as1; + const atom_suffix *as2; + + /* PMS 3.3 Version Comparison +* +* Algorithm 3.1: Version comparison top-level logic +* 1: let A and B be the versions to be compared +* 2: compare numeric components using Algorithm 3.2 +* 3: compare letter components using Algorithm 3.4 +* 4: compare suffixes using Algorithm 3.5 +* 5: compare revision components using Algorithm 3.7 +* 6: return A = B +*/ + + /* step 2: numeric components +* +* Algorithm 3.2: Version comparison logic for numeric +* components +* 1: define the notations Ank and Bnk to mean the kth numeric +* component of A and B respectively, using 0-based indexing +* 2: if An0 > Bn0 using integer comparison then +* 3:return A > B +* 4: else if An0 < Bn0 using integer comparison then +* 5:return A < B +* 6: end if +* 7: let Ann be the number of numeric components of A +* 8: let Bnn be the number of numeric components of B +* 9: for all i such that i ≥ 1 and i < Ann and i < Bnn, in +* ascending order do +* 10:compare Ani and Bni using Algorithm 3.3 +* 11: end for +* 12: if Ann > Bnn then +* 13:return A > B +* 14: else if Ann < Bnn then +* 15:return A < B +* 16: end if +* +* Algorithm 3.3: Version comparison logic for each numeric +* component after the first +* 1: if either Ani or Bni has a leading 0 then +* 2:let An′i be Ani with any trailing 0s removed +* 3:let Bn′i be Bni with any trailing 0s removed +* 4:if An′i > Bn′i using ASCII stringwise comparison then +* 5: return A > B +* 6:else if An′i < Bn′i using ASCII stringwise comparison then +* 7: return A < B +* 8:end if +* 9: else +* 10:if Ani > Bni using integer comparison then +* 11: return A > B +* 12:else if Ani < Bni using integer comparison then +* 13: return A < B +* 14:end if +* 15: end
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, libq/
commit: 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 15 19:53:43 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Wed Jun 15 19:53:43 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd libq/atom: fix atom_compare for "0" version components Bug: https://bugs.gentoo.org/852197 Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 36 ++-- tests/atom_compare/static.good | 1 + tests/atom_compare/static.tests | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 50e9520..31299f1 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) *ends1 != '_'; ends1++) ; + if (ends1 != s1) + ends1--; for (ends2 = s2; *ends2 != '\0' && *ends2 != '.' && *ends2 != '_'; ends2++) ; - /* 3.3L2-3: remove *trailing* zeros */ - for (ends1--; ends1 > s1 && *ends1 == '0'; ends1--) - ; - for (ends2--; ends2 > s2 && *ends2 == '0'; ends2--) - ; - /* 3.3L4 ASCII stringwise comparison */ - n1 = ends1 - s1; - n2 = ends2 - s2; - n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); - n2 = 0; + if (ends2 != s2) + ends2--; + /* bug 852197: leading 0 means something else +* must follow */ + if (ends1 - s1 > 1 || ends2 - s2 > 1) { + /* 3.3L2-3: remove *trailing* zeros */ + for (; ends1 > s1 && *ends1 == '0'; ends1--) + ; + for (; ends2 > s2 && *ends2 == '0'; ends2--) + ; + /* 3.3L4 ASCII stringwise comparison */ + n1 = ends1 - s1; + n2 = ends2 - s2; + n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); + n2 = 0; + } else { + /* repeat of 3.3#L9 (else case below) */ + n1 = strtoll(s1, &ends1, 10); + if (ends1 == s1) + n1 = -1; + n2 = strtoll(s2, &ends2, 10); + if (ends2 == s2) + n2 = -1; + } } else { /* 3.3#L9 */ n1 = strtoll(s1, &ends1, 10); if (ends1 == s1) diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good index 6da5553..83bf7ec 100644 --- a/tests/atom_compare/static.good +++ b/tests/atom_compare/static.good @@ -52,3 +52,4 @@ a-1 != =a-1.2z* a-1_alpha1 == =a-1* a-1 != =a-1_alpha1* a-1_alpha-r1 == =a-1_alpha* +a-3.10.5 == >=a-3.10.0_p1_r1 diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests index 168f358..213fb5e 100644 --- a/tests/atom_compare/static.tests +++ b/tests/atom_compare/static.tests @@ -52,3 +52,4 @@ a-1 =a-1.2
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/
commit: 7de2f154c775e9de276f2fc1f619922f48a13b90 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 18 09:35:48 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 18 09:35:48 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7de2f154 libq/atom: implement strict PMS 3.3 in atom_compare Version comparisons are complex, stick with strict PMS definition for it, so we produce the same results as Portage. Bug: https://bugs.gentoo.org/838856 Signed-off-by: Fabian Groffen gentoo.org> autogen.sh| 1 + libq/atom.c | 249 -- tests/atom_compare/static.q.good | 3 +- tests/atom_compare/static.q.tests | 1 + 4 files changed, 219 insertions(+), 35 deletions(-) diff --git a/autogen.sh b/autogen.sh index ea564e0..df6e574 100755 --- a/autogen.sh +++ b/autogen.sh @@ -43,6 +43,7 @@ mods=" stat-time strcasestr-simple strncat + strtoll symlinkat sys_stat unlinkat diff --git a/libq/atom.c b/libq/atom.c index 0b5fcdd..d1eb9a4 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2021 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd- @@ -694,41 +694,170 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) /* check version */ if (data->PV && query->PV) { - char *s1, *s2; - uint64_t n1, n2; - /* first we compare the version [1.0]z_alpha1 */ - s1 = data->PV; - s2 = query->PV; - while (s1 || s2) { - if (s1 && s2) { - /* deal with leading zeros */ - while (*s1 == '0' && *s2 == '0') { - ++s1; - ++s2; + char *s1; + char *ends1; + char *s2; + char *ends2; + long long n1; + long long n2; + const atom_suffix *as1; + const atom_suffix *as2; + + /* PMS 3.3 Version Comparison +* +* Algorithm 3.1: Version comparison top-level logic +* 1: let A and B be the versions to be compared +* 2: compare numeric components using Algorithm 3.2 +* 3: compare letter components using Algorithm 3.4 +* 4: compare suffixes using Algorithm 3.5 +* 5: compare revision components using Algorithm 3.7 +* 6: return A = B +*/ + + /* step 2: numeric components +* +* Algorithm 3.2: Version comparison logic for numeric +* components +* 1: define the notations Ank and Bnk to mean the kth numeric +* component of A and B respectively, using 0-based indexing +* 2: if An0 > Bn0 using integer comparison then +* 3:return A > B +* 4: else if An0 < Bn0 using integer comparison then +* 5:return A < B +* 6: end if +* 7: let Ann be the number of numeric components of A +* 8: let Bnn be the number of numeric components of B +* 9: for all i such that i ≥ 1 and i < Ann and i < Bnn, in +* ascending order do +* 10:compare Ani and Bni using Algorithm 3.3 +* 11: end for +* 12: if Ann > Bnn then +* 13:return A > B +* 14: else if Ann < Bnn then +* 15:return A < B +* 16: end if +* +* Algorithm 3.3: Version comparison logic for each numeric +* component after the first +* 1: if either Ani or Bni has a leading 0 then +* 2:let An′i be Ani with any trailing 0s removed +* 3:let Bn′i be Bni with any trailing 0s removed +* 4:if An′i > Bn′i using ASCII stringwise comparison then +* 5: return A > B +* 6:else if An′i < Bn′i using ASCII stringwise comparison then +* 7: return A < B +* 8:end if +* 9: else +* 10:if Ani > Bni using integer comparison then +* 11: return A > B +* 12:else if Ani < Bni using integer comparison then +* 13: return A < B +* 14:end if +* 15: end
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/
commit: 7de2f154c775e9de276f2fc1f619922f48a13b90 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 18 09:35:48 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 18 09:35:48 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7de2f154 libq/atom: implement strict PMS 3.3 in atom_compare Version comparisons are complex, stick with strict PMS definition for it, so we produce the same results as Portage. Bug: https://bugs.gentoo.org/838856 Signed-off-by: Fabian Groffen gentoo.org> autogen.sh| 1 + libq/atom.c | 249 -- tests/atom_compare/static.q.good | 3 +- tests/atom_compare/static.q.tests | 1 + 4 files changed, 219 insertions(+), 35 deletions(-) diff --git a/autogen.sh b/autogen.sh index ea564e0..df6e574 100755 --- a/autogen.sh +++ b/autogen.sh @@ -43,6 +43,7 @@ mods=" stat-time strcasestr-simple strncat + strtoll symlinkat sys_stat unlinkat diff --git a/libq/atom.c b/libq/atom.c index 0b5fcdd..d1eb9a4 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2021 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd- @@ -694,41 +694,170 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) /* check version */ if (data->PV && query->PV) { - char *s1, *s2; - uint64_t n1, n2; - /* first we compare the version [1.0]z_alpha1 */ - s1 = data->PV; - s2 = query->PV; - while (s1 || s2) { - if (s1 && s2) { - /* deal with leading zeros */ - while (*s1 == '0' && *s2 == '0') { - ++s1; - ++s2; + char *s1; + char *ends1; + char *s2; + char *ends2; + long long n1; + long long n2; + const atom_suffix *as1; + const atom_suffix *as2; + + /* PMS 3.3 Version Comparison +* +* Algorithm 3.1: Version comparison top-level logic +* 1: let A and B be the versions to be compared +* 2: compare numeric components using Algorithm 3.2 +* 3: compare letter components using Algorithm 3.4 +* 4: compare suffixes using Algorithm 3.5 +* 5: compare revision components using Algorithm 3.7 +* 6: return A = B +*/ + + /* step 2: numeric components +* +* Algorithm 3.2: Version comparison logic for numeric +* components +* 1: define the notations Ank and Bnk to mean the kth numeric +* component of A and B respectively, using 0-based indexing +* 2: if An0 > Bn0 using integer comparison then +* 3:return A > B +* 4: else if An0 < Bn0 using integer comparison then +* 5:return A < B +* 6: end if +* 7: let Ann be the number of numeric components of A +* 8: let Bnn be the number of numeric components of B +* 9: for all i such that i ≥ 1 and i < Ann and i < Bnn, in +* ascending order do +* 10:compare Ani and Bni using Algorithm 3.3 +* 11: end for +* 12: if Ann > Bnn then +* 13:return A > B +* 14: else if Ann < Bnn then +* 15:return A < B +* 16: end if +* +* Algorithm 3.3: Version comparison logic for each numeric +* component after the first +* 1: if either Ani or Bni has a leading 0 then +* 2:let An′i be Ani with any trailing 0s removed +* 3:let Bn′i be Bni with any trailing 0s removed +* 4:if An′i > Bn′i using ASCII stringwise comparison then +* 5: return A > B +* 6:else if An′i < Bn′i using ASCII stringwise comparison then +* 7: return A < B +* 8:end if +* 9: else +* 10:if Ani > Bni using integer comparison then +* 11: return A > B +* 12:else if Ani < Bni using integer comparison then +* 13: return A < B +* 14:end if +* 15: end
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, libq/
commit: 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 15 19:53:43 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Wed Jun 15 19:53:43 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd libq/atom: fix atom_compare for "0" version components Bug: https://bugs.gentoo.org/852197 Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 36 ++-- tests/atom_compare/static.good | 1 + tests/atom_compare/static.tests | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 50e9520..31299f1 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) *ends1 != '_'; ends1++) ; + if (ends1 != s1) + ends1--; for (ends2 = s2; *ends2 != '\0' && *ends2 != '.' && *ends2 != '_'; ends2++) ; - /* 3.3L2-3: remove *trailing* zeros */ - for (ends1--; ends1 > s1 && *ends1 == '0'; ends1--) - ; - for (ends2--; ends2 > s2 && *ends2 == '0'; ends2--) - ; - /* 3.3L4 ASCII stringwise comparison */ - n1 = ends1 - s1; - n2 = ends2 - s2; - n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); - n2 = 0; + if (ends2 != s2) + ends2--; + /* bug 852197: leading 0 means something else +* must follow */ + if (ends1 - s1 > 1 || ends2 - s2 > 1) { + /* 3.3L2-3: remove *trailing* zeros */ + for (; ends1 > s1 && *ends1 == '0'; ends1--) + ; + for (; ends2 > s2 && *ends2 == '0'; ends2--) + ; + /* 3.3L4 ASCII stringwise comparison */ + n1 = ends1 - s1; + n2 = ends2 - s2; + n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); + n2 = 0; + } else { + /* repeat of 3.3#L9 (else case below) */ + n1 = strtoll(s1, &ends1, 10); + if (ends1 == s1) + n1 = -1; + n2 = strtoll(s2, &ends2, 10); + if (ends2 == s2) + n2 = -1; + } } else { /* 3.3#L9 */ n1 = strtoll(s1, &ends1, 10); if (ends1 == s1) diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good index 6da5553..83bf7ec 100644 --- a/tests/atom_compare/static.good +++ b/tests/atom_compare/static.good @@ -52,3 +52,4 @@ a-1 != =a-1.2z* a-1_alpha1 == =a-1* a-1 != =a-1_alpha1* a-1_alpha-r1 == =a-1_alpha* +a-3.10.5 == >=a-3.10.0_p1_r1 diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests index 168f358..213fb5e 100644 --- a/tests/atom_compare/static.tests +++ b/tests/atom_compare/static.tests @@ -52,3 +52,4 @@ a-1 =a-1.2
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/
commit: 7de2f154c775e9de276f2fc1f619922f48a13b90 Author: Fabian Groffen gentoo org> AuthorDate: Mon Apr 18 09:35:48 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Mon Apr 18 09:35:48 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7de2f154 libq/atom: implement strict PMS 3.3 in atom_compare Version comparisons are complex, stick with strict PMS definition for it, so we produce the same results as Portage. Bug: https://bugs.gentoo.org/838856 Signed-off-by: Fabian Groffen gentoo.org> autogen.sh| 1 + libq/atom.c | 249 -- tests/atom_compare/static.q.good | 3 +- tests/atom_compare/static.q.tests | 1 + 4 files changed, 219 insertions(+), 35 deletions(-) diff --git a/autogen.sh b/autogen.sh index ea564e0..df6e574 100755 --- a/autogen.sh +++ b/autogen.sh @@ -43,6 +43,7 @@ mods=" stat-time strcasestr-simple strncat + strtoll symlinkat sys_stat unlinkat diff --git a/libq/atom.c b/libq/atom.c index 0b5fcdd..d1eb9a4 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2021 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd- @@ -694,41 +694,170 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) /* check version */ if (data->PV && query->PV) { - char *s1, *s2; - uint64_t n1, n2; - /* first we compare the version [1.0]z_alpha1 */ - s1 = data->PV; - s2 = query->PV; - while (s1 || s2) { - if (s1 && s2) { - /* deal with leading zeros */ - while (*s1 == '0' && *s2 == '0') { - ++s1; - ++s2; + char *s1; + char *ends1; + char *s2; + char *ends2; + long long n1; + long long n2; + const atom_suffix *as1; + const atom_suffix *as2; + + /* PMS 3.3 Version Comparison +* +* Algorithm 3.1: Version comparison top-level logic +* 1: let A and B be the versions to be compared +* 2: compare numeric components using Algorithm 3.2 +* 3: compare letter components using Algorithm 3.4 +* 4: compare suffixes using Algorithm 3.5 +* 5: compare revision components using Algorithm 3.7 +* 6: return A = B +*/ + + /* step 2: numeric components +* +* Algorithm 3.2: Version comparison logic for numeric +* components +* 1: define the notations Ank and Bnk to mean the kth numeric +* component of A and B respectively, using 0-based indexing +* 2: if An0 > Bn0 using integer comparison then +* 3:return A > B +* 4: else if An0 < Bn0 using integer comparison then +* 5:return A < B +* 6: end if +* 7: let Ann be the number of numeric components of A +* 8: let Bnn be the number of numeric components of B +* 9: for all i such that i ≥ 1 and i < Ann and i < Bnn, in +* ascending order do +* 10:compare Ani and Bni using Algorithm 3.3 +* 11: end for +* 12: if Ann > Bnn then +* 13:return A > B +* 14: else if Ann < Bnn then +* 15:return A < B +* 16: end if +* +* Algorithm 3.3: Version comparison logic for each numeric +* component after the first +* 1: if either Ani or Bni has a leading 0 then +* 2:let An′i be Ani with any trailing 0s removed +* 3:let Bn′i be Bni with any trailing 0s removed +* 4:if An′i > Bn′i using ASCII stringwise comparison then +* 5: return A > B +* 6:else if An′i < Bn′i using ASCII stringwise comparison then +* 7: return A < B +* 8:end if +* 9: else +* 10:if Ani > Bni using integer comparison then +* 11: return A > B +* 12:else if Ani < Bni using integer comparison then +* 13: return A < B +* 14:end if +* 15: end
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, libq/
commit: 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 15 19:53:43 2022 + Commit: Fabian Groffen gentoo org> CommitDate: Wed Jun 15 19:53:43 2022 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd libq/atom: fix atom_compare for "0" version components Bug: https://bugs.gentoo.org/852197 Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 36 ++-- tests/atom_compare/static.good | 1 + tests/atom_compare/static.tests | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 50e9520..31299f1 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags) *ends1 != '_'; ends1++) ; + if (ends1 != s1) + ends1--; for (ends2 = s2; *ends2 != '\0' && *ends2 != '.' && *ends2 != '_'; ends2++) ; - /* 3.3L2-3: remove *trailing* zeros */ - for (ends1--; ends1 > s1 && *ends1 == '0'; ends1--) - ; - for (ends2--; ends2 > s2 && *ends2 == '0'; ends2--) - ; - /* 3.3L4 ASCII stringwise comparison */ - n1 = ends1 - s1; - n2 = ends2 - s2; - n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); - n2 = 0; + if (ends2 != s2) + ends2--; + /* bug 852197: leading 0 means something else +* must follow */ + if (ends1 - s1 > 1 || ends2 - s2 > 1) { + /* 3.3L2-3: remove *trailing* zeros */ + for (; ends1 > s1 && *ends1 == '0'; ends1--) + ; + for (; ends2 > s2 && *ends2 == '0'; ends2--) + ; + /* 3.3L4 ASCII stringwise comparison */ + n1 = ends1 - s1; + n2 = ends2 - s2; + n1 = strncmp(s1, s2, n1 > n2 ? n1 : n2); + n2 = 0; + } else { + /* repeat of 3.3#L9 (else case below) */ + n1 = strtoll(s1, &ends1, 10); + if (ends1 == s1) + n1 = -1; + n2 = strtoll(s2, &ends2, 10); + if (ends2 == s2) + n2 = -1; + } } else { /* 3.3#L9 */ n1 = strtoll(s1, &ends1, 10); if (ends1 == s1) diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good index 6da5553..83bf7ec 100644 --- a/tests/atom_compare/static.good +++ b/tests/atom_compare/static.good @@ -52,3 +52,4 @@ a-1 != =a-1.2z* a-1_alpha1 == =a-1* a-1 != =a-1_alpha1* a-1_alpha-r1 == =a-1_alpha* +a-3.10.5 == >=a-3.10.0_p1_r1 diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests index 168f358..213fb5e 100644 --- a/tests/atom_compare/static.tests +++ b/tests/atom_compare/static.tests @@ -52,3 +52,4 @@ a-1 =a-1.2
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/, man/, tests/qatom/
commit: 199e4f62b4ede5f2319ef6795a15737ac0882d09 Author: Fabian Groffen gentoo org> AuthorDate: Sun Apr 7 20:06:20 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Sun Apr 7 20:14:35 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=199e4f62 atoms: add proper support for blockers and USE dependencies - ignore SLOT in atom_compare when not set on both sides - parse USE-dependencies, properly removing it from PV - parse blockers (! and !!) separate from version ranges, such that the original meaning can be restored and differentiated from Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 250 --- libq/atom.h | 66 --- man/qatom.1 | 5 +- qatom.c | 40 +-- tests/atom_compare/static.good | 4 +- tests/atom_compare/static.q.good | 2 +- tests/atom_compare/static.tests | 4 +- tests/qatom/dotest | 22 8 files changed, 298 insertions(+), 95 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 60a37ce..4c06c1a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -16,16 +16,28 @@ #include #include -const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; - const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; +const char * const atom_slotdep_str[] = { + "", "=", "*" +}; + +const char * const atom_usecond_str[] = { + "", "!", "-", "?", "=", "(+)", "(-)" +}; + +const char * const atom_blocker_str[] = { + "", "!", "!!" +}; + const char * const atom_op_str[] = { - "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" + "", "=", ">", ">=", "<", "<=", "~", "*" }; +const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; + #ifdef EBUG void atom_print(const depend_atom *atom) @@ -52,7 +64,10 @@ atom_explode(const char *atom) { depend_atom *ret; char *ptr; - size_t len, slen, idx, sidx; + size_t len; + size_t slen; + size_t idx; + size_t sidx; /* we allocate mem for atom struct and two strings (strlen(atom)). * the first string is for CAT/PN/PV while the second is for PVR. @@ -76,61 +91,37 @@ atom_explode(const char *atom) ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + /* check for blocker operators */ + ret->blocker = ATOM_BL_NONE; + if (*atom == '!') { + ret->blocker++; + atom++; + } + if (*atom == '!') { + ret->blocker++; + atom++; + } + /* eat any prefix operators */ - switch (atom[0]) { + ret->pfx_op = ATOM_OP_NONE; + switch (*atom) { case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - } else - ret->pfx_op = ATOM_OP_NEWER; - break; - case '=': - ++atom; - ret->pfx_op = ATOM_OP_EQUAL; + ret->pfx_op = ATOM_OP_NEWER; + atom++; break; case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - } else - ret->pfx_op = ATOM_OP_OLDER; + ret->pfx_op = ATOM_OP_OLDER; + atom++; break; case '~': - ++atom; ret->pfx_op = ATOM_OP_PV_EQUAL; - break; - case '!': - ++atom; - switch (atom[0]) { - case '!': - ++atom; - ret->pfx_op = ATOM_OP_BLOCK_HARD; - break; - case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER; - } else - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - break; - case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER; - } else - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - break; - default: - ret->pfx_op = ATOM_OP_BLOCK; - break; - } + atom++; break; } + if (*atom == '=') { + ret->pfx_op += ATOM_OP_EQUAL; + atom++; + } strcpy(ret->CATEGORY, atom); /* eat file name crap when given
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/, man/, tests/qatom/
commit: 199e4f62b4ede5f2319ef6795a15737ac0882d09 Author: Fabian Groffen gentoo org> AuthorDate: Sun Apr 7 20:06:20 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Sun Apr 7 20:14:35 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=199e4f62 atoms: add proper support for blockers and USE dependencies - ignore SLOT in atom_compare when not set on both sides - parse USE-dependencies, properly removing it from PV - parse blockers (! and !!) separate from version ranges, such that the original meaning can be restored and differentiated from Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 250 --- libq/atom.h | 66 --- man/qatom.1 | 5 +- qatom.c | 40 +-- tests/atom_compare/static.good | 4 +- tests/atom_compare/static.q.good | 2 +- tests/atom_compare/static.tests | 4 +- tests/qatom/dotest | 22 8 files changed, 298 insertions(+), 95 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 60a37ce..4c06c1a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -16,16 +16,28 @@ #include #include -const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; - const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; +const char * const atom_slotdep_str[] = { + "", "=", "*" +}; + +const char * const atom_usecond_str[] = { + "", "!", "-", "?", "=", "(+)", "(-)" +}; + +const char * const atom_blocker_str[] = { + "", "!", "!!" +}; + const char * const atom_op_str[] = { - "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" + "", "=", ">", ">=", "<", "<=", "~", "*" }; +const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; + #ifdef EBUG void atom_print(const depend_atom *atom) @@ -52,7 +64,10 @@ atom_explode(const char *atom) { depend_atom *ret; char *ptr; - size_t len, slen, idx, sidx; + size_t len; + size_t slen; + size_t idx; + size_t sidx; /* we allocate mem for atom struct and two strings (strlen(atom)). * the first string is for CAT/PN/PV while the second is for PVR. @@ -76,61 +91,37 @@ atom_explode(const char *atom) ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + /* check for blocker operators */ + ret->blocker = ATOM_BL_NONE; + if (*atom == '!') { + ret->blocker++; + atom++; + } + if (*atom == '!') { + ret->blocker++; + atom++; + } + /* eat any prefix operators */ - switch (atom[0]) { + ret->pfx_op = ATOM_OP_NONE; + switch (*atom) { case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - } else - ret->pfx_op = ATOM_OP_NEWER; - break; - case '=': - ++atom; - ret->pfx_op = ATOM_OP_EQUAL; + ret->pfx_op = ATOM_OP_NEWER; + atom++; break; case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - } else - ret->pfx_op = ATOM_OP_OLDER; + ret->pfx_op = ATOM_OP_OLDER; + atom++; break; case '~': - ++atom; ret->pfx_op = ATOM_OP_PV_EQUAL; - break; - case '!': - ++atom; - switch (atom[0]) { - case '!': - ++atom; - ret->pfx_op = ATOM_OP_BLOCK_HARD; - break; - case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER; - } else - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - break; - case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER; - } else - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - break; - default: - ret->pfx_op = ATOM_OP_BLOCK; - break; - } + atom++; break; } + if (*atom == '=') { + ret->pfx_op += ATOM_OP_EQUAL; + atom++; + } strcpy(ret->CATEGORY, atom); /* eat file name crap when given
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/, man/, tests/qatom/
commit: 199e4f62b4ede5f2319ef6795a15737ac0882d09 Author: Fabian Groffen gentoo org> AuthorDate: Sun Apr 7 20:06:20 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Sun Apr 7 20:14:35 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=199e4f62 atoms: add proper support for blockers and USE dependencies - ignore SLOT in atom_compare when not set on both sides - parse USE-dependencies, properly removing it from PV - parse blockers (! and !!) separate from version ranges, such that the original meaning can be restored and differentiated from Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 250 --- libq/atom.h | 66 --- man/qatom.1 | 5 +- qatom.c | 40 +-- tests/atom_compare/static.good | 4 +- tests/atom_compare/static.q.good | 2 +- tests/atom_compare/static.tests | 4 +- tests/qatom/dotest | 22 8 files changed, 298 insertions(+), 95 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 60a37ce..4c06c1a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -16,16 +16,28 @@ #include #include -const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; - const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; +const char * const atom_slotdep_str[] = { + "", "=", "*" +}; + +const char * const atom_usecond_str[] = { + "", "!", "-", "?", "=", "(+)", "(-)" +}; + +const char * const atom_blocker_str[] = { + "", "!", "!!" +}; + const char * const atom_op_str[] = { - "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" + "", "=", ">", ">=", "<", "<=", "~", "*" }; +const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; + #ifdef EBUG void atom_print(const depend_atom *atom) @@ -52,7 +64,10 @@ atom_explode(const char *atom) { depend_atom *ret; char *ptr; - size_t len, slen, idx, sidx; + size_t len; + size_t slen; + size_t idx; + size_t sidx; /* we allocate mem for atom struct and two strings (strlen(atom)). * the first string is for CAT/PN/PV while the second is for PVR. @@ -76,61 +91,37 @@ atom_explode(const char *atom) ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + /* check for blocker operators */ + ret->blocker = ATOM_BL_NONE; + if (*atom == '!') { + ret->blocker++; + atom++; + } + if (*atom == '!') { + ret->blocker++; + atom++; + } + /* eat any prefix operators */ - switch (atom[0]) { + ret->pfx_op = ATOM_OP_NONE; + switch (*atom) { case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - } else - ret->pfx_op = ATOM_OP_NEWER; - break; - case '=': - ++atom; - ret->pfx_op = ATOM_OP_EQUAL; + ret->pfx_op = ATOM_OP_NEWER; + atom++; break; case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - } else - ret->pfx_op = ATOM_OP_OLDER; + ret->pfx_op = ATOM_OP_OLDER; + atom++; break; case '~': - ++atom; ret->pfx_op = ATOM_OP_PV_EQUAL; - break; - case '!': - ++atom; - switch (atom[0]) { - case '!': - ++atom; - ret->pfx_op = ATOM_OP_BLOCK_HARD; - break; - case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER; - } else - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - break; - case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER; - } else - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - break; - default: - ret->pfx_op = ATOM_OP_BLOCK; - break; - } + atom++; break; } + if (*atom == '=') { + ret->pfx_op += ATOM_OP_EQUAL; + atom++; + } strcpy(ret->CATEGORY, atom); /* eat file name crap when given
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/, man/, tests/qatom/
commit: 199e4f62b4ede5f2319ef6795a15737ac0882d09 Author: Fabian Groffen gentoo org> AuthorDate: Sun Apr 7 20:06:20 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Sun Apr 7 20:14:35 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=199e4f62 atoms: add proper support for blockers and USE dependencies - ignore SLOT in atom_compare when not set on both sides - parse USE-dependencies, properly removing it from PV - parse blockers (! and !!) separate from version ranges, such that the original meaning can be restored and differentiated from Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 250 --- libq/atom.h | 66 --- man/qatom.1 | 5 +- qatom.c | 40 +-- tests/atom_compare/static.good | 4 +- tests/atom_compare/static.q.good | 2 +- tests/atom_compare/static.tests | 4 +- tests/qatom/dotest | 22 8 files changed, 298 insertions(+), 95 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 60a37ce..4c06c1a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -16,16 +16,28 @@ #include #include -const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; - const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; +const char * const atom_slotdep_str[] = { + "", "=", "*" +}; + +const char * const atom_usecond_str[] = { + "", "!", "-", "?", "=", "(+)", "(-)" +}; + +const char * const atom_blocker_str[] = { + "", "!", "!!" +}; + const char * const atom_op_str[] = { - "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" + "", "=", ">", ">=", "<", "<=", "~", "*" }; +const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; + #ifdef EBUG void atom_print(const depend_atom *atom) @@ -52,7 +64,10 @@ atom_explode(const char *atom) { depend_atom *ret; char *ptr; - size_t len, slen, idx, sidx; + size_t len; + size_t slen; + size_t idx; + size_t sidx; /* we allocate mem for atom struct and two strings (strlen(atom)). * the first string is for CAT/PN/PV while the second is for PVR. @@ -76,61 +91,37 @@ atom_explode(const char *atom) ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + /* check for blocker operators */ + ret->blocker = ATOM_BL_NONE; + if (*atom == '!') { + ret->blocker++; + atom++; + } + if (*atom == '!') { + ret->blocker++; + atom++; + } + /* eat any prefix operators */ - switch (atom[0]) { + ret->pfx_op = ATOM_OP_NONE; + switch (*atom) { case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - } else - ret->pfx_op = ATOM_OP_NEWER; - break; - case '=': - ++atom; - ret->pfx_op = ATOM_OP_EQUAL; + ret->pfx_op = ATOM_OP_NEWER; + atom++; break; case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - } else - ret->pfx_op = ATOM_OP_OLDER; + ret->pfx_op = ATOM_OP_OLDER; + atom++; break; case '~': - ++atom; ret->pfx_op = ATOM_OP_PV_EQUAL; - break; - case '!': - ++atom; - switch (atom[0]) { - case '!': - ++atom; - ret->pfx_op = ATOM_OP_BLOCK_HARD; - break; - case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER; - } else - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - break; - case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER; - } else - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - break; - default: - ret->pfx_op = ATOM_OP_BLOCK; - break; - } + atom++; break; } + if (*atom == '=') { + ret->pfx_op += ATOM_OP_EQUAL; + atom++; + } strcpy(ret->CATEGORY, atom); /* eat file name crap when given
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/, man/, tests/qatom/
commit: 199e4f62b4ede5f2319ef6795a15737ac0882d09 Author: Fabian Groffen gentoo org> AuthorDate: Sun Apr 7 20:06:20 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Sun Apr 7 20:14:35 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=199e4f62 atoms: add proper support for blockers and USE dependencies - ignore SLOT in atom_compare when not set on both sides - parse USE-dependencies, properly removing it from PV - parse blockers (! and !!) separate from version ranges, such that the original meaning can be restored and differentiated from Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 250 --- libq/atom.h | 66 --- man/qatom.1 | 5 +- qatom.c | 40 +-- tests/atom_compare/static.good | 4 +- tests/atom_compare/static.q.good | 2 +- tests/atom_compare/static.tests | 4 +- tests/qatom/dotest | 22 8 files changed, 298 insertions(+), 95 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 60a37ce..4c06c1a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -16,16 +16,28 @@ #include #include -const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; - const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; +const char * const atom_slotdep_str[] = { + "", "=", "*" +}; + +const char * const atom_usecond_str[] = { + "", "!", "-", "?", "=", "(+)", "(-)" +}; + +const char * const atom_blocker_str[] = { + "", "!", "!!" +}; + const char * const atom_op_str[] = { - "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" + "", "=", ">", ">=", "<", "<=", "~", "*" }; +const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; + #ifdef EBUG void atom_print(const depend_atom *atom) @@ -52,7 +64,10 @@ atom_explode(const char *atom) { depend_atom *ret; char *ptr; - size_t len, slen, idx, sidx; + size_t len; + size_t slen; + size_t idx; + size_t sidx; /* we allocate mem for atom struct and two strings (strlen(atom)). * the first string is for CAT/PN/PV while the second is for PVR. @@ -76,61 +91,37 @@ atom_explode(const char *atom) ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + /* check for blocker operators */ + ret->blocker = ATOM_BL_NONE; + if (*atom == '!') { + ret->blocker++; + atom++; + } + if (*atom == '!') { + ret->blocker++; + atom++; + } + /* eat any prefix operators */ - switch (atom[0]) { + ret->pfx_op = ATOM_OP_NONE; + switch (*atom) { case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - } else - ret->pfx_op = ATOM_OP_NEWER; - break; - case '=': - ++atom; - ret->pfx_op = ATOM_OP_EQUAL; + ret->pfx_op = ATOM_OP_NEWER; + atom++; break; case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - } else - ret->pfx_op = ATOM_OP_OLDER; + ret->pfx_op = ATOM_OP_OLDER; + atom++; break; case '~': - ++atom; ret->pfx_op = ATOM_OP_PV_EQUAL; - break; - case '!': - ++atom; - switch (atom[0]) { - case '!': - ++atom; - ret->pfx_op = ATOM_OP_BLOCK_HARD; - break; - case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER; - } else - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - break; - case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER; - } else - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - break; - default: - ret->pfx_op = ATOM_OP_BLOCK; - break; - } + atom++; break; } + if (*atom == '=') { + ret->pfx_op += ATOM_OP_EQUAL; + atom++; + } strcpy(ret->CATEGORY, atom); /* eat file name crap when given
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/, man/, tests/qatom/
commit: 199e4f62b4ede5f2319ef6795a15737ac0882d09 Author: Fabian Groffen gentoo org> AuthorDate: Sun Apr 7 20:06:20 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Sun Apr 7 20:14:35 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=199e4f62 atoms: add proper support for blockers and USE dependencies - ignore SLOT in atom_compare when not set on both sides - parse USE-dependencies, properly removing it from PV - parse blockers (! and !!) separate from version ranges, such that the original meaning can be restored and differentiated from Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 250 --- libq/atom.h | 66 --- man/qatom.1 | 5 +- qatom.c | 40 +-- tests/atom_compare/static.good | 4 +- tests/atom_compare/static.q.good | 2 +- tests/atom_compare/static.tests | 4 +- tests/qatom/dotest | 22 8 files changed, 298 insertions(+), 95 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 60a37ce..4c06c1a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -16,16 +16,28 @@ #include #include -const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; - const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; +const char * const atom_slotdep_str[] = { + "", "=", "*" +}; + +const char * const atom_usecond_str[] = { + "", "!", "-", "?", "=", "(+)", "(-)" +}; + +const char * const atom_blocker_str[] = { + "", "!", "!!" +}; + const char * const atom_op_str[] = { - "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" + "", "=", ">", ">=", "<", "<=", "~", "*" }; +const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; + #ifdef EBUG void atom_print(const depend_atom *atom) @@ -52,7 +64,10 @@ atom_explode(const char *atom) { depend_atom *ret; char *ptr; - size_t len, slen, idx, sidx; + size_t len; + size_t slen; + size_t idx; + size_t sidx; /* we allocate mem for atom struct and two strings (strlen(atom)). * the first string is for CAT/PN/PV while the second is for PVR. @@ -76,61 +91,37 @@ atom_explode(const char *atom) ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + /* check for blocker operators */ + ret->blocker = ATOM_BL_NONE; + if (*atom == '!') { + ret->blocker++; + atom++; + } + if (*atom == '!') { + ret->blocker++; + atom++; + } + /* eat any prefix operators */ - switch (atom[0]) { + ret->pfx_op = ATOM_OP_NONE; + switch (*atom) { case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - } else - ret->pfx_op = ATOM_OP_NEWER; - break; - case '=': - ++atom; - ret->pfx_op = ATOM_OP_EQUAL; + ret->pfx_op = ATOM_OP_NEWER; + atom++; break; case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - } else - ret->pfx_op = ATOM_OP_OLDER; + ret->pfx_op = ATOM_OP_OLDER; + atom++; break; case '~': - ++atom; ret->pfx_op = ATOM_OP_PV_EQUAL; - break; - case '!': - ++atom; - switch (atom[0]) { - case '!': - ++atom; - ret->pfx_op = ATOM_OP_BLOCK_HARD; - break; - case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER; - } else - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - break; - case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER; - } else - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - break; - default: - ret->pfx_op = ATOM_OP_BLOCK; - break; - } + atom++; break; } + if (*atom == '=') { + ret->pfx_op += ATOM_OP_EQUAL; + atom++; + } strcpy(ret->CATEGORY, atom); /* eat file name crap when given
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/, man/, tests/qatom/
commit: 199e4f62b4ede5f2319ef6795a15737ac0882d09 Author: Fabian Groffen gentoo org> AuthorDate: Sun Apr 7 20:06:20 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Sun Apr 7 20:14:35 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=199e4f62 atoms: add proper support for blockers and USE dependencies - ignore SLOT in atom_compare when not set on both sides - parse USE-dependencies, properly removing it from PV - parse blockers (! and !!) separate from version ranges, such that the original meaning can be restored and differentiated from Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 250 --- libq/atom.h | 66 --- man/qatom.1 | 5 +- qatom.c | 40 +-- tests/atom_compare/static.good | 4 +- tests/atom_compare/static.q.good | 2 +- tests/atom_compare/static.tests | 4 +- tests/qatom/dotest | 22 8 files changed, 298 insertions(+), 95 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 60a37ce..4c06c1a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -16,16 +16,28 @@ #include #include -const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; - const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; +const char * const atom_slotdep_str[] = { + "", "=", "*" +}; + +const char * const atom_usecond_str[] = { + "", "!", "-", "?", "=", "(+)", "(-)" +}; + +const char * const atom_blocker_str[] = { + "", "!", "!!" +}; + const char * const atom_op_str[] = { - "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" + "", "=", ">", ">=", "<", "<=", "~", "*" }; +const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; + #ifdef EBUG void atom_print(const depend_atom *atom) @@ -52,7 +64,10 @@ atom_explode(const char *atom) { depend_atom *ret; char *ptr; - size_t len, slen, idx, sidx; + size_t len; + size_t slen; + size_t idx; + size_t sidx; /* we allocate mem for atom struct and two strings (strlen(atom)). * the first string is for CAT/PN/PV while the second is for PVR. @@ -76,61 +91,37 @@ atom_explode(const char *atom) ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + /* check for blocker operators */ + ret->blocker = ATOM_BL_NONE; + if (*atom == '!') { + ret->blocker++; + atom++; + } + if (*atom == '!') { + ret->blocker++; + atom++; + } + /* eat any prefix operators */ - switch (atom[0]) { + ret->pfx_op = ATOM_OP_NONE; + switch (*atom) { case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - } else - ret->pfx_op = ATOM_OP_NEWER; - break; - case '=': - ++atom; - ret->pfx_op = ATOM_OP_EQUAL; + ret->pfx_op = ATOM_OP_NEWER; + atom++; break; case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - } else - ret->pfx_op = ATOM_OP_OLDER; + ret->pfx_op = ATOM_OP_OLDER; + atom++; break; case '~': - ++atom; ret->pfx_op = ATOM_OP_PV_EQUAL; - break; - case '!': - ++atom; - switch (atom[0]) { - case '!': - ++atom; - ret->pfx_op = ATOM_OP_BLOCK_HARD; - break; - case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER; - } else - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - break; - case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER; - } else - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - break; - default: - ret->pfx_op = ATOM_OP_BLOCK; - break; - } + atom++; break; } + if (*atom == '=') { + ret->pfx_op += ATOM_OP_EQUAL; + atom++; + } strcpy(ret->CATEGORY, atom); /* eat file name crap when given
[gentoo-commits] proj/portage-utils:master commit in: tests/atom_compare/, /, libq/, man/, tests/qatom/
commit: 199e4f62b4ede5f2319ef6795a15737ac0882d09 Author: Fabian Groffen gentoo org> AuthorDate: Sun Apr 7 20:06:20 2019 + Commit: Fabian Groffen gentoo org> CommitDate: Sun Apr 7 20:14:35 2019 + URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=199e4f62 atoms: add proper support for blockers and USE dependencies - ignore SLOT in atom_compare when not set on both sides - parse USE-dependencies, properly removing it from PV - parse blockers (! and !!) separate from version ranges, such that the original meaning can be restored and differentiated from Signed-off-by: Fabian Groffen gentoo.org> libq/atom.c | 250 --- libq/atom.h | 66 --- man/qatom.1 | 5 +- qatom.c | 40 +-- tests/atom_compare/static.good | 4 +- tests/atom_compare/static.q.good | 2 +- tests/atom_compare/static.tests | 4 +- tests/qatom/dotest | 22 8 files changed, 298 insertions(+), 95 deletions(-) diff --git a/libq/atom.c b/libq/atom.c index 60a37ce..4c06c1a 100644 --- a/libq/atom.c +++ b/libq/atom.c @@ -16,16 +16,28 @@ #include #include -const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; - const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; +const char * const atom_slotdep_str[] = { + "", "=", "*" +}; + +const char * const atom_usecond_str[] = { + "", "!", "-", "?", "=", "(+)", "(-)" +}; + +const char * const atom_blocker_str[] = { + "", "!", "!!" +}; + const char * const atom_op_str[] = { - "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" + "", "=", ">", ">=", "<", "<=", "~", "*" }; +const char * const booga[] = {"!!!", "!=", "==", ">", "<"}; + #ifdef EBUG void atom_print(const depend_atom *atom) @@ -52,7 +64,10 @@ atom_explode(const char *atom) { depend_atom *ret; char *ptr; - size_t len, slen, idx, sidx; + size_t len; + size_t slen; + size_t idx; + size_t sidx; /* we allocate mem for atom struct and two strings (strlen(atom)). * the first string is for CAT/PN/PV while the second is for PVR. @@ -76,61 +91,37 @@ atom_explode(const char *atom) ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + /* check for blocker operators */ + ret->blocker = ATOM_BL_NONE; + if (*atom == '!') { + ret->blocker++; + atom++; + } + if (*atom == '!') { + ret->blocker++; + atom++; + } + /* eat any prefix operators */ - switch (atom[0]) { + ret->pfx_op = ATOM_OP_NONE; + switch (*atom) { case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - } else - ret->pfx_op = ATOM_OP_NEWER; - break; - case '=': - ++atom; - ret->pfx_op = ATOM_OP_EQUAL; + ret->pfx_op = ATOM_OP_NEWER; + atom++; break; case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - } else - ret->pfx_op = ATOM_OP_OLDER; + ret->pfx_op = ATOM_OP_OLDER; + atom++; break; case '~': - ++atom; ret->pfx_op = ATOM_OP_PV_EQUAL; - break; - case '!': - ++atom; - switch (atom[0]) { - case '!': - ++atom; - ret->pfx_op = ATOM_OP_BLOCK_HARD; - break; - case '>': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_OLDER; - } else - ret->pfx_op = ATOM_OP_OLDER_EQUAL; - break; - case '<': - ++atom; - if (atom[0] == '=') { - ++atom; - ret->pfx_op = ATOM_OP_NEWER; - } else - ret->pfx_op = ATOM_OP_NEWER_EQUAL; - break; - default: - ret->pfx_op = ATOM_OP_BLOCK; - break; - } + atom++; break; } + if (*atom == '=') { + ret->pfx_op += ATOM_OP_EQUAL; + atom++; + } strcpy(ret->CATEGORY, atom); /* eat file name crap when given