diff options
author | Thierry Vignaud <tv@mageia.org> | 2012-06-22 16:02:50 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2012-06-22 16:02:50 +0000 |
commit | ebc816b062408510a7b36dab7e7a6c2851c40989 (patch) | |
tree | 8b61d775a84d788f6ae23c54088fdda3c491add0 /URPM.xs | |
parent | 2fb1e91ceeb25ee136cb10369fabac15096283d2 (diff) | |
download | perl-URPM-ebc816b062408510a7b36dab7e7a6c2851c40989.tar perl-URPM-ebc816b062408510a7b36dab7e7a6c2851c40989.tar.gz perl-URPM-ebc816b062408510a7b36dab7e7a6c2851c40989.tar.bz2 perl-URPM-ebc816b062408510a7b36dab7e7a6c2851c40989.tar.xz perl-URPM-ebc816b062408510a7b36dab7e7a6c2851c40989.zip |
(compare_evrs) factorize comparing EVRs
Diffstat (limited to 'URPM.xs')
-rw-r--r-- | URPM.xs | 52 |
1 files changed, 23 insertions, 29 deletions
@@ -1348,6 +1348,17 @@ static void push_rflags(URPM__Package pkg, int gimme) { } } +static int compare_evrs(int lepoch, char*lversion, char*lrelease, int repoch, char*rversion, char*rrelease) { + int compare; + compare = lepoch - repoch; + if (!compare) { + compare = rpmvercmp(lversion, rversion); + if (!compare && rrelease) + compare = rpmvercmp(lrelease, rrelease); + } + return compare; +} + MODULE = URPM PACKAGE = URPM::Package PREFIX = Pkg_ void @@ -1636,11 +1647,8 @@ Pkg_compare_pkg(lpkg, rpkg) } croak("undefined package"); } - compare = lepoch - repoch; - if (!compare) { - compare = rpmvercmp(lversion, rversion); - if (!compare) { - compare = rpmvercmp(lrelease, rrelease); + compare = compare_evrs(lepoch, lversion, lrelease, repoch, rversion, rrelease); + // equal? compare arches too if (!compare) { int lscore, rscore; char *eolarch = strchr(larch, '@'); @@ -1665,8 +1673,6 @@ Pkg_compare_pkg(lpkg, rpkg) if (eolarch) *eolarch = '@'; if (eorarch) *eorarch = '@'; } - } - } /* restore info string modified */ if (lpkg->info) { lrelease[-1] = '-'; @@ -1686,8 +1692,7 @@ Pkg_compare(pkg, evr) URPM::Package pkg char *evr PREINIT: - int compare = 0; - int _epoch; + int _epoch, repoch = 0; char *_version; char *_release; char *_eos; @@ -1707,11 +1712,13 @@ Pkg_compare(pkg, evr) /* temporarily mark end of each substring */ _release[-1] = 0; _eos[-1] = 0; - } else if (pkg->h) + } else if (pkg->h) { _epoch = get_int(pkg->h, RPMTAG_EPOCH); - else croak("undefined package"); + _version = get_name(pkg->h, RPMTAG_VERSION); + _release = get_name(pkg->h, RPMTAG_RELEASE); + } else croak("undefined package"); - char *epoch, *version, *release; + char *epoch = NULL, *version, *release; /* extract epoch and version from evr */ version = evr; @@ -1720,38 +1727,25 @@ Pkg_compare(pkg, evr) 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); - } } + repoch = epoch && *epoch ? atoi(epoch) : 0; + RETVAL = compare_evrs(_epoch, _version, _release, repoch, version, release); /* restore info string modified */ if (pkg->info) { _release[-1] = '-'; _eos[-1] = '.'; } - RETVAL = compare; + if (release) + release[-1] = '-'; /* restore in memory modification */ OUTPUT: RETVAL |