From c4cca79156ef5651e90772bae5f4aa11f669907d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 11 Nov 2011 16:03:40 +0100 Subject: [PATCH] - provide a {Package,Version}List similar to {Package,Version}Set * cmdline/apt-{get,cache,mark}.cc: - use Lists instead of Sets if input order should be preserved for commands accepting lists of packages, e.g. policy (Closes: #625960) --- apt-pkg/cacheset.h | 110 +++++++++++++++++++--- cmdline/apt-cache.cc | 28 +++--- cmdline/apt-get.cc | 14 +-- cmdline/apt-mark.cc | 16 ++-- debian/changelog | 6 +- test/integration/Packages-pdiff-usage-new | 26 ++--- 6 files changed, 146 insertions(+), 54 deletions(-) diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 411b3151..a23659ef 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -159,8 +160,8 @@ template class PackageContainer : public PackageContainerInterf Container _cont; public: /*{{{*/ /** \brief smell like a pkgCache::PkgIterator */ - class const_iterator : public PackageContainerInterface::const_iterator, - public std::iterator {/*{{{*/ + class const_iterator : public PackageContainerInterface::const_iterator,/*{{{*/ + public std::iterator { typename Container::const_iterator _iter; public: const_iterator(typename Container::const_iterator i) : _iter(i) {} @@ -172,22 +173,37 @@ public: /*{{{*/ inline bool operator==(const_iterator const &i) const { return _iter == i._iter; }; friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } }; - // we are not going to allow modify our pkgiterators (it doesn't make sense)… - typedef APT::PackageContainer::const_iterator iterator; + class iterator : public PackageContainerInterface::const_iterator, + public std::iterator { + typename Container::iterator _iter; + public: + iterator(typename Container::iterator i) : _iter(i) {} + pkgCache::PkgIterator getPkg(void) const { return *_iter; } + inline pkgCache::PkgIterator operator*(void) const { return *_iter; }; + operator typename Container::iterator(void) const { return _iter; } + operator typename PackageContainer::const_iterator() { return PackageContainer::const_iterator(_iter); } + inline void operator++(void) { ++_iter; }; + inline bool operator!=(iterator const &i) const { return _iter != i._iter; }; + inline bool operator==(iterator const &i) const { return _iter == i._iter; }; + friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } + }; /*}}}*/ bool insert(pkgCache::PkgIterator const &P) { if (P.end() == true) return false; _cont.insert(P); return true; }; template void insert(PackageContainer const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); }; void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }; + bool empty() const { return _cont.empty(); }; void clear() { return _cont.clear(); }; - void erase(iterator position) { _cont.erase((typename Container::const_iterator)position); }; + void erase(iterator position) { _cont.erase((typename Container::iterator)position); }; size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); }; void erase(iterator first, iterator last) { _cont.erase(first, last); }; size_t size() const { return _cont.size(); }; const_iterator begin() const { return const_iterator(_cont.begin()); }; const_iterator end() const { return const_iterator(_cont.end()); }; + iterator begin() { return iterator(_cont.begin()); }; + iterator end() { return iterator(_cont.end()); }; const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }; void setConstructor(Constructor const &by) { ConstructedBy = by; }; @@ -318,7 +334,25 @@ private: /*{{{*/ Constructor ConstructedBy; /*}}}*/ }; /*}}}*/ + +template<> template void PackageContainer >::insert(PackageContainer const &pkgcont) { + for (typename PackageContainer::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p) + _cont.push_back(*p); +}; +// these two are 'inline' as otherwise the linker has problems with seeing these untemplated +// specializations again and again - but we need to see them, so that library users can use them +template<> inline bool PackageContainer >::insert(pkgCache::PkgIterator const &P) { + if (P.end() == true) + return false; + _cont.push_back(P); + return true; +}; +template<> inline void PackageContainer >::insert(const_iterator begin, const_iterator end) { + for (const_iterator p = begin; p != end; ++p) + _cont.push_back(*p); +}; typedef PackageContainer > PackageSet; +typedef PackageContainer > PackageList; class VersionContainerInterface { /*{{{*/ /** \class APT::VersionContainerInterface @@ -406,6 +440,13 @@ public: std::list const &mods, CacheSetHelper &helper); + + static bool FromDependency(VersionContainerInterface * const vci, + pkgCacheFile &Cache, + pkgCache::DepIterator const &D, + Version const &selector, + CacheSetHelper &helper); + protected: /*{{{*/ /** \brief returns the candidate version of the package @@ -425,7 +466,7 @@ protected: /*{{{*/ }; /*}}}*/ template class VersionContainer : public VersionContainerInterface {/*{{{*/ -/** \class APT::PackageContainer +/** \class APT::VersionContainer Simple wrapper around a container class like std::set to provide a similar interface to a set of versions as to the complete set of all versions in the @@ -446,8 +487,20 @@ public: /*{{{*/ inline bool operator==(const_iterator const &i) const { return _iter == i._iter; }; friend std::ostream& operator<<(std::ostream& out, const_iterator i) { return operator<<(out, *i); } }; - // we are not going to allow modify our veriterators (it doesn't make sense)… - typedef APT::VersionContainer::const_iterator iterator; + class iterator : public VersionContainerInterface::const_iterator, + public std::iterator { + typename Container::iterator _iter; + public: + iterator(typename Container::iterator i) : _iter(i) {} + pkgCache::VerIterator getVer(void) const { return *_iter; } + inline pkgCache::VerIterator operator*(void) const { return *_iter; }; + operator typename Container::iterator(void) const { return _iter; } + operator typename VersionContainer::const_iterator() { return VersionContainer::const_iterator(_iter); } + inline void operator++(void) { ++_iter; }; + inline bool operator!=(iterator const &i) const { return _iter != i._iter; }; + inline bool operator==(iterator const &i) const { return _iter == i._iter; }; + friend std::ostream& operator<<(std::ostream& out, iterator i) { return operator<<(out, *i); } + }; /*}}}*/ bool insert(pkgCache::VerIterator const &V) { if (V.end() == true) return false; _cont.insert(V); return true; }; @@ -455,13 +508,15 @@ public: /*{{{*/ void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }; bool empty() const { return _cont.empty(); }; void clear() { return _cont.clear(); }; - void erase(iterator position) { _cont.erase((typename Container::const_iterator)position); }; - size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); }; + void erase(iterator position) { _cont.erase((typename Container::iterator)position); }; + size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); }; void erase(iterator first, iterator last) { _cont.erase(first, last); }; size_t size() const { return _cont.size(); }; const_iterator begin() const { return const_iterator(_cont.begin()); }; const_iterator end() const { return const_iterator(_cont.end()); }; + iterator begin() { return iterator(_cont.begin()); }; + iterator end() { return iterator(_cont.end()); }; const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }; /** \brief returns all versions specified on the commandline @@ -520,7 +575,7 @@ public: /*{{{*/ return FromPackage(Cache, P, fallback, helper); } static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) { - return FromPackage(Cache, P, CANDINST); + return FromPackage(Cache, P, CANDIDATE); } static std::map GroupedFromCommandLine( @@ -547,8 +602,41 @@ public: /*{{{*/ return GroupedFromCommandLine(Cache, cmdline, mods, fallback, helper); } + + static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, + Version const &selector, CacheSetHelper &helper) { + VersionContainer vercon; + VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper); + return vercon; + } + static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D, + Version const &selector) { + CacheSetHelper helper; + return FromPackage(Cache, D, selector, helper); + } + static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) { + return FromPackage(Cache, D, CANDIDATE); + } /*}}}*/ }; /*}}}*/ + +template<> template void VersionContainer >::insert(VersionContainer const &vercont) { + for (typename VersionContainer::const_iterator v = vercont.begin(); v != vercont.end(); ++v) + _cont.push_back(*v); +}; +// these two are 'inline' as otherwise the linker has problems with seeing these untemplated +// specializations again and again - but we need to see them, so that library users can use them +template<> inline bool VersionContainer >::insert(pkgCache::VerIterator const &V) { + if (V.end() == true) + return false; + _cont.push_back(V); + return true; +}; +template<> inline void VersionContainer >::insert(const_iterator begin, const_iterator end) { + for (const_iterator v = begin; v != end; ++v) + _cont.push_back(*v); +}; typedef VersionContainer > VersionSet; +typedef VersionContainer > VersionList; } #endif diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index ee3416ff..65d7b0cc 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -199,9 +199,9 @@ bool UnMet(CommandLine &CmdL) else { CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); - APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, - APT::VersionSet::CANDIDATE, helper); - for (APT::VersionSet::iterator V = verset.begin(); V != verset.end(); ++V) + APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, + APT::VersionList::CANDIDATE, helper); + for (APT::VersionList::iterator V = verset.begin(); V != verset.end(); ++V) if (ShowUnMet(V, Important) == false) return false; } @@ -215,9 +215,9 @@ bool DumpPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; APT::CacheSetHelper helper(true, GlobalError::NOTICE); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); + APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { cout << "Package: " << Pkg.FullName(true) << endl; cout << "Versions: " << endl; @@ -588,7 +588,7 @@ bool ShowDepends(CommandLine &CmdL, bool const RevDepends) return false; CacheSetHelperVirtuals helper(false); - APT::VersionSet verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper); if (verset.empty() == true && helper.virtualPkgs.empty() == true) return _error->Error(_("No packages found")); std::vector Shown(Cache->Head().PackageCount); @@ -1365,10 +1365,10 @@ bool ShowPackage(CommandLine &CmdL) { pkgCacheFile CacheFile; CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); - APT::VersionSet::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? - APT::VersionSet::ALL : APT::VersionSet::CANDIDATE; - APT::VersionSet const verset = APT::VersionSet::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); - for (APT::VersionSet::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) + APT::VersionList::Version const select = _config->FindB("APT::Cache::AllVersions", true) ? + APT::VersionList::ALL : APT::VersionList::CANDIDATE; + APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); + for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver) == false) return false; @@ -1531,8 +1531,8 @@ bool Policy(CommandLine &CmdL) // Print out detailed information for each package APT::CacheSetHelper helper(true, GlobalError::NOTICE); - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1, helper); + for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { cout << Pkg.FullName(true) << ":" << endl; @@ -1608,8 +1608,8 @@ bool Madison(CommandLine &CmdL) for (const char **I = CmdL.FileList + 1; *I != 0; I++) { _error->PushToStack(); - APT::PackageSet pkgset = APT::PackageSet::FromString(CacheFile, *I, helper); - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + APT::PackageList pkgset = APT::PackageList::FromString(CacheFile, *I, helper); + for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { for (pkgCache::VerIterator V = Pkg.VersionList(); V.end() == false; ++V) { diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 5ead83dd..763f0eda 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -2293,8 +2293,8 @@ bool DoDownload(CommandLine &CmdL) return false; APT::CacheSetHelper helper(c0out); - APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache, - CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + APT::VersionList verset = APT::VersionList::FromCommandLine(Cache, + CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper); if (verset.empty() == true) return false; @@ -2306,7 +2306,7 @@ bool DoDownload(CommandLine &CmdL) pkgRecords Recs(Cache); pkgSourceList *SrcList = Cache.GetSourceList(); - for (APT::VersionSet::const_iterator Ver = verset.begin(); + for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) { @@ -3165,14 +3165,14 @@ bool DoChangelog(CommandLine &CmdL) return false; APT::CacheSetHelper helper(c0out); - APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache, - CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper); + APT::VersionList verset = APT::VersionList::FromCommandLine(Cache, + CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper); if (verset.empty() == true) return false; pkgAcquire Fetcher; if (_config->FindB("APT::Get::Print-URIs", false) == true) - for (APT::VersionSet::const_iterator Ver = verset.begin(); + for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) return DownloadChangelog(Cache, Fetcher, Ver, ""); @@ -3195,7 +3195,7 @@ bool DoChangelog(CommandLine &CmdL) return _error->Errno("mkdtemp", "mkdtemp failed"); } - for (APT::VersionSet::const_iterator Ver = verset.begin(); + for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) { diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index 339cbdf4..dbbef501 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -34,14 +34,14 @@ bool DoAuto(CommandLine &CmdL) if (unlikely(Cache == NULL || DepCache == NULL)) return false; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1); if (pkgset.empty() == true) return _error->Error(_("No packages found")); bool MarkAuto = strcasecmp(CmdL.FileList[0],"auto") == 0; int AutoMarkChanged = 0; - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (Pkg->CurrentVer == 0) { @@ -81,7 +81,7 @@ bool DoMarkAuto(CommandLine &CmdL) if (unlikely(Cache == NULL || DepCache == NULL)) return false; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1); if (pkgset.empty() == true) return _error->Error(_("No packages found")); @@ -89,7 +89,7 @@ bool DoMarkAuto(CommandLine &CmdL) bool const Verbose = _config->FindB("APT::MarkAuto::Verbose", false); int AutoMarkChanged = 0; - for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (Pkg->CurrentVer == 0 || (((*DepCache)[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto) == MarkAuto) @@ -157,13 +157,13 @@ bool DoHold(CommandLine &CmdL) if (unlikely(Cache == NULL)) return false; - APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1); if (pkgset.empty() == true) return _error->Error(_("No packages found")); bool const MarkHold = strcasecmp(CmdL.FileList[0],"hold") == 0; - for (APT::PackageSet::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if ((Pkg->SelectedState == pkgCache::State::Hold) == MarkHold) { @@ -181,7 +181,7 @@ bool DoHold(CommandLine &CmdL) if (_config->FindB("APT::Mark::Simulate", false) == true) { - for (APT::PackageSet::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (MarkHold == false) ioprintf(c1out,_("%s set on hold.\n"), Pkg.FullName(true).c_str()); @@ -201,7 +201,7 @@ bool DoHold(CommandLine &CmdL) if (dpkg == NULL) return _error->Errno("DoHold", "fdopen on dpkg stdin failed"); - for (APT::PackageSet::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) + for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) { if (MarkHold == true) { diff --git a/debian/changelog b/debian/changelog index 95ad7368..058e2926 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,8 +12,12 @@ apt (0.8.16~exp8) experimental; urgency=low * apt-pkg/cacheset.cc: - make the cachesets real containers which can embedding any container to be able to use the same interface regardless of set or list usage + - provide a {Package,Version}List similar to {Package,Version}Set + * cmdline/apt-{get,cache,mark}.cc: + - use Lists instead of Sets if input order should be preserved for + commands accepting lists of packages, e.g. policy (Closes: #625960) - -- David Kalnischkies Wed, 09 Nov 2011 17:21:02 +0100 + -- David Kalnischkies Fri, 11 Nov 2011 15:55:13 +0100 apt (0.8.16~exp7) experimental; urgency=low diff --git a/test/integration/Packages-pdiff-usage-new b/test/integration/Packages-pdiff-usage-new index 9157596a..4f374b37 100644 --- a/test/integration/Packages-pdiff-usage-new +++ b/test/integration/Packages-pdiff-usage-new @@ -1,16 +1,3 @@ -Package: newstuff -Version: 1.0 -Architecture: i386 -Maintainer: Joe Sixpack -Installed-Size: 101 -Filename: pool/newstuff_1.0_i386.deb -Size: 101100 -MD5sum: 311aeeadf78324aaff1ceaf3e1f76671 -SHA1: 3c695e028f7a1ae324deeddaaa1242desa81088c -SHA256: b46fd154615edefab321cc56a5cc0e7deaef23e2da3e4f129727fd660f28f050 -Description: some cool and shiny new stuff - This package will appear in the next mirror update - Package: apt Priority: important Section: admin @@ -35,3 +22,16 @@ Description: Advanced front-end for dpkg . APT features complete installation ordering, multiple source capability and several other unique features, see the Users Guide in apt-doc. + +Package: newstuff +Version: 1.0 +Architecture: i386 +Maintainer: Joe Sixpack +Installed-Size: 101 +Filename: pool/newstuff_1.0_i386.deb +Size: 101100 +MD5sum: 311aeeadf78324aaff1ceaf3e1f76671 +SHA1: 3c695e028f7a1ae324deeddaaa1242desa81088c +SHA256: b46fd154615edefab321cc56a5cc0e7deaef23e2da3e4f129727fd660f28f050 +Description: some cool and shiny new stuff + This package will appear in the next mirror update -- 2.20.1