Version for multiver. pkgs in summary (bnc #644820)
authorJán Kupec <jkupec@suse.cz>
Mon, 11 Oct 2010 07:33:22 +0000 (09:33 +0200)
committerJán Kupec <jkupec@suse.cz>
Mon, 11 Oct 2010 07:33:22 +0000 (09:33 +0200)
Not only show version if multiple version of the same package
is shown in one summary category, but wherever a package which
has multiple versions (to be) installed is shown.

src/Summary.cc
src/Summary.h

index cdcfcd3..518df2c 100644 (file)
@@ -273,6 +273,18 @@ void Summary::readPool(const zypp::ResPool & pool)
       ++it;
   }
 
+  // find multi-version packages, which actually have mult. versions installed
+  const set<string> & multies = ZConfig::instance().multiversionSpec();
+  for_(name, multies.begin(), multies.end())
+  {
+    ui::Selectable::Ptr s = pool.proxy().lookup(ResKind::package, *name);
+    bool got_multi = s && (
+        s->installedSize() > 1 ||
+        (s->installedSize() == 1 && s->toInstall()) );
+    if (got_multi)
+      multi_installed.insert(*name);
+  }
+
   m.stop();
 }
 
@@ -316,37 +328,29 @@ unsigned Summary::packagesToDowngrade() const
 
 void Summary::writeResolvableList(ostream & out, const ResPairSet & resolvables)
 {
-  // find multi-version packages
-  map<string, unsigned> dupes;
-  // no need to do this if SHOW_VERSION is on
-  if (!(_viewop & SHOW_VERSION))
-  {
-    for_(resit, resolvables.begin(), resolvables.end())
-      dupes[resit->second->name()]++;
-    // remove the single-versions from the map
-    for (map<string, unsigned>::iterator it = dupes.begin(); it != dupes.end(); /**/)
-    {
-      if (it->second == 1)
-        dupes.erase(it++); // postfix! Incrementing before erase
-      else
-        ++it;
-    }
-  }
-
   if ((_viewop & DETAILS) == 0)
   {
     ostringstream s;
     for (ResPairSet::const_iterator resit = resolvables.begin();
         resit != resolvables.end(); ++resit)
-        // name
+    {
+      // name
       s << (resit->second->kind() == ResKind::product ?
-              resit->second->summary() :
-              resit->second->name())
-        // version (if multiple versions are present)
-        << (dupes.find(resit->second->name()) != dupes.end() ?
-             string("-") + resit->second->edition().asString() :
-             string())
-        << " ";
+          resit->second->summary() :
+          resit->second->name());
+
+      // version (if multiple versions are present)
+      if (!(_viewop & SHOW_VERSION) && multi_installed.find(resit->second->name()) != multi_installed.end())
+      {
+        if (resit->first && resit->first->edition() != resit->second->edition())
+          s << "-" << resit->first->edition().asString()
+            << "->" << resit->second->edition().asString();
+        else
+          s << "-" << resit->second->edition().asString();
+      }
+
+      s << " ";
+    }
     mbs_write_wrapped(out, s.str(), 2, _wrap_width);
     out << endl;
     return;
@@ -359,14 +363,21 @@ void Summary::writeResolvableList(ostream & out, const ResPairSet & resolvables)
   {
     TableRow tr;
 
-    // name
-    tr << (resit->second->kind() == ResKind::product ?
+    string name = (resit->second->kind() == ResKind::product ?
         resit->second->summary() :
-        resit->second->name()) +
-      // version (if multiple versions are present)
-      (dupes.find(resit->second->name()) != dupes.end() && !(_viewop & SHOW_VERSION) ?
-        string("-") + resit->second->edition().asString() :
-        string());
+        resit->second->name());
+
+    // version (if multiple versions are present)
+    if (!(_viewop & SHOW_VERSION) && multi_installed.find(resit->second->name()) != multi_installed.end())
+    {
+      if (resit->first && resit->first->edition() != resit->second->edition())
+        name += string("-") + resit->first->edition().asString()
+             + "->" + resit->second->edition().asString();
+      else
+        name += string("-") + resit->second->edition().asString();
+    }
+
+    tr << name;
 
     if (_viewop & SHOW_VERSION)
     {
index e63c36f..8e55f61 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "zypp/base/PtrTypes.h"
 #include "zypp/ByteCount.h"
+#include "zypp/base/DefaultIntegral.h"
 #include "zypp/ResObject.h"
 #include "zypp/ResPool.h"
 
@@ -144,6 +145,10 @@ private:
   /** objects from previous lists that need additional customer contract */
   KindToResPairSet support_needacc;
 
+  /** names of packages which have multiple versions (to-be-)installed */
+  std::set<std::string> multi_installed;
+
+
   /** \name For weak deps info.
    * @{
    */