From: Lennart Poettering Date: Thu, 18 Sep 2025 07:29:27 +0000 (+0200) Subject: format-table: add TABLE_VERSION cell type X-Git-Tag: v259-rc1~526^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e9fbaa620920c2422056d5eecd43cde0590e4ba;p=thirdparty%2Fsystemd.git format-table: add TABLE_VERSION cell type This is exactly like TABLE_STRING, with one exception: it sorts via strverscmp_improved(). --- diff --git a/src/shared/format-table.c b/src/shared/format-table.c index c672be326d2..c129f260e8c 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -287,6 +287,7 @@ static size_t table_data_size(TableDataType type, const void *data) { case TABLE_PATH_BASENAME: case TABLE_FIELD: case TABLE_HEADER: + case TABLE_VERSION: return strlen(data) + 1; case TABLE_STRV: @@ -526,7 +527,7 @@ int table_add_cell_stringf_full(Table *t, TableCell **ret_cell, TableDataType dt int r; assert(t); - assert(IN_SET(dt, TABLE_STRING, TABLE_PATH, TABLE_PATH_BASENAME, TABLE_FIELD, TABLE_HEADER)); + assert(IN_SET(dt, TABLE_STRING, TABLE_PATH, TABLE_PATH_BASENAME, TABLE_FIELD, TABLE_HEADER, TABLE_VERSION)); va_start(ap, format); r = vasprintf(&buffer, format, ap); @@ -934,6 +935,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) { case TABLE_PATH_BASENAME: case TABLE_FIELD: case TABLE_HEADER: + case TABLE_VERSION: data = va_arg(ap, const char *); break; @@ -1395,6 +1397,9 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t case TABLE_PATH_BASENAME: return path_compare(a->string, b->string); + case TABLE_VERSION: + return strverscmp_improved(a->string, b->string); + case TABLE_STRV: case TABLE_STRV_WRAPPED: return strv_compare(a->strv, b->strv); @@ -1579,7 +1584,8 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas case TABLE_PATH: case TABLE_PATH_BASENAME: case TABLE_FIELD: - case TABLE_HEADER: { + case TABLE_HEADER: + case TABLE_VERSION: { _cleanup_free_ char *bn = NULL; const char *s; @@ -2753,6 +2759,7 @@ static int table_data_to_json(TableData *d, sd_json_variant **ret) { case TABLE_PATH_BASENAME: case TABLE_FIELD: case TABLE_HEADER: + case TABLE_VERSION: return sd_json_variant_new_string(ret, d->string); case TABLE_STRV: diff --git a/src/shared/format-table.h b/src/shared/format-table.h index beea0cbe1b4..3365a8feb7b 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -16,6 +16,7 @@ typedef enum TableDataType { TABLE_STRV_WRAPPED, TABLE_PATH, TABLE_PATH_BASENAME, /* like TABLE_PATH, but display only last path element (i.e. the "basename") in regular output */ + TABLE_VERSION, /* just like TABLE_STRING, but uses version comparison when sorting */ TABLE_BOOLEAN, TABLE_BOOLEAN_CHECKMARK, TABLE_TIMESTAMP,