This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
commit cd96cca4b2cf83f46d6e289418ed06e3c2ef7066 Author: Guillem Jover <[email protected]> Date: Fri Mar 16 04:33:31 2018 +0100 libdpkg: Make pkg_name() and pkgbin_name() get const structs Modifying the struct pkginfo and struct pkgbin complicates how the code is used, and when the function can be called. Let's just initialize the pkgname_archqual variable at parse time, so that we can use it at any time, simplifying the overall code. --- lib/dpkg/dpkg-db.h | 7 +++---- lib/dpkg/dump.c | 10 ++-------- lib/dpkg/parse.c | 10 ++++++++++ lib/dpkg/pkg-show.c | 17 ++--------------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h index bffd317..56b4b5c 100644 --- a/lib/dpkg/dpkg-db.h +++ b/lib/dpkg/dpkg-db.h @@ -110,8 +110,7 @@ struct pkgbin { bool essential; enum pkgmultiarch multiarch; const struct dpkg_arch *arch; - /** The following is the "pkgname:archqual" cached string, if this was a - * C++ class this member would be mutable. */ + /** The fully qualified package name, i.e. "pkgname:archqual". */ const char *pkgname_archqual; const char *description; const char *maintainer; @@ -377,9 +376,9 @@ enum pkg_name_arch_when { void varbuf_add_pkgbin_name(struct varbuf *vb, const struct pkginfo *pkg, const struct pkgbin *pkgbin, enum pkg_name_arch_when pnaw); -const char *pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin, +const char *pkgbin_name(const struct pkginfo *pkg, const struct pkgbin *pkgbin, enum pkg_name_arch_when pnaw); -const char *pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw); +const char *pkg_name(const struct pkginfo *pkg, enum pkg_name_arch_when pnaw); void pkg_source_version(struct dpkg_version *version, diff --git a/lib/dpkg/dump.c b/lib/dpkg/dump.c index b13eb6e..a04f673 100644 --- a/lib/dpkg/dump.c +++ b/lib/dpkg/dump.c @@ -461,16 +461,10 @@ writerecord(FILE *file, const char *filename, varbufrecord(&vb, pkg, pkgbin); varbuf_end_str(&vb); - if (fputs(vb.buf,file) < 0) { - struct varbuf pkgname = VARBUF_INIT; - int errno_saved = errno; - varbuf_add_pkgbin_name(&pkgname, pkg, pkgbin, pnaw_nonambig); - - errno = errno_saved; + if (fputs(vb.buf, file) < 0) ohshite(_("failed to write details of '%.50s' to '%.250s'"), - pkgname.buf, filename); - } + pkgbin_name(pkg, pkgbin, pnaw_nonambig), filename); varbuf_destroy(&vb); } diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c index 1b3bf13..d75c544 100644 --- a/lib/dpkg/parse.c +++ b/lib/dpkg/parse.c @@ -219,6 +219,16 @@ pkg_parse_verify(struct parsedb_state *ps, parse_error(ps, _("package has field '%s' but is architecture all"), "Multi-Arch: same"); + /* Generate the fully qualified package name representation. */ + if (pkgbin->arch->type != DPKG_ARCH_NONE && + pkgbin->arch->type != DPKG_ARCH_EMPTY) { + char *pkgname = nfmalloc(strlen(pkg->set->name) + 1 + + strlen(pkgbin->arch->name) + 1); + + str_concat(pkgname, pkg->set->name, ":", pkgbin->arch->name, NULL); + pkgbin->pkgname_archqual = pkgname; + } + /* Initialize deps to be arch-specific unless stated otherwise. */ for (dep = pkgbin->depends; dep; dep = dep->next) for (dop = dep->list; dop; dop = dop->next) diff --git a/lib/dpkg/pkg-show.c b/lib/dpkg/pkg-show.c index 6af658c..4818675 100644 --- a/lib/dpkg/pkg-show.c +++ b/lib/dpkg/pkg-show.c @@ -93,25 +93,12 @@ varbuf_add_pkgbin_name(struct varbuf *vb, * @return The string representation. */ const char * -pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin, +pkgbin_name(const struct pkginfo *pkg, const struct pkgbin *pkgbin, enum pkg_name_arch_when pnaw) { if (!pkgbin_name_needs_arch(pkgbin, pnaw)) return pkg->set->name; - /* Cache the package name representation, for later reuse. */ - if (pkgbin->pkgname_archqual == NULL) { - struct varbuf vb = VARBUF_INIT; - - varbuf_add_str(&vb, pkg->set->name); - varbuf_add_archqual(&vb, pkgbin->arch); - varbuf_end_str(&vb); - - pkgbin->pkgname_archqual = nfstrsave(vb.buf); - - varbuf_destroy(&vb); - } - return pkgbin->pkgname_archqual; } @@ -126,7 +113,7 @@ pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin, * @return The string representation. */ const char * -pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw) +pkg_name(const struct pkginfo *pkg, enum pkg_name_arch_when pnaw) { return pkgbin_name(pkg, &pkg->installed, pnaw); } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/dpkg/dpkg.git

