diff options
author | Per Øyvind Karlsen <peroyvind@mandriva.org> | 2009-08-05 21:58:02 +0000 |
---|---|---|
committer | Per Øyvind Karlsen <peroyvind@mandriva.org> | 2009-08-05 21:58:02 +0000 |
commit | ac43bb6ac84a1fa2cf1c8faf478838ac9497fab5 (patch) | |
tree | 6c728ff6515304358c3072bfe0988bcc27b15557 | |
parent | fd1f166c0530e862020939c3ee8a878eec7f653d (diff) | |
download | perl-URPM-ac43bb6ac84a1fa2cf1c8faf478838ac9497fab5.tar perl-URPM-ac43bb6ac84a1fa2cf1c8faf478838ac9497fab5.tar.gz perl-URPM-ac43bb6ac84a1fa2cf1c8faf478838ac9497fab5.tar.bz2 perl-URPM-ac43bb6ac84a1fa2cf1c8faf478838ac9497fab5.tar.xz perl-URPM-ac43bb6ac84a1fa2cf1c8faf478838ac9497fab5.zip |
* get version to compare from %provideversion with get_evr() rather than
manually extracting it from package name
* just pass whole evr directly to rpmvercmp() rather than one by one element,
makes things a lot cleaner and less confusing while also automatically adding
support for distepoch comparision as well
-rw-r--r-- | URPM.xs | 176 |
1 files changed, 62 insertions, 114 deletions
@@ -172,6 +172,26 @@ get_int(Header header, int32_t tag) { return ep ? *ep : 0; } +/* This function might modify strings that needs to be reverted after use + * with restore_chars() + */ +static char * +get_evr(URPM__Package pkg) { + char *evr = NULL; + if(pkg->provides) { + evr = strrchr(pkg->provides, ' ')+1; + char *tmp = strrchr(evr, ']'); + if(tmp) + backup_char(tmp); + } else if(pkg->h) { + evr = get_name(pkg->h, RPMTAG_PROVIDEVERSION); + } + return evr; +} + +/* This function might modify strings that needs to be reverted after use + * with restore_chars() + */ static int get_fullname_parts(URPM__Package pkg, char **name, char **version, char **release, char **disttag, char **distepoch, char **arch, char **eos) { char *_version = NULL, *_release = NULL, *_disttag = NULL, *_distepoch, *_arch = NULL, *_eos = NULL, *tmp = NULL; @@ -1853,77 +1873,43 @@ Pkg_compare_pkg(lpkg, rpkg) URPM::Package rpkg PREINIT: int compare = 0; - int lepoch; - char *lversion; - char *lrelease; + char *levr; char *larch; - char *leos; - int repoch; - char *rversion; - char *rrelease; + char *revr; char *rarch; - char *reos; CODE: if (lpkg == rpkg) RETVAL = 0; else { - get_fullname_parts(lpkg, NULL, &lversion, &lrelease, &larch, NULL, NULL, &leos); - if (lpkg->info) { - char *s; - - if ((s = strchr(leos, '@')) != NULL) { - backup_char(s); - lepoch = atoi(leos); - } else { - lepoch = 0; - } - } else if (lpkg->h) { - lepoch = get_int(lpkg->h, RPMTAG_EPOCH); - } else croak("undefined package"); - - get_fullname_parts(rpkg, NULL, &rversion, &rrelease, NULL, NULL, &rarch, &reos); - if (rpkg->info) { - char *s; - - if ((s = strchr(reos, '@')) != NULL) { - backup_char(s); - repoch = atoi(reos); - } else { - repoch = 0; - } - } else if (rpkg->h) { - repoch = get_int(rpkg->h, RPMTAG_EPOCH); - } else { + levr = get_evr(lpkg); + revr = get_evr(rpkg); + if(levr == NULL || revr == NULL) { restore_chars(); croak("undefined package"); } - compare = lepoch - repoch; + + compare = rpmvercmp(levr, revr); if (!compare) { - compare = rpmvercmp(lversion, rversion); - if (!compare) { - compare = rpmvercmp(lrelease, rrelease); - if (!compare) { - int lscore, rscore; - - read_config_files(0); - lscore = rpmMachineScore(RPM_MACHTABLE_INSTARCH, larch); - rscore = rpmMachineScore(RPM_MACHTABLE_INSTARCH, rarch); - if (lscore == 0) { - if (rscore == 0) + int lscore, rscore; + get_fullname_parts(lpkg, NULL, NULL, NULL, NULL, NULL, &larch, NULL); + get_fullname_parts(rpkg, NULL, NULL, NULL, NULL, NULL, &rarch, NULL); + read_config_files(0); + lscore = rpmMachineScore(RPM_MACHTABLE_INSTARCH, larch); + rscore = rpmMachineScore(RPM_MACHTABLE_INSTARCH, rarch); + if (lscore == 0) { + if (rscore == 0) #if 0 - /* Nanar: TODO check this - * hu ?? what is the goal of strcmp, some of arch are equivalent */ - compare = 0 + /* Nanar: TODO check this + * hu ?? what is the goal of strcmp, some of arch are equivalent */ + compare = 0 #endif - compare = strcmp(larch, rarch); - else - compare = -1; - } else { - if (rscore == 0) - compare = 1; - else - compare = rscore - lscore; /* score are lower for better */ - } - } + compare = strcmp(larch, rarch); + else + compare = -1; + } else { + if (rscore == 0) + compare = 1; + else + compare = rscore - lscore; /* score are lower for better */ } } /* restore info string modified */ @@ -1939,63 +1925,25 @@ Pkg_compare(pkg, evr) char *evr PREINIT: int compare = 0; - int _epoch; - char *_version; - char *_release; - char *_arch; - char *_eos; + char *_evr; CODE: - get_fullname_parts(pkg, NULL, &_version, &_release, NULL, NULL, &_arch, &_eos); - if (pkg->info) { - char *s; - - if ((s = strchr(_eos, '@')) != NULL) { - backup_char(s); - _epoch = atoi(_eos); - } else { - _epoch = 0; - } - } else if (pkg->h) { - _epoch = get_int(pkg->h, RPMTAG_EPOCH); - } else croak("undefined package"); if (!compare) { - char *epoch, *version, *release; - - /* extract epoch and version from evr */ - version = evr; - while (*version && isdigit(*version)) version++; - if (*version == ':') { - epoch = evr; - *version++ = 0; - if (!*epoch) epoch = "0"; - compare = _epoch - (*epoch ? atoi(epoch) : 0); - version[-1] = ':'; /* restore in memory modification */ - } else { - /* there is no epoch defined, so assume epoch = 0 */ - version = evr; - compare = _epoch; - } - if (!compare) { - if (!pkg->info) - _version = get_name(pkg->h, RPMTAG_VERSION); - /* continue extracting release if any */ - if ((release = strrchr(version, '-')) != NULL) { - *release++ = 0; - compare = rpmvercmp(_version, version); - if (!compare) { - /* need to compare with release here */ - if (!pkg->info) - _release = get_name(pkg->h, RPMTAG_RELEASE); - compare = rpmvercmp(_release, release); - } - release[-1] = '-'; /* restore in memory modification */ - } else { - compare = rpmvercmp(_version, version); - } - } + const char *seps; + char *tmp; + + _evr = get_evr(pkg); + /* This will remove fields from _evr (from the right) that evr is missing + * so that ie. if only version is given as an argument, it won't compare + * release etc. + */ + for(seps = ":-:"; *seps != 0; seps++) + if((tmp = strrchr(_evr, *seps)) != NULL && strrchr(evr, *seps) == NULL) + backup_char(tmp); + + compare = rpmvercmp(_evr, evr); + /* restore provides string modified */ + restore_chars(); } - /* restore info string modified */ - restore_chars(); RETVAL = compare; OUTPUT: RETVAL |