This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=b2e7e210e86efb4fb5107736a1610c5d24597bb5 commit b2e7e210e86efb4fb5107736a1610c5d24597bb5 Author: Guillem Jover <guil...@debian.org> AuthorDate: Sun Aug 24 03:14:19 2025 +0200 libdpkg: Switch status abbreviations from char to strings This unifies these abbreviations with the rest of the other strings, so that we can use them where normal strings appear and can also use the same enum to string mapping functions. --- lib/dpkg/dpkg-db.h | 3 +++ lib/dpkg/pkg-format.c | 6 +++--- lib/dpkg/pkg-namevalue.c | 27 +++++++++++++++++++++++++++ lib/dpkg/pkg-show.c | 12 ++++++------ lib/dpkg/pkg-show.h | 9 ++++++--- src/query/main.c | 6 +++--- 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h index f223d745e..2d9b25655 100644 --- a/lib/dpkg/dpkg-db.h +++ b/lib/dpkg/dpkg-db.h @@ -398,8 +398,11 @@ extern const struct namevalue booleaninfos[]; extern const struct namevalue multiarchinfos[]; extern const struct namevalue priorityinfos[]; extern const struct namevalue statusinfos[]; +extern const struct namevalue status_abbrev[]; extern const struct namevalue eflaginfos[]; +extern const struct namevalue eflag_abbrev[]; extern const struct namevalue wantinfos[]; +extern const struct namevalue want_abbrev[]; #include <dpkg/error.h> diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c index 81c6b670a..8fa323184 100644 --- a/lib/dpkg/pkg-format.c +++ b/lib/dpkg/pkg-format.c @@ -227,9 +227,9 @@ virt_status_abbrev(struct varbuf *vb, if (pkgbin != &pkg->installed) return; - varbuf_add_char(vb, pkg_abbrev_want(pkg)); - varbuf_add_char(vb, pkg_abbrev_status(pkg)); - varbuf_add_char(vb, pkg_abbrev_eflag(pkg)); + varbuf_add_str(vb, pkg_abbrev_want(pkg)); + varbuf_add_str(vb, pkg_abbrev_status(pkg)); + varbuf_add_str(vb, pkg_abbrev_eflag(pkg)); } static void diff --git a/lib/dpkg/pkg-namevalue.c b/lib/dpkg/pkg-namevalue.c index 5f6fcb7b3..ef5194597 100644 --- a/lib/dpkg/pkg-namevalue.c +++ b/lib/dpkg/pkg-namevalue.c @@ -58,12 +58,27 @@ const struct namevalue wantinfos[] = { { .name = NULL } }; +const struct namevalue want_abbrev[] = { + NAMEVALUE_DEF("u", PKG_WANT_UNKNOWN), + NAMEVALUE_DEF("i", PKG_WANT_INSTALL), + NAMEVALUE_DEF("h", PKG_WANT_HOLD), + NAMEVALUE_DEF("r", PKG_WANT_DEINSTALL), + NAMEVALUE_DEF("p", PKG_WANT_PURGE), + { .name = NULL } +}; + const struct namevalue eflaginfos[] = { NAMEVALUE_DEF("ok", PKG_EFLAG_OK), NAMEVALUE_DEF("reinstreq", PKG_EFLAG_REINSTREQ), { .name = NULL } }; +const struct namevalue eflag_abbrev[] = { + NAMEVALUE_DEF(" ", PKG_EFLAG_OK), + NAMEVALUE_DEF("R", PKG_EFLAG_REINSTREQ), + { .name = NULL } +}; + const struct namevalue statusinfos[] = { NAMEVALUE_DEF("not-installed", PKG_STAT_NOTINSTALLED), NAMEVALUE_DEF("config-files", PKG_STAT_CONFIGFILES), @@ -75,3 +90,15 @@ const struct namevalue statusinfos[] = { NAMEVALUE_DEF("installed", PKG_STAT_INSTALLED), { .name = NULL } }; + +const struct namevalue status_abbrev[] = { + NAMEVALUE_DEF("n", PKG_STAT_NOTINSTALLED), + NAMEVALUE_DEF("c", PKG_STAT_CONFIGFILES), + NAMEVALUE_DEF("H", PKG_STAT_HALFINSTALLED), + NAMEVALUE_DEF("U", PKG_STAT_UNPACKED), + NAMEVALUE_DEF("F", PKG_STAT_HALFCONFIGURED), + NAMEVALUE_DEF("W", PKG_STAT_TRIGGERSAWAITED), + NAMEVALUE_DEF("t", PKG_STAT_TRIGGERSPENDING), + NAMEVALUE_DEF("i", PKG_STAT_INSTALLED), + { .name = NULL } +}; diff --git a/lib/dpkg/pkg-show.c b/lib/dpkg/pkg-show.c index 178268614..046b5e085 100644 --- a/lib/dpkg/pkg-show.c +++ b/lib/dpkg/pkg-show.c @@ -266,10 +266,10 @@ pkg_synopsis(const struct pkginfo *pkg, int *len) * * @return The character abbreviated representation. */ -int +const char * pkg_abbrev_want(const struct pkginfo *pkg) { - return "uihrp"[pkg->want]; + return want_abbrev[pkg->want].name; } /** @@ -279,10 +279,10 @@ pkg_abbrev_want(const struct pkginfo *pkg) * * @return The character abbreviated representation. */ -int +const char * pkg_abbrev_status(const struct pkginfo *pkg) { - return "ncHUFWti"[pkg->status]; + return status_abbrev[pkg->status].name; } /** @@ -292,10 +292,10 @@ pkg_abbrev_status(const struct pkginfo *pkg) * * @return The character abbreviated representation. */ -int +const char * pkg_abbrev_eflag(const struct pkginfo *pkg) { - return " R"[pkg->eflag]; + return eflag_abbrev[pkg->eflag].name; } /** diff --git a/lib/dpkg/pkg-show.h b/lib/dpkg/pkg-show.h index 4ac3f5d65..19dcfbff3 100644 --- a/lib/dpkg/pkg-show.h +++ b/lib/dpkg/pkg-show.h @@ -38,9 +38,12 @@ const char *pkgbin_synopsis(const struct pkginfo *pkg, const struct pkgbin *pkgbin, int *len_ret); const char * pkg_synopsis(const struct pkginfo *pkg, int *len_ret); -int pkg_abbrev_want(const struct pkginfo *pkg); -int pkg_abbrev_status(const struct pkginfo *pkg); -int pkg_abbrev_eflag(const struct pkginfo *pkg); +const char * +pkg_abbrev_want(const struct pkginfo *pkg); +const char * +pkg_abbrev_status(const struct pkginfo *pkg); +const char * +pkg_abbrev_eflag(const struct pkginfo *pkg); /** @} */ diff --git a/src/query/main.c b/src/query/main.c index c6259574e..51fb97e86 100644 --- a/src/query/main.c +++ b/src/query/main.c @@ -158,7 +158,7 @@ list_format_init(struct list_format *fmt, struct pkg_array *array) static void list_format_print(struct list_format *fmt, - int c_want, int c_status, int c_eflag, + const char *c_want, const char *c_status, const char *c_eflag, const char *name, const char *version, const char *arch, const char *desc, int desc_len) { @@ -169,7 +169,7 @@ list_format_print(struct list_format *fmt, str_gen_crop(arch, fmt->aw, &as); str_gen_crop(desc, desc_len, &ds); - printf("%c%c%c %-*.*s %-*.*s %-*.*s %.*s\n", c_want, c_status, c_eflag, + printf("%s%s%s %-*.*s %-*.*s %-*.*s %.*s\n", c_want, c_status, c_eflag, ns.max_bytes, ns.str_bytes, name, vs.max_bytes, vs.str_bytes, version, as.max_bytes, as.str_bytes, arch, @@ -194,7 +194,7 @@ list_format_print_header(struct list_format *fmt) Desired=Unknown/Install/Remove/Purge/Hold\n\ | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend\n\ |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)\n"), stdout); - list_format_print(fmt, '|', '|', '/', _("Name"), _("Version"), + list_format_print(fmt, "|", "|", "/", _("Name"), _("Version"), _("Architecture"), _("Description"), fmt->dw); /* Status */ -- Dpkg.Org's dpkg