#include <stddef.h>
#include <string.h>
-#include <ostream>
+#include <sstream>
+#include <algorithm>
#include <vector>
#include <string>
#include <sys/stat.h>
/* Whenever the structures change the major version should be bumped,
whenever the generator changes the minor version should be bumped. */
APT_HEADER_SET(MajorVersion, 10);
- APT_HEADER_SET(MinorVersion, 0);
+ APT_HEADER_SET(MinorVersion, 1);
APT_HEADER_SET(Dirty, false);
APT_HEADER_SET(HeaderSz, sizeof(pkgCache::Header));
return Hash % HeaderP->GetHashTableSize();
}
/*}}}*/
-// Cache::SingleArchFindPkg - Locate a package by name /*{{{*/
-// ---------------------------------------------------------------------
-/* Returns 0 on error, pointer to the package otherwise
- The multiArch enabled methods will fallback to this one as it is (a bit)
- faster for single arch environments and realworld is mostly singlearch… */
-pkgCache::PkgIterator pkgCache::SingleArchFindPkg(const string &Name)
-{
- // Look at the hash bucket
- Package *Pkg = PkgP + HeaderP->PkgHashTableP()[Hash(Name)];
- for (; Pkg != PkgP; Pkg = PkgP + Pkg->NextPackage)
- {
- int const cmp = strcmp(Name.c_str(), StrP + (GrpP + Pkg->Group)->Name);
- if (cmp == 0)
- return PkgIterator(*this, Pkg);
- else if (cmp < 0)
- break;
- }
- return PkgIterator(*this,0);
-}
- /*}}}*/
// Cache::FindPkg - Locate a package by name /*{{{*/
// ---------------------------------------------------------------------
/* Returns 0 on error, pointer to the package otherwise */
if (found == string::npos)
return FindPkg(Name, "native");
string const Arch = Name.substr(found+1);
- /* Beware: This is specialcased to handle pkg:any in dependencies as
- these are linked to virtual pkg:any named packages with all archs.
- If you want any arch from a given pkg, use FindPkg(pkg,arch) */
+ /* Beware: This is specialcased to handle pkg:any in dependencies
+ as these are linked to virtual pkg:any named packages.
+ If you want any arch from a pkg, use FindPkg(pkg,"any") */
if (Arch == "any")
return FindPkg(Name, "any");
return FindPkg(Name.substr(0, found), Arch);
return PkgIterator(*Owner, 0);
/* If we accept any package we simply return the "first"
- package in this group (the last one added). */
+ package in this group */
if (Arch == "any")
return PkgIterator(*Owner, Owner->PkgP + S->FirstPackage);
-
- char const* const myArch = Owner->NativeArch();
- /* Most of the time the package for our native architecture is
- the one we add at first to the cache, but this would be the
- last one we check, so we do it now. */
- if (Arch == "native" || Arch == myArch || Arch == "all") {
- pkgCache::Package *Pkg = Owner->PkgP + S->LastPackage;
- if (strcmp(myArch, Owner->StrP + Pkg->Arch) == 0)
- return PkgIterator(*Owner, Pkg);
- Arch = myArch;
- }
+ if (Arch == "native" || Arch == "all")
+ Arch = Owner->NativeArch();
// Iterate over the list to find the matching arch
for (pkgCache::Package *Pkg = PackageList(); Pkg != Owner->PkgP;
{
string fullname = Name();
if (Pretty == false ||
- (strcmp(Arch(), "all") != 0 &&
+ (strcmp(Arch(), "all") != 0 && strcmp(Arch(), "any") != 0 &&
strcmp(Owner->NativeArch(), Arch()) != 0))
return fullname.append(":").append(Arch());
return fullname;
// ---------------------------------------------------------------------
/* This describes the version from a release-centric manner. The output is a
list of Label:Version/Archive */
+static std::string PkgFileIteratorToRelString(pkgCache::PkgFileIterator const &File)
+{
+ std::string Res;
+ if (File.Label() != 0)
+ Res = Res + File.Label() + ':';
+
+ if (File.Archive() != 0)
+ {
+ if (File.Version() == 0)
+ Res += File.Archive();
+ else
+ Res = Res + File.Version() + '/' + File.Archive();
+ }
+ else
+ {
+ // No release file, print the host name that this came from
+ if (File.Site() == 0 || File.Site()[0] == 0)
+ Res += "localhost";
+ else
+ Res += File.Site();
+ }
+ return Res;
+}
string pkgCache::VerIterator::RelStr() const
{
- bool First = true;
- string Res;
+ std::vector<std::string> RelStrs;
for (pkgCache::VerFileIterator I = this->FileList(); I.end() == false; ++I)
{
// Do not print 'not source' entries'
if (File.Flagged(pkgCache::Flag::NotSource))
continue;
- // See if we have already printed this out..
- bool Seen = false;
- for (pkgCache::VerFileIterator J = this->FileList(); I != J; ++J)
- {
- pkgCache::PkgFileIterator const File2 = J.File();
- if (File2.Label() == 0 || File.Label() == 0)
- continue;
-
- if (strcmp(File.Label(),File2.Label()) != 0)
- continue;
-
- if (File2.Version() == File.Version())
- {
- Seen = true;
- break;
- }
- if (File2.Version() == 0 || File.Version() == 0)
- break;
- if (strcmp(File.Version(),File2.Version()) == 0)
- Seen = true;
- }
-
- if (Seen == true)
+ std::string const RS = PkgFileIteratorToRelString(File);
+ if (std::find(RelStrs.begin(), RelStrs.end(), RS) != RelStrs.end())
continue;
-
- if (First == false)
- Res += ", ";
- else
- First = false;
-
- if (File.Label() != 0)
- Res = Res + File.Label() + ':';
- if (File.Archive() != 0)
- {
- if (File.Version() == 0)
- Res += File.Archive();
- else
- Res = Res + File.Version() + '/' + File.Archive();
- }
- else
- {
- // No release file, print the host name that this came from
- if (File.Site() == 0 || File.Site()[0] == 0)
- Res += "localhost";
- else
- Res += File.Site();
- }
+ RelStrs.push_back(RS);
+ }
+ std::ostringstream os;
+ if (likely(RelStrs.empty() == false))
+ {
+ std::copy(RelStrs.begin(), RelStrs.end()-1, std::ostream_iterator<std::string>(os, ", "));
+ os << *RelStrs.rbegin();
}
if (S->ParentPkg != 0)
- Res.append(" [").append(Arch()).append("]");
- return Res;
+ os << " [" << Arch() << "]";
+ return os.str();
}
/*}}}*/
// VerIterator::MultiArchType - string representing MultiArch flag /*{{{*/