This is a refactoring for _alpm_sync_sysupgrade, but I didn't really cut down on the total code length. I just thought the triple nested for loops deserved their own function (and maybe this will lead to inspiration to cleaning up this code). The patch looks kind of weird but a vimdiff makes a lot more sense of it. -Dan $ cvs diff lib/libalpm/sync.c Index: lib/libalpm/sync.c =================================================================== RCS file: /home/cvs-pacman/pacman-lib/lib/libalpm/sync.c,v retrieving revision 1.86 diff -u -r1.86 sync.c --- lib/libalpm/sync.c 22 Dec 2006 19:38:55 -0000 1.86 +++ lib/libalpm/sync.c 28 Dec 2006 19:09:27 -0000 @@ -118,12 +118,14 @@ return((pkg->date + handle->upgradedelay) > t); } -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync) +/* Find recommended replacements for packages during a sync. + * (refactored from _alpm_sync_prepare) + */ +static int find_replacements(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync) { pmlist_t *i, *j, *k; - /* check for "recommended" package replacements */ - _alpm_log(PM_LOG_FLOW1, _("checking for package replacements")); + /* TODO can these nested loops be commented better? */ for(i = dbs_sync; i; i = i->next) { for(j = _alpm_db_get_pkgcache(i->data, INFRQ_DESC); j; j = j->next) { pmpkg_t *spkg = j->data; @@ -179,6 +181,23 @@ } } + return(0); + +error: + return(-1); +} + +int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync) +{ + pmlist_t *i, *j; + + /* check for "recommended" package replacements */ + _alpm_log(PM_LOG_FLOW1, _("checking for package replacements")); + if( find_replacements(trans, db_local, dbs_sync) != 0 ) { + /* pm_errno is set by find_replacement */ + goto error; + } + /* match installed packages with the sync dbs and compare versions */ _alpm_log(PM_LOG_FLOW1, _("checking for package upgrades")); for(i = _alpm_db_get_pkgcache(db_local, INFRQ_NONE); i; i = i->next) { @@ -382,7 +401,7 @@ { pmlist_t *deps = NULL; pmlist_t *list = NULL; /* list allowing checkdeps usage with data from trans->packages */ - pmlist_t *trail = NULL; /* breadcrumb list to avoid running into circles */ + pmlist_t *trail = NULL; /* breadcrumb list to avoid running in circles */ pmlist_t *asked = NULL; pmlist_t *i, *j, *k, *l; int ret = 0;