[master] 1eeb29114 param: Show "all" or "none" for bits parameters
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Tue Feb 18 09:46:16 UTC 2025
commit 1eeb29114641d036f8e7e2243c99f5e30eb580cc
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Feb 4 13:24:39 2025 +0100
param: Show "all" or "none" for bits parameters
The value for bits parameters currently follows this syntax:
all(,-\w+)*
none(,[+]\w+)*
When either all or none of the flags are set according to the parameter
sign, the value will simply be "all" or "none". The opposite value will
respectively be:
all,-every,-single,-flag...
none,+every,+single,+flag...
Considering the number of bits per parameters, we can compute upfront
whether all bits are raised and simply print "none" or "all":
"none" instead of "all,-every,-single,-flag..."
"all" instead of "none,+every,+single,+flag..."
Co-authored-by: Nils Goroll <nils.goroll at uplex.de>
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index 644dbab44..51c3766d5 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -713,7 +713,7 @@ tweak_generic_bits(struct vsb *vsb, const struct parspec *par, const char *arg,
uint8_t *p, unsigned l, const char * const *tags, const char *desc,
char sign)
{
- unsigned j;
+ unsigned j, all;
if (arg != NULL && !strcmp(arg, "default")) {
/* XXX: deprecated in favor of param.reset */
@@ -724,10 +724,19 @@ tweak_generic_bits(struct vsb *vsb, const struct parspec *par, const char *arg,
if (arg != NULL && arg != JSON_FMT)
return (bit_tweak(vsb, p, l, arg, tags, desc, sign));
+ all = 1;
+ for (j = 0; all && j < l; j++) {
+ if (!bit(p, j, BTST))
+ all = 0;
+ }
+
if (arg == JSON_FMT)
VSB_putc(vsb, '"');
- VSB_cat(vsb, sign == '+' ? "none" : "all");
- for (j = 0; j < l; j++) {
+ if (all)
+ VSB_cat(vsb, sign == '+' ? "all" : "none");
+ else
+ VSB_cat(vsb, sign == '+' ? "none" : "all");
+ for (j = 0; !all && j < l; j++) {
if (bit(p, j, BTST))
VSB_printf(vsb, ",%c%s", sign, tags[j]);
}
More information about the varnish-commit
mailing list