1 |
commit: 868b2b4b4f5140da7188389acf9f719fcf343ab2 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Apr 19 11:47:29 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Apr 19 11:47:29 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=868b2b4b |
7 |
|
8 |
atom: allow category-only atoms |
9 |
|
10 |
This allows to match categories via atom matches, using e.g. mail-client/ |
11 |
|
12 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
13 |
|
14 |
libq/atom.c | 28 +++++++++++++++++++++++++--- |
15 |
1 file changed, 25 insertions(+), 3 deletions(-) |
16 |
|
17 |
diff --git a/libq/atom.c b/libq/atom.c |
18 |
index 4c06c1a..58565bc 100644 |
19 |
--- a/libq/atom.c |
20 |
+++ b/libq/atom.c |
21 |
@@ -160,6 +160,11 @@ atom_explode(const char *atom) |
22 |
if ((ptr = strrchr(ret->CATEGORY, '/')) != NULL) { |
23 |
ret->PN = ptr + 1; |
24 |
*ptr = '\0'; |
25 |
+ |
26 |
+ /* set PN to NULL if there's nothing */ |
27 |
+ if (ret->PN[0] == '\0') |
28 |
+ ret->PN = NULL; |
29 |
+ |
30 |
/* eat extra crap in case it exists, this is a feature to allow |
31 |
* /path/to/pkg.ebuild, doesn't work with prefix operators |
32 |
* though */ |
33 |
@@ -170,6 +175,13 @@ atom_explode(const char *atom) |
34 |
ret->CATEGORY = NULL; |
35 |
} |
36 |
|
37 |
+ if (ret->PN == NULL) { |
38 |
+ /* atom has no name, this is it */ |
39 |
+ ret->P = NULL; |
40 |
+ ret->PVR = NULL; |
41 |
+ return ret; |
42 |
+ } |
43 |
+ |
44 |
/* hunt down build with USE dependencies */ |
45 |
if ((ptr = strrchr(ret->PN, ']')) != NULL && ptr[1] == '\0' && |
46 |
(ptr = strrchr(ret->PN, '[')) != NULL) |
47 |
@@ -378,15 +390,22 @@ int |
48 |
atom_compare(const depend_atom *a1, const depend_atom *a2) |
49 |
{ |
50 |
/* sanity check that at most one has operators */ |
51 |
- if (a1->pfx_op != ATOM_OP_NONE || a1->sfx_op != ATOM_OP_NONE) { |
52 |
- /* this is bogus, so punt it */ |
53 |
- if (a2->pfx_op != ATOM_OP_NONE || a2->sfx_op != ATOM_OP_NONE) |
54 |
+ if (a1->pfx_op != ATOM_OP_NONE || |
55 |
+ a1->sfx_op != ATOM_OP_NONE || |
56 |
+ a1->blocker != ATOM_BL_NONE) |
57 |
+ { |
58 |
+ /* is the other also having operators, then punt it */ |
59 |
+ if (a2->pfx_op != ATOM_OP_NONE || |
60 |
+ a2->sfx_op != ATOM_OP_NONE || |
61 |
+ a2->blocker != ATOM_BL_NONE) |
62 |
return NOT_EQUAL; |
63 |
+ |
64 |
/* swap a1 & a2 so that a2 is the atom with operators */ |
65 |
const depend_atom *as = a2; |
66 |
a2 = a1; |
67 |
a1 = as; |
68 |
} |
69 |
+ |
70 |
atom_operator pfx_op = a2->pfx_op; |
71 |
atom_operator sfx_op = a2->sfx_op; |
72 |
|
73 |
@@ -437,6 +456,9 @@ atom_compare(const depend_atom *a1, const depend_atom *a2) |
74 |
if (a1->PN && a2->PN) { |
75 |
if (strcmp(a1->PN, a2->PN)) |
76 |
return NOT_EQUAL; |
77 |
+ } else if (a1->CATEGORY && a2->CATEGORY) { |
78 |
+ /* if CAT is set, and one side has empty PN, accept as match */ |
79 |
+ return a2->blocker != ATOM_BL_NONE ? NOT_EQUAL : EQUAL; |
80 |
} else if (a1->PN || a2->PN) |
81 |
return NOT_EQUAL; |