summaryrefslogtreecommitdiff
path: root/lib/rpmds.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-09-11 07:23:50 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-09-11 08:08:54 +0300
commitd2f51ded49d438f3c6c6026ff4202196c94f2651 (patch)
tree2a075ef1c40681c48505bd02a0f1111511ae5eaf /lib/rpmds.c
parent03b6fcb1a19f82708ed5453d474584e7aa5782be (diff)
downloadlibrpm-tizen-d2f51ded49d438f3c6c6026ff4202196c94f2651.tar.gz
librpm-tizen-d2f51ded49d438f3c6c6026ff4202196c94f2651.tar.bz2
librpm-tizen-d2f51ded49d438f3c6c6026ff4202196c94f2651.zip
Split rpmds EVR comparison into function of its own
- The EVR comparison is a distinct operation of its own: rpmdsCompare() looks at the other properties, EVR comparison is done if needed. Doesn't affect speed or functionality, but cuts down on the big number of local variables and has the nice side-effect of making the xstrdup() allocations local within rpmdsCompareEVR()
Diffstat (limited to 'lib/rpmds.c')
-rw-r--r--lib/rpmds.c92
1 files changed, 50 insertions, 42 deletions
diff --git a/lib/rpmds.c b/lib/rpmds.c
index 51d3f4b9d..d9a039c78 100644
--- a/lib/rpmds.c
+++ b/lib/rpmds.c
@@ -695,55 +695,24 @@ void parseEVR(char * evr,
if (rp) *rp = release;
}
-int rpmdsCompare(const rpmds A, const rpmds B)
+static inline int rpmdsCompareEVR(const char *AEVR, uint32_t AFlags,
+ const char *BEVR, uint32_t BFlags,
+ int nopromote)
{
- char *aEVR, *bEVR;
const char *aE, *aV, *aR, *bE, *bV, *bR;
- const char *AEVR, *BEVR;
- rpmsenseFlags AFlags, BFlags;
- int result;
- int sense;
-
- /* Different names don't overlap. */
- if (!rstreq(rpmdsN(A), rpmdsN(B))) {
- result = 0;
- goto exit;
- }
-
- /* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */
- if (!(A->EVR && A->Flags && B->EVR && B->Flags)) {
- result = 1;
- goto exit;
- }
-
- /* Same name. If either A or B is an existence test, always overlap. */
- AFlags = rpmdsFlags(A);
- BFlags = rpmdsFlags(B);
- if (!((AFlags & RPMSENSE_SENSEMASK) && (BFlags & RPMSENSE_SENSEMASK))) {
- result = 1;
- goto exit;
- }
-
- /* If either EVR is non-existent or empty, always overlap. */
- AEVR = rpmdsEVR(A);
- BEVR = rpmdsEVR(B);
- if (!(AEVR && *AEVR && BEVR && *BEVR)) {
- result = 1;
- goto exit;
- }
+ char *aEVR = xstrdup(AEVR);
+ char *bEVR = xstrdup(BEVR);
+ int sense = 0;
+ int result = 0;
- /* Both AEVR and BEVR exist. */
- aEVR = xstrdup(AEVR);
parseEVR(aEVR, &aE, &aV, &aR);
- bEVR = xstrdup(BEVR);
parseEVR(bEVR, &bE, &bV, &bR);
/* Compare {A,B} [epoch:]version[-release] */
- sense = 0;
if (aE && *aE && bE && *bE)
sense = rpmvercmp(aE, bE);
else if (aE && *aE && atol(aE) > 0) {
- if (!B->nopromote) {
+ if (!nopromote) {
sense = 0;
} else
sense = 1;
@@ -767,11 +736,8 @@ int rpmdsCompare(const rpmds A, const rpmds B)
}
}
}
- aEVR = _free(aEVR);
- bEVR = _free(bEVR);
/* Detect overlap of {A,B} range. */
- result = 0;
if (sense < 0 && ((AFlags & RPMSENSE_GREATER) || (BFlags & RPMSENSE_LESS))) {
result = 1;
} else if (sense > 0 && ((AFlags & RPMSENSE_LESS) || (BFlags & RPMSENSE_GREATER))) {
@@ -784,6 +750,48 @@ int rpmdsCompare(const rpmds A, const rpmds B)
}
exit:
+ free(aEVR);
+ free(bEVR);
+ return result;
+}
+
+int rpmdsCompare(const rpmds A, const rpmds B)
+{
+ const char *AEVR, *BEVR;
+ rpmsenseFlags AFlags, BFlags;
+ int result;
+
+ /* Different names don't overlap. */
+ if (!rstreq(rpmdsN(A), rpmdsN(B))) {
+ result = 0;
+ goto exit;
+ }
+
+ /* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */
+ if (!(A->EVR && A->Flags && B->EVR && B->Flags)) {
+ result = 1;
+ goto exit;
+ }
+
+ /* Same name. If either A or B is an existence test, always overlap. */
+ AFlags = rpmdsFlags(A);
+ BFlags = rpmdsFlags(B);
+ if (!((AFlags & RPMSENSE_SENSEMASK) && (BFlags & RPMSENSE_SENSEMASK))) {
+ result = 1;
+ goto exit;
+ }
+
+ AEVR = rpmdsEVR(A);
+ BEVR = rpmdsEVR(B);
+ if (!(AEVR && *AEVR && BEVR && *BEVR)) {
+ /* If either EVR is non-existent or empty, always overlap. */
+ result = 1;
+ } else {
+ /* Both AEVR and BEVR exist, compare [epoch:]version[-release]. */
+ result = rpmdsCompareEVR(AEVR, AFlags, BEVR, BFlags, B->nopromote);
+ }
+
+exit:
return result;
}