Author: kkaempf Date: Tue Feb 19 15:53:17 2008 New Revision: 8812 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8812&view=rev Log: fix (resp. enhance) solver result iterators - each_to_install, each_to_remove: add flags to distinguish between 'new' installs and 'update' installs, same for removals - each_to_update: iterate over updates, pass old and new solvable back through callback Modified: trunk/sat-solver/applayer/xsolvable.c trunk/sat-solver/applayer/xsolvable.h trunk/sat-solver/bindings/satsolver.i Modified: trunk/sat-solver/applayer/xsolvable.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/xsolvable.c?rev=8812&r1=8811&r2=8812&view=diff ============================================================================== --- trunk/sat-solver/applayer/xsolvable.c (original) +++ trunk/sat-solver/applayer/xsolvable.c Tue Feb 19 15:53:17 2008 @@ -130,16 +130,25 @@ } +/* + * Iterate over all installs + */ + void -solver_installs_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) ) +solver_installs_iterate( Solver *solver, int all, int (*callback)( const XSolvable *xs ) ) { Id p; Solvable *s; int i; + Id *obsoletesmap; + Repo *installed = solver->installed; /* repo of installed solvables */ if (!callback) return; + if (!all) + obsoletesmap = create_decisions_obsoletesmap( solver ); + for ( i = 0; i < solver->decisionq.count; i++) { p = solver->decisionq.elements[i]; @@ -151,37 +160,88 @@ // getting repo s = solver->pool->solvables + p; Repo *repo = s->repo; - if (!repo || repo == solver->installed) + if (!repo || repo == installed) continue; /* already installed resolvable */ - - if (callback( xsolvable_new( solver->pool, p ) ) ) - break; + + if (!obsoletesmap || !obsoletesmap[p]) + if (callback( xsolvable_new( solver->pool, p ) ) ) + break; } + if (obsoletesmap) + sat_free( obsoletesmap ); } +/* + * Iterate over all removals + */ + void -solver_removals_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) ) +solver_removals_iterate( Solver *solver, int all, int (*callback)( const XSolvable *xs ) ) { Id p; Solvable *s; + Id *obsoletesmap = NULL; + Repo *installed = solver->installed; /* repo of installed solvables */ if (!callback) return; - if (!solver->installed) + if (!installed) return; + if (!all) + obsoletesmap = create_decisions_obsoletesmap( solver ); + /* solvables to be removed */ - FOR_REPO_SOLVABLES(solver->installed, p, s) + FOR_REPO_SOLVABLES(installed, p, s) { if (solver->decisionmap[p] >= 0) continue; /* we keep this package */ + if (obsoletesmap && obsoletesmap[p]) + continue; /* its being obsoleted (updated) */ if (callback( xsolvable_new( solver->pool, p ) ) ) break; } + if (obsoletesmap) + sat_free( obsoletesmap ); +} + + +/* + * Iterate over all updates + */ + +void +solver_updates_iterate( Solver *solver, int (*callback)( const XSolvable *xs_old, const XSolvable *xs_new ) ) +{ + Id p; + Solvable *s; + Id *obsoletesmap = NULL; + Repo *installed = solver->installed; /* repo of installed solvables */ + + if (!callback) + return; + + + if (!installed) + return; + + obsoletesmap = create_decisions_obsoletesmap( solver ); + + /* solvables to be removed */ + FOR_REPO_SOLVABLES(installed, p, s) + { + if (solver->decisionmap[p] >= 0) + continue; /* we keep this package */ + if (obsoletesmap[p]) + if (callback( xsolvable_new( solver->pool, p ), xsolvable_new( solver->pool, obsoletesmap[p] ) ) ) + break; + } + sat_free( obsoletesmap ); } + void solver_suggestions_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) ) { Modified: trunk/sat-solver/applayer/xsolvable.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/xsolvable.h?rev=8812&r1=8811&r2=8812&view=diff ============================================================================== --- trunk/sat-solver/applayer/xsolvable.h (original) +++ trunk/sat-solver/applayer/xsolvable.h Tue Feb 19 15:53:17 2008 @@ -33,18 +33,66 @@ unsigned int kind; /* one of KIND_xxx */ } XSolvable; +/* + * Create a new XSolvable in pool from Solvable id + */ XSolvable *xsolvable_new( Pool *pool, Id id ); + +/* + * Create a new XSolvable in pool from name, evr, arch + */ XSolvable *xsolvable_create( Repo *repo, const char *name, const char *evr, const char *arch ); + +/* + * Free a previously created XSolvable + */ void xsolvable_free( XSolvable *xs ); + +/* + * Return the Solvable corresponding to the given XSolvable + */ Solvable *xsolvable_solvable( const XSolvable *xs ); + +/* + * Find XSolvable by name in pool (and repo) + * If repo == NULL, search the complete pool + * If repo != NULL, limit search to the given repo + */ XSolvable *xsolvable_find( Pool *pool, char *name, const Repo *repo ); + +/* + * Get XSolvable by index in pool (and repo) + * If repo == NULL, count index from beginning of pool + * If repo != NULL, count index from the given repo + */ XSolvable *xsolvable_get( Pool *pool, int i, const Repo *repo ); -void solver_installs_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) ); -void solver_removals_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) ); +/* iterate over all (newly-)to-be-installed solvables + * if all = 0, only report *newly* installed ones (non-updates) + * if all = 1, report all to-be-installed ones + */ +void solver_installs_iterate( Solver *solver, int all, int (*callback)( const XSolvable *xs ) ); + +/* iterate over all to-be-removed solvables + * if all = 0, only report *dropped* ones (non-updates) + * if all = 1, report all to-be-removed ones + */ +void solver_removals_iterate( Solver *solver, int all, int (*callback)( const XSolvable *xs ) ); + +/* + * Iterate over all solvables which update installed ones + */ +void solver_updates_iterate( Solver *solver, int (*callback)( const XSolvable *xs_old, const XSolvable *xs_new ) ); + +/* + * Iterate over all solvables being suggested in the last solver run + */ void solver_suggestions_iterate( Solver *solver, int (*callback)( const XSolvable *xs ) ); +/* + * Iterate over all solvables of the given repo + */ void repo_xsolvables_iterate( Repo *repo, int (*callback)( const XSolvable *xs ) ); #endif /* SATSOLVER_XSOLVABLE_H */ Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8812&r1=8811&r2=8812&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Tue Feb 19 15:53:17 2008 @@ -106,7 +106,17 @@ { #if defined(SWIGRUBY) /* FIXME: how to pass 'break' back to the caller ? */ - rb_yield(SWIG_NewPointerObj((void*)xs, SWIGTYPE_p__Solvable, 0)); + rb_yield( SWIG_NewPointerObj((void*)xs, SWIGTYPE_p__Solvable, 0) ); +#endif + return 0; +} + +static int +update_xsolvables_iterate_callback( const XSolvable *xs_old, const XSolvable *xs_new ) +{ +#if defined(SWIGRUBY) + /* FIXME: how to pass 'break' back to the caller ? */ + rb_yield_values( 2, SWIG_NewPointerObj((void*)xs_old, SWIGTYPE_p__Solvable, 0), SWIG_NewPointerObj((void*)xs_new, SWIGTYPE_p__Solvable, 0) ); #endif return 0; } @@ -1438,11 +1448,27 @@ void each_problem( Transaction *t ) { return solver_problems_iterate( $self, t, solver_problems_iterate_callback ); } - void each_to_install() - { return solver_installs_iterate( $self, generic_xsolvables_iterate_callback ); } + /* + * iterate over all to-be-*newly*-installed solvables + * those brought in for update reasons are normally *not* reported. + * + * if true (resp '1') is passed, iterate over *all* to-be-installed + * solvables + */ + void each_to_install(int bflag = 0) + { return solver_installs_iterate( $self, bflag, generic_xsolvables_iterate_callback ); } + + void each_to_update() + { return solver_updates_iterate( $self, update_xsolvables_iterate_callback ); } - void each_to_remove() - { return solver_removals_iterate( $self, generic_xsolvables_iterate_callback ); } + /* + * iterate over all to-be-removed-without-replacement solvables + * those replaced by an updated are normally *not* reported. + * + * if true (resp '1') is passed, iterate over *all* to-be-removed solvables + */ + void each_to_remove(int bflag = 0) + { return solver_removals_iterate( $self, bflag, generic_xsolvables_iterate_callback ); } void each_suggested() { return solver_suggestions_iterate( $self, generic_xsolvables_iterate_callback); } -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org