diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-10-11 21:10:31 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-10-11 21:10:31 +0200 |
commit | 5f4db009e50a254f1dd3edaac7b77fe31e1c5f6b (patch) | |
tree | dcfd180c601c1e6afef570b96aa9c2a93c87d5cd | |
parent | 99a2ea5a2737ba6bf346e15a609d927dc03a02ea (diff) |
share description list between "same" versions (LP: #868977)
-rw-r--r-- | apt-pkg/pkgcachegen.cc | 60 | ||||
-rw-r--r-- | debian/changelog | 3 | ||||
-rwxr-xr-x | test/integration/test-bug-601016-description-translation | 34 |
3 files changed, 80 insertions, 17 deletions
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 5147d7547..3545517fe 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -38,6 +38,9 @@ typedef vector<pkgIndexFile *>::iterator FileIterator; template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap; +bool IsDuplicateDescription(pkgCache::DescIterator Desc, + MD5SumValue const &CurMd5, std::string const &CurLang); + // CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/ // --------------------------------------------------------------------- /* We set the dirty flag and make sure that is written to the disk */ @@ -242,8 +245,11 @@ bool pkgCacheGenerator::MergeList(ListParser &List, bool pkgCacheGenerator::MergeListGroup(ListParser &List, std::string const &GrpName) { pkgCache::GrpIterator Grp = Cache.FindGrp(GrpName); + // a group has no data on it's own, only packages have it but these + // stanzas like this come from Translation- files to add descriptions, + // but without a version we don't need a description for it… if (Grp.end() == true) - return _error->Error("Information merge for non-existent group %s requested", GrpName.c_str()); + return true; Dynamic<pkgCache::GrpIterator> DynGrp(Grp); pkgCache::PkgIterator Pkg; @@ -268,6 +274,7 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator // Find the right version to write the description MD5SumValue CurMd5 = List.Description_md5(); + std::string CurLang = List.DescriptionLanguage(); for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) { @@ -275,15 +282,9 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator Dynamic<pkgCache::DescIterator> DynDesc(Desc); map_ptrloc *LastDesc = &Ver->DescriptionList; - // don't add a new description if we have one for the given // md5 && language - bool duplicate = false; - for ( ; Desc.end() == false; ++Desc) - if (MD5SumValue(Desc.md5()) == CurMd5 && - Desc.LanguageCode() == List.DescriptionLanguage()) - duplicate=true; - if (duplicate == true) + if (IsDuplicateDescription(Desc, CurMd5, CurLang) == true) continue; for (Desc = Ver.DescriptionList(); @@ -295,7 +296,7 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator // Add new description void const * const oldMap = Map.Data(); - map_ptrloc const descindex = NewDescription(Desc, List.DescriptionLanguage(), CurMd5, *LastDesc); + map_ptrloc const descindex = NewDescription(Desc, CurLang, CurMd5, *LastDesc); if (oldMap != Map.Data()) LastDesc += (map_ptrloc*) Map.Data() - (map_ptrloc*) oldMap; *LastDesc = descindex; @@ -391,16 +392,34 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator return true; } - /* Record the Description data. Description data always exist in - Packages and Translation-* files. */ + /* Record the Description (it is not translated) */ + MD5SumValue CurMd5 = List.Description_md5(); + if (CurMd5.Value().empty() == true) + return true; + std::string CurLang = List.DescriptionLanguage(); + + /* Before we add a new description we first search in the group for + a version with a description of the same MD5 - if so we reuse this + description group instead of creating our own for this version */ + pkgCache::GrpIterator Grp = Pkg.Group(); + for (pkgCache::PkgIterator P = Grp.PackageList(); + P.end() == false; P = Grp.NextPkg(P)) + { + for (pkgCache::VerIterator V = P.VersionList(); + V.end() == false; ++V) + { + if (IsDuplicateDescription(V.DescriptionList(), CurMd5, "") == false) + continue; + Ver->DescriptionList = V->DescriptionList; + return true; + } + } + + // We haven't found reusable descriptions, so add the first description pkgCache::DescIterator Desc = Ver.DescriptionList(); Dynamic<pkgCache::DescIterator> DynDesc(Desc); map_ptrloc *LastDesc = &Ver->DescriptionList; - // Skip to the end of description set - for (; Desc.end() == false; LastDesc = &Desc->NextDesc, ++Desc); - - // Add new description oldMap = Map.Data(); map_ptrloc const descindex = NewDescription(Desc, List.DescriptionLanguage(), List.Description_md5(), *LastDesc); if (oldMap != Map.Data()) @@ -1403,3 +1422,14 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O return true; } /*}}}*/ +// IsDuplicateDescription /*{{{*/ +bool IsDuplicateDescription(pkgCache::DescIterator Desc, + MD5SumValue const &CurMd5, std::string const &CurLang) +{ + for ( ; Desc.end() == false; ++Desc) + if (MD5SumValue(Desc.md5()) == CurMd5 && Desc.LanguageCode() == CurLang) + return true; + return false; +} + /*}}}*/ + diff --git a/debian/changelog b/debian/changelog index 1e5babe41..b7f199609 100644 --- a/debian/changelog +++ b/debian/changelog @@ -24,6 +24,7 @@ apt (0.8.16~exp7) UNRELEASEDexperimental; urgency=low - do not builtin languages only if none is forced (Closes: #643787) * apt-pkg/pkgcachegen.cc: - refactor MergeList by creating -Group, -Package and -Version specialist + - share description list between "same" versions (LP: #868977) [ Michael Vogt ] * apt-pkg/contrib/configuration.cc: @@ -38,7 +39,7 @@ apt (0.8.16~exp7) UNRELEASEDexperimental; urgency=low * ftparchive/cachedb.cc: - fix buffersize in bytes2hex - -- David Kalnischkies <kalnischkies@gmail.com> Tue, 11 Oct 2011 18:32:13 +0200 + -- David Kalnischkies <kalnischkies@gmail.com> Tue, 11 Oct 2011 21:07:38 +0200 apt (0.8.16~exp6) experimental; urgency=low diff --git a/test/integration/test-bug-601016-description-translation b/test/integration/test-bug-601016-description-translation index 44ab91900..03fddbfda 100755 --- a/test/integration/test-bug-601016-description-translation +++ b/test/integration/test-bug-601016-description-translation @@ -4,7 +4,7 @@ set -e TESTDIR=$(readlink -f $(dirname $0)) . $TESTDIR/framework setupenvironment -configarchitecture "i386" +configarchitecture 'i386' 'amd64' # we need a valid locale here, otherwise the language configuration # will be overridden by LC_ALL=C @@ -22,8 +22,22 @@ Size: 2140230 MD5sum: 74769bfbcef9ebc4fa74f7a5271b9c08 Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c" +PACKAGESTANZA2='Package: apt +Priority: important +Section: admin +Installed-Size: 5984 +Maintainer: APT Development Team <deity@lists.debian.org> +Architecture: amd64 +Version: 0.8.7 +Filename: pool/main/a/apt/apt_0.8.7_amd64.deb +Size: 2210342 +MD5sum: 4a869bfbdef9ebc9fa74f7a5271e8d1a +Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c' echo "$PACKAGESTANZA +Description: Advanced front-end for dpkg + +$PACKAGESTANZA2 Description: Advanced front-end for dpkg" > aptarchive/Packages echo "Package: apt @@ -53,6 +67,13 @@ Description-${LOCALE}: Mächtige Oberfläche für dpkg APT-Dselect-Methode. Beides sind einfache und sicherere Wege, um Pakete zu installieren und Upgrades durchzuführen. " +LOCALESTANZA2="$PACKAGESTANZA2 +Description-${LOCALE}: Mächtige Oberfläche für dpkg + Das Paket bietet dem Nutzer technisch führende Methoden für den Zugriff + auf den dpkg-Paketmanager. Es beinhaltet das apt-get-Werkzeug und die + APT-Dselect-Methode. Beides sind einfache und sicherere Wege, + um Pakete zu installieren und Upgrades durchzuführen. +" testrun() { echo "Acquire::Languages { \"${LOCALE}\"; \"en\"; };" > rootdir/etc/apt/apt.conf.d/00languages @@ -60,6 +81,8 @@ testrun() { rm -rf rootdir/var/lib/apt/lists setupaptarchive testequal "$LOCALESTANZA" aptcache show apt -o Test=File-${LOCALE} + testequal "$LOCALESTANZA" aptcache show apt:i386 -o Test=File-${LOCALE} + testequal "$LOCALESTANZA2" aptcache show apt:amd64 -o Test=File-${LOCALE} testequal "$NOLONGSTANZA" aptcache show apt -o Acquire::Languages="ww" -o Test=File-${LOCALE} testequal "$LOCALESTANZA" aptcache show apt -o Acquire::Languages::="ww" -o Test=File-${LOCALE} LC_ALL=C testequal "$ENGLISHSTANZA" aptcache show apt -o Test=File-${LOCALE} @@ -73,6 +96,9 @@ testrun() { testrun echo "$PACKAGESTANZA +Description: Advanced front-end for dpkg + +$PACKAGESTANZA2 Description: Advanced front-end for dpkg" > aptarchive/Packages echo "Package: apt @@ -88,5 +114,11 @@ Description-en: Advanced front-end for dpkg It provides the apt-get utility and APT dselect method that provides a simpler, safer way to install and upgrade packages. " +ENGLISHSTANZA2="$PACKAGESTANZA2 +Description-en: Advanced front-end for dpkg + This is Debian's next generation front-end for the dpkg package manager. + It provides the apt-get utility and APT dselect method that provides a + simpler, safer way to install and upgrade packages. +" testrun |