[dpkg] 64/200: libdpkg: Refactor varbuf_add_source_version() out from virt_source_version()

Ximin Luo infinity0 at debian.org
Wed Apr 5 15:17:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository dpkg.

commit 7d93495f41e5ecb125825ce13f7cae0a215075d4
Author: Guillem Jover <guillem at debian.org>
Date:   Sun Nov 9 01:14:07 2014 +0100

    libdpkg: Refactor varbuf_add_source_version() out from virt_source_version()
---
 lib/dpkg/dpkg-db.h    |  4 ++++
 lib/dpkg/libdpkg.map  |  1 +
 lib/dpkg/pkg-format.c | 18 +-----------------
 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 389aaad..a725fb5 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 93f0bfe..f5db6c7 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 8e6acc7..9f3b924 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 1d6ce91..cb93df3 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);
+	}
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list