Просмотр исходного кода

make GetLocalitySortedVersionSet more generic

No reason in and of by itself at the moment, but prepares for the goal
of having 'apt search' and 'apt-cache search' using the same code now
that they at least support the same stuff. The 'apt' code is just a
multitude slower at the moment…

Git-Dch: Ignore
David Kalnischkies лет назад: 12
Родитель
Сommit
25594bb5bd

+ 1 - 0
apt-pkg/cachefilter.h

@@ -73,6 +73,7 @@ public:
 	bool operator() (pkgCache::VerIterator const &Ver);
 	bool operator() (pkgCache::VerIterator const &Ver);
 	~PackageArchitectureMatchesSpecification();
 	~PackageArchitectureMatchesSpecification();
 };
 };
+									/*}}}*/
 
 
 #else
 #else
 
 

+ 46 - 43
apt-private/private-cacheset.cc

@@ -14,74 +14,77 @@
 
 
 #include <apti18n.h>
 #include <apti18n.h>
 
 
-bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, 
-                                 LocalitySortedVersionSet &output_set,
-                                 OpProgress &progress)
+bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
+                                 APT::VersionContainerInterface * const vci,
+                                 OpProgress * const progress)
 {
 {
     Matcher null_matcher = Matcher();
     Matcher null_matcher = Matcher();
-    return GetLocalitySortedVersionSet(CacheFile, output_set, 
+    return GetLocalitySortedVersionSet(CacheFile, vci,
                                        null_matcher, progress);
                                        null_matcher, progress);
 }
 }
 
 
-bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, 
-                                 LocalitySortedVersionSet &output_set,
+bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
+                                 APT::VersionContainerInterface * const vci,
                                  Matcher &matcher,
                                  Matcher &matcher,
-                                 OpProgress &progress)
+                                 OpProgress * const progress)
 {
 {
    pkgCache *Cache = CacheFile.GetPkgCache();
    pkgCache *Cache = CacheFile.GetPkgCache();
    pkgDepCache *DepCache = CacheFile.GetDepCache();
    pkgDepCache *DepCache = CacheFile.GetDepCache();
+   APT::CacheSetHelper helper(false);
 
 
    int Done=0;
    int Done=0;
-   progress.SubProgress(Cache->Head().PackageCount, _("Sorting"));
+   if (progress != NULL)
+      progress->SubProgress(Cache->Head().PackageCount, _("Sorting"));
+
+   bool const insertCurrentVer = _config->FindB("APT::Cmd::Installed", false);
+   bool const insertUpgradable = _config->FindB("APT::Cmd::Upgradable", false);
+   bool const insertManualInstalled = _config->FindB("APT::Cmd::Manual-Installed", false);
+
    for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
    for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
    {
    {
-      if (Done%500 == 0)
-         progress.Progress(Done);
-      Done++;
+      if (progress != NULL)
+      {
+	 if (Done % 500 == 0)
+	    progress->Progress(Done);
+	 ++Done;
+      }
+
+      // exclude virtual pkgs
+      if (P->VersionList == 0)
+	 continue;
 
 
       if ((matcher)(P) == false)
       if ((matcher)(P) == false)
-         continue;
+	 continue;
 
 
-      // exclude virtual pkgs
-      if (P.VersionList() == 0)
-         continue;
       pkgDepCache::StateCache &state = (*DepCache)[P];
       pkgDepCache::StateCache &state = (*DepCache)[P];
-      if (_config->FindB("APT::Cmd::Installed") == true)
+      if (insertCurrentVer == true)
       {
       {
-         if (P.CurrentVer() != NULL)
-         {
-            output_set.insert(P.CurrentVer());
-         }
+	 if (P->CurrentVer != 0)
+	    vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::INSTALLED, helper);
       }
       }
-      else if (_config->FindB("APT::Cmd::Upgradable") == true)
+      else if (insertUpgradable == true)
       {
       {
-         if(P.CurrentVer() && state.Upgradable())
-         {
-             pkgPolicy *policy = CacheFile.GetPolicy();
-             output_set.insert(policy->GetCandidateVer(P));
-         }
+	 if(P.CurrentVer() && state.Upgradable())
+	    vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper);
       }
       }
-      else if (_config->FindB("APT::Cmd::Manual-Installed") == true)
+      else if (insertManualInstalled == true)
       {
       {
-         if (P.CurrentVer() && 
-             ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
-         {
-             pkgPolicy *policy = CacheFile.GetPolicy();
-             output_set.insert(policy->GetCandidateVer(P));
-         }
+	 if (P.CurrentVer() &&
+	       ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
+	    vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper);
       }
       }
-      else 
+      else
       {
       {
-         pkgPolicy *policy = CacheFile.GetPolicy();
-         if (policy->GetCandidateVer(P).IsGood())
-            output_set.insert(policy->GetCandidateVer(P));
-         else 
-            // no candidate, this may happen for packages in 
-            // dpkg "deinstall ok config-file" state - we pick the first ver
-            // (which should be the only one)
-            output_set.insert(P.VersionList());
+         if (vci->FromPackage(vci, CacheFile, P, APT::VersionContainerInterface::CANDIDATE, helper) == false)
+	 {
+	    // no candidate, this may happen for packages in
+	    // dpkg "deinstall ok config-file" state - we pick the first ver
+	    // (which should be the only one)
+	    vci->insert(P.VersionList());
+	 }
       }
       }
    }
    }
-   progress.Done();
+   if (progress != NULL)
+      progress->Done();
    return true;
    return true;
 }
 }

+ 6 - 6
apt-private/private-cacheset.h

@@ -62,13 +62,13 @@ public:
 };
 };
 
 
 // FIXME: add default argument for OpProgress (or overloaded function)
 // FIXME: add default argument for OpProgress (or overloaded function)
-bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, 
-                                    LocalitySortedVersionSet &output_set,
+bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
+                                    APT::VersionContainerInterface * const vci,
                                     Matcher &matcher,
                                     Matcher &matcher,
-                                    OpProgress &progress);
-bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile, 
-                                    LocalitySortedVersionSet &output_set,
-                                    OpProgress &progress);
+                                    OpProgress * const progress);
+bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
+                                    APT::VersionContainerInterface * const vci,
+                                    OpProgress * const progress);
 
 
 
 
 // CacheSetHelper saving virtual packages				/*{{{*/
 // CacheSetHelper saving virtual packages				/*{{{*/

+ 1 - 1
apt-private/private-list.cc

@@ -127,7 +127,7 @@ bool DoList(CommandLine &Cmd)
                             Cache->Head().PackageCount, 
                             Cache->Head().PackageCount, 
                             Cache->Head().PackageCount,
                             Cache->Head().PackageCount,
                             _("Listing"));
                             _("Listing"));
-   GetLocalitySortedVersionSet(CacheFile, bag, matcher, progress);
+   GetLocalitySortedVersionSet(CacheFile, &bag, matcher, &progress);
    bool const ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false);
    bool const ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false);
    std::map<std::string, std::string> output_map;
    std::map<std::string, std::string> output_map;
    for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); ++V)
    for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); ++V)

+ 10 - 7
apt-private/private-search.cc

@@ -63,7 +63,7 @@ bool FullTextSearch(CommandLine &CmdL)					/*{{{*/
    LocalitySortedVersionSet bag;
    LocalitySortedVersionSet bag;
    OpTextProgress progress(*_config);
    OpTextProgress progress(*_config);
    progress.OverallProgress(0, 100, 50,  _("Sorting"));
    progress.OverallProgress(0, 100, 50,  _("Sorting"));
-   GetLocalitySortedVersionSet(CacheFile, bag, progress);
+   GetLocalitySortedVersionSet(CacheFile, &bag, &progress);
    LocalitySortedVersionSet::iterator V = bag.begin();
    LocalitySortedVersionSet::iterator V = bag.begin();
 
 
    progress.OverallProgress(50, 100, 50,  _("Full Text Search"));
    progress.OverallProgress(50, 100, 50,  _("Full Text Search"));
@@ -77,6 +77,7 @@ bool FullTextSearch(CommandLine &CmdL)					/*{{{*/
       format += "  ${LongDescription}\n";
       format += "  ${LongDescription}\n";
 
 
    int Done = 0;
    int Done = 0;
+   std::vector<bool> PkgsDone(Cache->Head().PackageCount, false);
    for ( ;V != bag.end(); ++V)
    for ( ;V != bag.end(); ++V)
    {
    {
       if (Done%500 == 0)
       if (Done%500 == 0)
@@ -84,10 +85,11 @@ bool FullTextSearch(CommandLine &CmdL)					/*{{{*/
       ++Done;
       ++Done;
 
 
       // we want to list each package only once
       // we want to list each package only once
-      char const * const PkgName = V.ParentPkg().Name();
-      if (output_map.find(PkgName) != output_map.end())
+      pkgCache::PkgIterator const P = V.ParentPkg();
+      if (PkgsDone[P->ID] == true)
 	 continue;
 	 continue;
 
 
+      char const * const PkgName = P.Name();
       pkgCache::DescIterator Desc = V.TranslatedDescription();
       pkgCache::DescIterator Desc = V.TranslatedDescription();
       pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
       pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
       std::string const LongDesc = parser.LongDesc();
       std::string const LongDesc = parser.LongDesc();
@@ -106,10 +108,11 @@ bool FullTextSearch(CommandLine &CmdL)					/*{{{*/
       }
       }
       if (all_found == true)
       if (all_found == true)
       {
       {
-            std::stringstream outs;
-            ListSingleVersion(CacheFile, records, V, outs, format);
-            output_map.insert(std::make_pair<std::string, std::string>(
-                                 PkgName, outs.str()));
+	 PkgsDone[P->ID] = true;
+	 std::stringstream outs;
+	 ListSingleVersion(CacheFile, records, V, outs, format);
+	 output_map.insert(std::make_pair<std::string, std::string>(
+		  PkgName, outs.str()));
       }
       }
    }
    }
    APT_FREE_PATTERNS();
    APT_FREE_PATTERNS();