diff options
author | Guillem Jover <guillem@debian.org> | 2014-11-09 01:14:07 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2016-12-17 01:42:08 +0100 |
commit | 7d93495f41e5ecb125825ce13f7cae0a215075d4 (patch) | |
tree | 089a5bf09d07d56f0fa8e0f541a36ad58274c4ef /lib | |
parent | 232c13c84b5d3c47f8319ea6f9adc8cc3ee71eda (diff) | |
download | dpkg-7d93495f41e5ecb125825ce13f7cae0a215075d4.tar.gz |
libdpkg: Refactor varbuf_add_source_version() out from virt_source_version()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpkg/dpkg-db.h | 4 | ||||
-rw-r--r-- | lib/dpkg/libdpkg.map | 1 | ||||
-rw-r--r-- | lib/dpkg/pkg-format.c | 18 | ||||
-rw-r--r-- | lib/dpkg/pkg-show.c | 34 |
4 files changed, 40 insertions, 17 deletions
diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h index 389aaad1b..a725fb56a 100644 --- a/lib/dpkg/dpkg-db.h +++ b/lib/dpkg/dpkg-db.h @@ -379,6 +379,10 @@ const char *pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin, enum pkg_name_arch_when pnaw); const char *pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw); +void +varbuf_add_source_version(struct varbuf *vb, + const struct pkginfo *pkg, const struct pkgbin *pkgbin); + const char *pkg_want_name(const struct pkginfo *pkg); const char *pkg_status_name(const struct pkginfo *pkg); const char *pkg_eflag_name(const struct pkginfo *pkg); diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index 93f0bfea0..f5db6c7a0 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -262,6 +262,7 @@ LIBDPKG_PRIVATE { pkg_sorter_by_nonambig_name_arch; varbuf_add_pkgbin_name; varbuf_add_archqual; + varbuf_add_source_version; pkgbin_name; pkg_name; pkgbin_summary; diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c index 8e6acc749..9f3b924d1 100644 --- a/lib/dpkg/pkg-format.c +++ b/lib/dpkg/pkg-format.c @@ -303,23 +303,7 @@ virt_source_version(struct varbuf *vb, const struct pkginfo *pkg, const struct pkgbin *pkgbin, enum fwriteflags flags, const struct fieldinfo *fip) { - const char *version; - size_t len; - - if (pkgbin->source) - version = strchr(pkgbin->source, '('); - else - version = NULL; - - if (version == NULL) { - varbufversion(vb, &pkgbin->version, vdew_nonambig); - } else { - version++; - - len = strcspn(version, ")"); - - varbuf_add_buf(vb, version, len); - } + varbuf_add_source_version(vb, pkg, pkgbin); } static const struct fieldinfo virtinfos[] = { diff --git a/lib/dpkg/pkg-show.c b/lib/dpkg/pkg-show.c index 1d6ce9146..cb93df30a 100644 --- a/lib/dpkg/pkg-show.c +++ b/lib/dpkg/pkg-show.c @@ -289,3 +289,37 @@ pkg_sorter_by_nonambig_name_arch(const void *a, const void *b) return -1; } } + +/** + * Add a string representation of the source package version to a varbuf. + * + * It parses the Source field (if present), and extracts the optional + * version enclosed in parenthesis. Otherwise it fallsback to use the + * binary package version. It NUL terminates the varbuf. + * + * @param vb The varbuf struct to modify. + * @param pkg The package to consider. + * @param pkgbin The binary package instance to consider. + */ +void +varbuf_add_source_version(struct varbuf *vb, + const struct pkginfo *pkg, const struct pkgbin *pkgbin) +{ + const char *version; + size_t len; + + if (pkgbin->source) + version = strchr(pkgbin->source, '('); + else + version = NULL; + + if (version == NULL) { + varbufversion(vb, &pkgbin->version, vdew_nonambig); + } else { + version++; + + len = strcspn(version, ")"); + + varbuf_add_buf(vb, version, len); + } +} |