aboutsummaryrefslogtreecommitdiffstats
path: root/URPM.xs
diff options
context:
space:
mode:
Diffstat (limited to 'URPM.xs')
-rw-r--r--URPM.xs52
1 files changed, 23 insertions, 29 deletions
diff --git a/URPM.xs b/URPM.xs
index d1c137e..da53874 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -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