Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Sat, 28 Nov 2015 02:44:48
Message-Id: 1448663822.b4db839907e96b8346ecb27dbc231dab1c335704.vapier@gentoo
1 commit: b4db839907e96b8346ecb27dbc231dab1c335704
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Fri Nov 27 22:37:02 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Fri Nov 27 22:37:02 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b4db8399
7
8 qcache: rework last traversal callback
9
10 Rather than packing the last entry in at the same time as a valid
11 call, make a dedicated call with a NULL argument. This way the
12 callback funcs are forced to deal with this up front cleanly.
13
14 qcache.c | 112 ++++++++++++++++++++++++++++++++++++---------------------------
15 1 file changed, 64 insertions(+), 48 deletions(-)
16
17 diff --git a/qcache.c b/qcache.c
18 index 0891918..091a510 100644
19 --- a/qcache.c
20 +++ b/qcache.c
21 @@ -67,7 +67,7 @@ static char **archlist; /* Read from PORTDIR/profiles/arch.list in qcache_init()
22 static int archlist_count;
23 static size_t arch_longest_len;
24 const char status[3] = {'-', '~', '+'};
25 -int qcache_skip, qcache_test_arch, qcache_last = 0;
26 +int qcache_skip, qcache_test_arch;
27 char *qcache_matchpkg = NULL, *qcache_matchcat = NULL;
28
29 /********************************************************************/
30 @@ -462,6 +462,7 @@ int qcache_traverse(void (*func)(qcache_data*))
31 qcache_skip = 0;
32
33 /* traverse ebuilds */
34 + data.num = num_ebuild;
35 for (k = 0; k < num_ebuild; k++) {
36 len = xasprintf(&cachepath, "%s/%s/%s", catpath, categories[i]->d_name, ebuilds[k]->d_name);
37 cachepath[len - 7] = '\0'; /* remove ".ebuild" */
38 @@ -470,14 +471,9 @@ int qcache_traverse(void (*func)(qcache_data*))
39 data.package = packages[j]->d_name;
40 data.ebuild = ebuilds[k]->d_name;
41 data.cur = k + 1;
42 - data.num = num_ebuild;
43 data.cache_data = qcache_read_cache_file(cachepath);
44
45 if (data.cache_data != NULL) {
46 - /* is this the last ebuild? */
47 - if (i+1 == num_cat && j+1 == num_pkg && k+1 == num_ebuild)
48 - qcache_last = 1;
49 -
50 if (!qcache_skip)
51 func(&data);
52
53 @@ -508,6 +504,8 @@ int qcache_traverse(void (*func)(qcache_data*))
54 free(categories);
55 free(catpath);
56
57 + func(NULL);
58 +
59 return 0;
60 }
61
62 @@ -521,6 +519,9 @@ void qcache_imlate(qcache_data *data)
63 int *keywords;
64 int a;
65
66 + if (!data)
67 + return;
68 +
69 keywords = xmalloc(sizeof(*keywords) * archlist_count);
70
71 if (read_keywords(data->cache_data->KEYWORDS, keywords) < 0) {
72 @@ -552,6 +553,9 @@ void qcache_not(qcache_data *data)
73 {
74 int *keywords;
75
76 + if (!data)
77 + return;
78 +
79 keywords = xmalloc(sizeof(*keywords) * archlist_count);
80
81 if (read_keywords(data->cache_data->KEYWORDS, keywords) < 0) {
82 @@ -574,6 +578,9 @@ void qcache_all(qcache_data *data)
83 {
84 int *keywords;
85
86 + if (!data)
87 + return;
88 +
89 keywords = xmalloc(sizeof(*keywords) * archlist_count);
90
91 if (read_keywords(data->cache_data->KEYWORDS, keywords) < 0) {
92 @@ -596,6 +603,9 @@ void qcache_dropped(qcache_data *data)
93 static int possible = 0;
94 int *keywords, i;
95
96 + if (!data)
97 + return;
98 +
99 if (data->cur == 1)
100 possible = 0;
101
102 @@ -644,6 +654,51 @@ void qcache_stats(qcache_data *data)
103 static int *keywords;
104 int a;
105
106 + /* Is this the last time we'll be called? */
107 + if (!data) {
108 + const char border[] = "------------------------------------------------------------------";
109 +
110 + printf("+%.*s+\n", 25, border);
111 + printf("| general statistics |\n");
112 + printf("+%.*s+\n", 25, border);
113 + printf("| %s%13s%s | %s%7d%s |\n", GREEN, "architectures", NORM, BLUE, archlist_count, NORM);
114 + printf("| %s%13s%s | %s%7d%s |\n", GREEN, "categories", NORM, BLUE, numcat, NORM);
115 + printf("| %s%13s%s | %s%7d%s |\n", GREEN, "packages", NORM, BLUE, numpkg, NORM);
116 + printf("| %s%13s%s | %s%7d%s |\n", GREEN, "ebuilds", NORM, BLUE, numebld, NORM);
117 + printf("+%.*s+\n\n", 25, border);
118 +
119 + printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
120 + printf("|%*skeyword distribution |\n",
121 + (int)arch_longest_len, "");
122 + printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
123 + printf("| %s%*s%s |%s%8s%s |%s%8s%s |%s%8s%s | %s%8s%s |\n",
124 + RED, (int)arch_longest_len, "architecture", NORM, RED, "stable", NORM,
125 + RED, "~arch", NORM, RED, "total", NORM, RED, "total/#pkgs", NORM);
126 + printf("| %*s | |%s%8s%s | | |\n",
127 + (int)arch_longest_len, "", RED, "only", NORM);
128 + printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
129 +
130 + for (a = 0; a < archlist_count; ++a) {
131 + printf("| %s%*s%s |", GREEN, (int)arch_longest_len, archlist[a], NORM);
132 + printf("%s%8d%s |", BLUE, packages_stable[a], NORM);
133 + printf("%s%8d%s |", BLUE, packages_testing[a], NORM);
134 + printf("%s%8d%s |", BLUE, packages_testing[a]+packages_stable[a], NORM);
135 + printf("%s%11.2f%s%% |\n", BLUE, (100.0*(packages_testing[a]+packages_stable[a]))/numpkg, NORM);
136 + }
137 +
138 + printf("+%.*s+\n\n", (int)(arch_longest_len + 46), border);
139 +
140 + printf("Completed in ");
141 + print_seconds_for_earthlings(time(NULL) - runtime);
142 + printf("\n");
143 +
144 + free(packages_stable);
145 + free(packages_testing);
146 + free(keywords);
147 + free(current_package_keywords);
148 + return;
149 + }
150 +
151 if (!numpkg) {
152 struct dirent **categories;
153 char *catpath;
154 @@ -702,48 +757,6 @@ void qcache_stats(qcache_data *data)
155 }
156 }
157 }
158 -
159 - if (qcache_last) {
160 - const char border[] = "------------------------------------------------------------------";
161 - printf("+%.*s+\n", 25, border);
162 - printf("| general statistics |\n");
163 - printf("+%.*s+\n", 25, border);
164 - printf("| %s%13s%s | %s%7d%s |\n", GREEN, "architectures", NORM, BLUE, archlist_count, NORM);
165 - printf("| %s%13s%s | %s%7d%s |\n", GREEN, "categories", NORM, BLUE, numcat, NORM);
166 - printf("| %s%13s%s | %s%7d%s |\n", GREEN, "packages", NORM, BLUE, numpkg, NORM);
167 - printf("| %s%13s%s | %s%7d%s |\n", GREEN, "ebuilds", NORM, BLUE, numebld, NORM);
168 - printf("+%.*s+\n\n", 25, border);
169 -
170 - printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
171 - printf("|%*skeyword distribution |\n",
172 - (int)arch_longest_len, "");
173 - printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
174 - printf("| %s%*s%s |%s%8s%s |%s%8s%s |%s%8s%s | %s%8s%s |\n",
175 - RED, (int)arch_longest_len, "architecture", NORM, RED, "stable", NORM,
176 - RED, "~arch", NORM, RED, "total", NORM, RED, "total/#pkgs", NORM);
177 - printf("| %*s | |%s%8s%s | | |\n",
178 - (int)arch_longest_len, "", RED, "only", NORM);
179 - printf("+%.*s+\n", (int)(arch_longest_len + 46), border);
180 -
181 - for (a = 0; a < archlist_count; ++a) {
182 - printf("| %s%*s%s |", GREEN, (int)arch_longest_len, archlist[a], NORM);
183 - printf("%s%8d%s |", BLUE, packages_stable[a], NORM);
184 - printf("%s%8d%s |", BLUE, packages_testing[a], NORM);
185 - printf("%s%8d%s |", BLUE, packages_testing[a]+packages_stable[a], NORM);
186 - printf("%s%11.2f%s%% |\n", BLUE, (100.0*(packages_testing[a]+packages_stable[a]))/numpkg, NORM);
187 - }
188 -
189 - printf("+%.*s+\n\n", (int)(arch_longest_len + 46), border);
190 -
191 - printf("Completed in ");
192 - print_seconds_for_earthlings(time(NULL) - runtime);
193 - printf("\n");
194 -
195 - free(packages_stable);
196 - free(packages_testing);
197 - free(keywords);
198 - free(current_package_keywords);
199 - }
200 }
201
202 _q_static
203 @@ -752,6 +765,9 @@ void qcache_testing_only(qcache_data *data)
204 static int possible = 0;
205 int *keywords;
206
207 + if (!data)
208 + return;
209 +
210 if (data->cur == 1)
211 possible = 0;