backup
authorMichael Andres <ma@suse.de>
Wed, 28 Nov 2007 00:01:44 +0000 (00:01 +0000)
committerMichael Andres <ma@suse.de>
Wed, 28 Nov 2007 00:01:44 +0000 (00:01 +0000)
devel/devel.ma/NewPool.cc
devel/devel.ma/defstr.txt [new file with mode: 0644]
zypp/CMakeLists.txt
zypp/pool/PoolImpl.cc
zypp/pool/Res2Sat.cc [new file with mode: 0644]
zypp/sat/IdStr.cc
zypp/sat/IdStr.h
zypp/sat/Pool.h
zypp/sat/Repo.cc
zypp/sat/Solvable.cc
zypp/sat/Solvable.h

index ed4b972..d901827 100644 (file)
@@ -409,6 +409,13 @@ void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIter
 bool isTrue()  { return true; }
 bool isFalse() { return false; }
 
+void dumpIdStr()
+{
+  for ( unsigned i = 0; i < 30; ++i )
+  {
+    DBG << i << '\t' << sat::IdStr( i ) << endl;
+  }
+}
 
 /******************************************************************
 **
@@ -424,6 +431,11 @@ int main( int argc, char * argv[] )
   sat::Pool satpool( sat::Pool::instance() );
 
 #if 0
+  //sat::Repo r( satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) );
+  sat::Repo s( satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) );
+
+  std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Print() );
+
   ///////////////////////////////////////////////////////////////////
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
diff --git a/devel/devel.ma/defstr.txt b/devel/devel.ma/defstr.txt
new file mode 100644 (file)
index 0000000..1e98f8b
--- /dev/null
@@ -0,0 +1,31 @@
+0      <NULL>
+1      
+2      solvable:name
+3      solvable:arch
+4      solvable:evr
+5      solvable:vendor
+6      solvable:provides
+7      solvable:obsoletes
+8      solvable:conflicts
+9      solvable:requires
+10     solvable:recommends
+11     solvable:suggests
+12     solvable:supplements
+13     solvable:enhances
+14     solvable:freshens
+15     rpm:dbid
+16     solvable:prereqmarker
+17     solvable:filemarker
+18     namespace:installed
+19     namespace:modalias
+20     system:system
+21     src
+22     nosrc
+23     noarch
+24     <NULL>
+25     <NULL>
+26     <NULL>
+27     <NULL>
+28     <NULL>
+29     <NULL>
+
index c431616..7e8c06a 100644 (file)
@@ -577,6 +577,7 @@ SET( zypp_pool_SRCS
   pool/GetResolvablesToInsDel.cc
   pool/PoolImpl.cc
   pool/PoolStats.cc
+  pool/Res2Sat.cc
 )
 
 SET( zypp_pool_HEADERS
index 87cae3b..606dddb 100644 (file)
@@ -38,6 +38,8 @@ namespace zypp
   namespace pool
   { /////////////////////////////////////////////////////////////////
 
+    void pi2sat( const PoolItem & pi_r, sat::Solvable & slv_r );
+
     ///////////////////////////////////////////////////////////////////
     //
     // METHOD NAME : NameHash::NameHash
@@ -240,6 +242,7 @@ namespace zypp
       debug::Measure mnf( "Sync changes to sat-pool..." );
       MIL << "Pool: " << _serial << ": Sync changes to sat-pool... " << _satSyncRequired << endl;
 
+      // collect unsynced PoolItems per repository.
       std::map<std::string, std::list<PoolItem> > todo;
       for_( it, begin(), end() )
       {
@@ -249,17 +252,25 @@ namespace zypp
         }
       }
 
+      // add the missing PoolItems.
       DBG << "Update missing repos... " << todo.size() << endl;
+      void res2sat( const ResObject::constPtr & res_r, sat::Solvable & slv_r );
+
       for_( it, todo.begin(), todo.end() )
       {
-        DBG << "Update " << it->first << ": " << it->second.size() << endl;
+        DBG << "Update repo " << it->first << ": " << it->second.size() << endl;
         sat::Repo repo( sat::Pool::instance().reposInsert( it->first ) );
         sat::Solvable first( repo.addSolvables( it->second.size() ) );
         DBG << " starting at " << first << endl;
+
+        sat::Solvable cur( first );
         for_( pit, it->second.begin(), it->second.end() )
         {
-          // *pit to sat::Solvable
+          res2sat( *pit, cur );
+          (*pit).rememberSatSolvable( cur );
+          cur = cur.nextInRepo();
         }
+        break;
       }
 
       //_satSyncRequired.remember( _serial );
@@ -268,8 +279,8 @@ namespace zypp
 
     ///////////////////////////////////////////////////////////////////
     //
-    // METHOD NAME : PoolImpl::satSync
-    // METHOD TYPE : void
+    // METHOD NAME : PoolImpl::find
+    // METHOD TYPE : PoolItem
     //
     PoolItem PoolImpl::find( const sat::Solvable & slv_r ) const
     {
diff --git a/zypp/pool/Res2Sat.cc b/zypp/pool/Res2Sat.cc
new file mode 100644 (file)
index 0000000..2011046
--- /dev/null
@@ -0,0 +1,146 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/pool/Res2Sat.cc
+ *
+*/
+#include <iostream>
+
+#include "zypp/base/Easy.h"
+#include "zypp/base/LogTools.h"
+#include "zypp/base/Gettext.h"
+#include "zypp/base/Exception.h"
+#include "zypp/base/String.h"
+
+#include "zypp/ResObject.h"
+#include "zypp/Capability.h"
+#include "zypp/capability/VersionedCap.h"
+
+#include "zypp/sat/detail/PoolImpl.h"
+#include "zypp/sat/Solvable.h"
+#include "zypp/sat/Repo.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace pool
+  { /////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
+    namespace
+    { /////////////////////////////////////////////////////////////////
+
+      inline void store( ::Id & where_r, const::std::string & str_r )
+      {
+        where_r = sat::IdStr( str_r ).id();
+      }
+
+      inline void store( ::Offset & where_r, ::_Solvable * slv_r, const Dependencies & dep_r, Dep which_r )
+      {
+        const CapSet & caps( dep_r[which_r] );
+        if ( caps.empty() )
+          return;
+
+        for_( it, caps.begin(), caps.end() )
+        {
+          // check PREREQUIRES later
+          int isreq = ( which_r == Dep::REQUIRES ? 1 : 0 );
+
+          std::string name;
+          Rel         op;
+          Edition     ed;
+
+          using capability::VersionedCap;
+          VersionedCap::constPtr vercap = capability::asKind<VersionedCap>(*it);
+          if ( vercap )
+          {
+            name = vercap->name();
+            op = vercap->op();
+            ed = vercap->edition();
+          }
+          else
+          {
+            name = (*it).asString();
+          }
+
+          sat::IdStr nid;
+          if ( refersTo<Package>( *it ) )
+          {
+            nid = sat::IdStr( name );
+          }
+          else
+          {
+            nid = sat::IdStr( str::form( "%s:%s",
+                                         (*it).refers().asString().c_str(),
+                                         name.c_str() ) );
+          }
+
+          if ( op != Rel::ANY && ed != Edition::noedition )
+          {
+            sat::IdStr eid( ed.asString() );
+#warning TBD calc rel and prereqcheck
+            ::Id rid = ::rel2id( slv_r->repo->pool, nid.id(), eid.id(), REL_EQ, true );
+            where_r = ::repo_addid_dep( slv_r->repo, where_r, rid, isreq );
+          }
+          else
+          {
+            where_r = ::repo_addid_dep( slv_r->repo, where_r, nid.id(), isreq );
+          }
+        }
+      }
+
+      /////////////////////////////////////////////////////////////////
+    } // namespace
+    ///////////////////////////////////////////////////////////////////
+
+
+    void res2sat( const ResObject::constPtr & res_r, sat::Solvable & slv_r )
+    {
+      ::_Solvable * slv( slv_r.get() );
+      if ( ! ( res_r && slv ) )
+      {
+        INT << res_r << " -> " << slv_r << endl;
+        ZYPP_THROW( Exception( _("Can't store data in NULL objlect") ) );
+      }
+
+      if ( isKind<Package>( res_r ) )
+      {
+        store( slv->name, res_r->name() );
+      }
+      else
+      {
+        store( slv->name, str::form( "%s:%s",
+                                     res_r->kind().asString().c_str(),
+                                     res_r->name().c_str() ) );
+      }
+      store( slv->arch,   res_r->arch().asString() );
+      store( slv->evr,    res_r->edition().asString() );
+      store( slv->vendor, res_r->vendor() );
+
+      store( slv->provides,    slv, res_r->deps(), Dep::PROVIDES );
+      store( slv->obsoletes,   slv, res_r->deps(), Dep::OBSOLETES );
+      store( slv->conflicts,   slv, res_r->deps(), Dep::CONFLICTS );
+      store( slv->requires,    slv, res_r->deps(), Dep::REQUIRES );
+      store( slv->recommends,  slv, res_r->deps(), Dep::RECOMMENDS );
+      store( slv->suggests,    slv, res_r->deps(), Dep::SUGGESTS );
+      store( slv->supplements, slv, res_r->deps(), Dep::SUPPLEMENTS );
+      store( slv->enhances,    slv, res_r->deps(), Dep::ENHANCES );
+      store( slv->freshens,    slv, res_r->deps(), Dep::FRESHENS );
+
+      //DBG << "  " << res_r << " -> " << slv_r << endl;
+    }
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace pool
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
index 7e6640f..d880f41 100644 (file)
@@ -24,10 +24,19 @@ namespace zypp
   namespace sat
   { /////////////////////////////////////////////////////////////////
 
-    static const IdStr::IdStr Null( STRID_NULL );
+    const IdStr IdStr::Null( unsigned(STRID_NULL) );
+    const IdStr IdStr::Empty( unsigned(STRID_EMPTY) );
 
     /////////////////////////////////////////////////////////////////
 
+    IdStr::IdStr( const char * str_r )
+      : _id( ::stringpool_str2id( &myPool()->ss, str_r, true ) )
+    {}
+
+    IdStr::IdStr( const std::string & str_r )
+      : _id( ::stringpool_str2id( &myPool()->ss, str_r.c_str(), true ) )
+    {}
+
     const char * IdStr::c_str() const
     {
       return ::id2str( myPool().getPool(), _id );
index b93bfad..0ff7768 100644 (file)
@@ -28,25 +28,47 @@ namespace zypp
     //
     // CLASS NAME : IdStr
     //
-    /** */
+    /** Access to the sat-pools string space.
+     * Construction from string will place a copy of the string in the
+     * string space, if it is not already present.
+    */
     class IdStr: protected detail::PoolMember
     {
       friend std::ostream & operator<<( std::ostream & str, const IdStr & obj );
 
       public:
-        IdStr() : _id( 0 ) {}
-        explicit IdStr( int id_r ) : _id( id_r ) {}
+        /** Default ctor, empty string. */
+        IdStr() : _id( Empty.id() ) {}
+        /** Ctor from id. */
+        explicit IdStr( unsigned id_r ) : _id( id_r ) {}
+        /** Ctor from string. */
         explicit IdStr( const char * str_r );
+        /** Ctor from string. */
         explicit IdStr( const std::string & str_r );
       public:
+        /** No or Null string. */
         static const IdStr Null;
+        /** Empty string. */
+        static const IdStr::IdStr Empty;
       public:
+        bool empty() const
+        { return( _id == Empty.id() ); }
+
+      public:
+        /** Conversion to <tt>const char *</tt> */
         const char * c_str() const;
+        /** Conversion to <tt>std::string</tt> */
         std::string string() const;
+        /** \overload */
+        std::string asString() const
+        { return string(); }
+
       public:
-        int get() const { return _id; }
+        /** Expert backdoor. */
+        unsigned id() const
+        { return _id; }
       private:
-        int _id;
+        unsigned _id;
     };
     ///////////////////////////////////////////////////////////////////
 
@@ -55,11 +77,11 @@ namespace zypp
 
     /** \relates IdStr */
     inline bool operator==( const IdStr & lhs, const IdStr & rhs )
-    { return lhs.get() == rhs.get(); }
+    { return lhs.id() == rhs.id(); }
 
     /** \relates IdStr */
     inline bool operator!=( const IdStr & lhs, const IdStr & rhs )
-    { return lhs.get() != rhs.get(); }
+    { return lhs.id() != rhs.id(); }
 
 
     /////////////////////////////////////////////////////////////////
index 1e9fcae..ad73815 100644 (file)
@@ -21,6 +21,7 @@ namespace zypp
 { /////////////////////////////////////////////////////////////////
 
   class Pathname;
+  class SerialNumber;
 
   ///////////////////////////////////////////////////////////////////
   namespace sat
index 7d11950..70d91fc 100644 (file)
@@ -94,13 +94,13 @@ namespace zypp
 
     void Repo::addSolv( const Pathname & file_r )
     {
-      NO_REPO_THROW( Exception( "Can't add solvables to noepo." ) );
+      NO_REPO_THROW( Exception( _("Can't add solvables to noepo.") ) );
 
       AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "r" ), ::fclose );
       if ( file == NULL )
       {
         file.resetDispose();
-        ZYPP_THROW( Exception( "Can't read solv-file "+file_r.asString() ) );
+        ZYPP_THROW( Exception( _("Can't read solv-file: ")+file_r.asString() ) );
       }
 
       myPool().setDirty();
@@ -109,14 +109,14 @@ namespace zypp
 
     detail::SolvableIdType Repo::addSolvable()
     {
-      NO_REPO_THROW( Exception( "Can't add solvables to noepo." ) );
+      NO_REPO_THROW( Exception( _("Can't add solvables to noepo.") ) );
       myPool().setDirty();
       return ::repo_add_solvable( _repo );
     }
 
     detail::SolvableIdType Repo::addSolvables( unsigned count_r )
     {
-      NO_REPO_THROW( Exception( "Can't add solvables to noepo." ) );
+      NO_REPO_THROW( Exception( _("Can't add solvables to noepo.") ) );
       myPool().setDirty();
       return ::repo_add_solvable_block( _repo, count_r );
     }
index 8cdacce..d874d66 100644 (file)
@@ -36,13 +36,27 @@ namespace zypp
     ::_Solvable * Solvable::get() const
     { return myPool().getSolvable( _id ); }
 
-    Solvable Solvable::nextInPool() const
-    { return Solvable( myPool().getNextId( _id ) ); }
-
 #define NO_SOLVABLE_RETURN( VAL ) \
     ::_Solvable * _solvable( get() ); \
     if ( ! _solvable ) return VAL
 
+    Solvable Solvable::nextInPool() const
+    { return Solvable( myPool().getNextId( _id ) ); }
+
+    Solvable Solvable::nextInRepo() const
+    {
+      NO_SOLVABLE_RETURN( nosolvable );
+      for ( detail::SolvableIdType next = _id+1; next < unsigned(_solvable->repo->end); ++next )
+      {
+        ::_Solvable * nextS( myPool().getSolvable( next ) );
+        if ( nextS &&  nextS->repo == _solvable->repo )
+        {
+          return Solvable( next );
+        }
+      }
+      return nosolvable;
+    }
+
     NameId Solvable::name() const
     {
       NO_SOLVABLE_RETURN( NameId() );
index 409b61c..32ae92e 100644 (file)
@@ -17,6 +17,7 @@
 #include "zypp/base/SafeBool.h"
 
 #include "zypp/sat/detail/PoolMember.h"
+#include "zypp/sat/IdStr.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp