From e67e1dbad30dadf14effc3ae6e83c73504d23f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Wed, 13 Oct 2010 19:40:19 +0000 Subject: use rpmEVRoverlap() in ranges_overlap() --- URPM.xs | 69 +++++++++++++---------------------------------------------------- 1 file changed, 13 insertions(+), 56 deletions(-) diff --git a/URPM.xs b/URPM.xs index ea6631f..5ba8da3 100644 --- a/URPM.xs +++ b/URPM.xs @@ -347,64 +347,21 @@ ranges_overlap(uint32_t aflags, char *sa, uint32_t bflags, char *sb) { if (!aflags || !bflags) return 1; /* really faster to test it there instead of later */ else { - int sense = 0; char *eosa = strchr(sa, ']'); char *eosb = strchr(sb, ']'); - char *ea, *va, *ra, *eb, *vb, *rb; - - if (eosa) *eosa = 0; - if (eosb) *eosb = 0; - /* parse sa as an [epoch:]version[-release] */ - for (ea = sa; *sa >= '0' && *sa <= '9'; ++sa); - if (*sa == ':') { - *sa++ = 0; /* ea could be an empty string (should be interpreted as 0) */ - va = sa; - } else { - va = ea; /* no epoch */ - ea = NULL; - } - if ((ra = strrchr(sa, '-'))) *ra++ = 0; - /* parse sb as an [epoch:]version[-release] */ - for (eb = sb; *sb >= '0' && *sb <= '9'; ++sb); - if (*sb == ':') { - *sb++ = 0; /* ea could be an empty string (should be interpreted as 0) */ - vb = sb; - } else { - vb = eb; /* no epoch */ - eb = NULL; - } - if ((rb = strrchr(sb, '-'))) *rb++ = 0; - /* now compare epoch */ - if (ea && eb) - sense = rpmvercmp(*ea ? ea : "0", *eb ? eb : "0"); - else if (ea && *ea && atol(ea) > 0) - sense = 1; - else if (eb && *eb && atol(eb) > 0) - sense = -1; - /* now compare version and release if epoch has not been enough */ - if (sense == 0) { - sense = rpmvercmp(va, vb); - if (sense == 0 && ra && *ra && rb && *rb) - sense = rpmvercmp(ra, rb); - } - /* restore all character that have been modified inline */ - if (rb) rb[-1] = '-'; - if (ra) ra[-1] = '-'; - if (eb) vb[-1] = ':'; - if (ea) va[-1] = ':'; - if (eosb) *eosb = ']'; - if (eosa) *eosa = ']'; - /* finish the overlap computation */ - if (sense < 0 && ((aflags & RPMSENSE_GREATER) || (bflags & RPMSENSE_LESS))) - return 1; - else if (sense > 0 && ((aflags & RPMSENSE_LESS) || (bflags & RPMSENSE_GREATER))) - return 1; - else if (sense == 0 && (((aflags & RPMSENSE_EQUAL) && (bflags & RPMSENSE_EQUAL)) || - ((aflags & RPMSENSE_LESS) && (bflags & RPMSENSE_LESS)) || - ((aflags & RPMSENSE_GREATER) && (bflags & RPMSENSE_GREATER)))) - return 1; - else - return 0; + EVR_t lEVR = rpmEVRnew(aflags, 0), + rEVR = rpmEVRnew(bflags, 0); + + backup_char(eosa); + backup_char(eosb); + rpmEVRparse(sa, lEVR); + rpmEVRparse(sb, rEVR); + /* TODO: upstream bug? should rpmEVRparse really reset Flags? */ + lEVR->Flags = aflags; + rEVR->Flags = bflags; + restore_chars(); + + return rpmEVRoverlap(lEVR,rEVR); } } -- cgit v1.2.1