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=cee8e4b5a5c7cc0ccd4810c83796ec824f5ebb63

commit cee8e4b5a5c7cc0ccd4810c83796ec824f5ebb63
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Sat Jan 29 18:23:49 2022 +0100

    libdpkg: Refactor pkg_format_print() out from pkg_format_show()
    
    This will allow testing the formatting code.
---
 lib/dpkg/libdpkg.map  |  1 +
 lib/dpkg/pkg-format.c | 27 ++++++++++++++++++---------
 lib/dpkg/pkg-format.h |  2 ++
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map
index 6aa38248b..9f345f9eb 100644
--- a/lib/dpkg/libdpkg.map
+++ b/lib/dpkg/libdpkg.map
@@ -353,6 +353,7 @@ LIBDPKG_PRIVATE {
 
        # Package field format handling
        pkg_format_parse;
+       pkg_format_print;
        pkg_format_show;
        pkg_format_needs_db_fsys;
        pkg_format_free;
diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c
index 8af7c4fe3..48966c4e0 100644
--- a/lib/dpkg/pkg-format.c
+++ b/lib/dpkg/pkg-format.c
@@ -414,11 +414,11 @@ pkg_format_item(struct varbuf *vb,
 }
 
 void
-pkg_format_show(const struct pkg_format_node *head,
-                struct pkginfo *pkg, struct pkgbin *pkgbin)
+pkg_format_print(struct varbuf *vb, const struct pkg_format_node *head,
+                 struct pkginfo *pkg, struct pkgbin *pkgbin)
 {
        const struct pkg_format_node *node;
-       struct varbuf vb = VARBUF_INIT, fb = VARBUF_INIT, wb = VARBUF_INIT;
+       struct varbuf fb = VARBUF_INIT, wb = VARBUF_INIT;
 
        for (node = head; node; node = node->next) {
                bool ok = false;
@@ -457,18 +457,27 @@ pkg_format_show(const struct pkg_format_node *head,
 
                        if ((width != 0) && (len > width))
                                len = width;
-                       varbuf_add_buf(&vb, fb.buf, len);
+                       varbuf_add_buf(vb, fb.buf, len);
+                       varbuf_end_str(vb);
                }
 
                varbuf_reset(&fb);
        }
 
-       if (vb.buf) {
-               varbuf_end_str(&vb);
-               fputs(vb.buf, stdout);
-       }
-
        varbuf_destroy(&wb);
        varbuf_destroy(&fb);
+}
+
+void
+pkg_format_show(const struct pkg_format_node *head,
+                struct pkginfo *pkg, struct pkgbin *pkgbin)
+{
+       struct varbuf vb = VARBUF_INIT;
+
+       pkg_format_print(&vb, head, pkg, pkgbin);
+
+       if (vb.buf)
+               fputs(vb.buf, stdout);
+
        varbuf_destroy(&vb);
 }
diff --git a/lib/dpkg/pkg-format.h b/lib/dpkg/pkg-format.h
index b0c61bad3..40d41ffc1 100644
--- a/lib/dpkg/pkg-format.h
+++ b/lib/dpkg/pkg-format.h
@@ -41,6 +41,8 @@ pkg_format_needs_db_fsys(const struct pkg_format_node *head);
 struct pkg_format_node *pkg_format_parse(const char *fmt,
                                          struct dpkg_error *err);
 void pkg_format_free(struct pkg_format_node *head);
+void pkg_format_print(struct varbuf *vb, const struct pkg_format_node *head,
+                      struct pkginfo *pkg, struct pkgbin *pkgbin);
 void pkg_format_show(const struct pkg_format_node *head,
                      struct pkginfo *pkg, struct pkgbin *pkgbin);
 

-- 
Dpkg.Org's dpkg

Reply via email to