- use package build time as EVR comparison tie breaker.
authorjbj <devnull@localhost>
Sun, 28 Mar 2004 14:57:53 +0000 (14:57 +0000)
committerjbj <devnull@localhost>
Sun, 28 Mar 2004 14:57:53 +0000 (14:57 +0000)
CVS patchset: 7201
CVS date: 2004/03/28 14:57:53

CHANGES
lib/psm.c
lib/rpmds.c
lib/rpmds.h
python/rpmds-py.c

diff --git a/CHANGES b/CHANGES
index 41b3dc382cc859c7ec5a4d7c977a025bbe0e7da4..053a7b351f7a1c9e4542fc36f41e0382ade37bfd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+4.3.1 -> 4.4:
+       - use package build time as EVR comparison tie breaker.
+
+4.3 -> 4.3.1:
+
 4.2.2 -> 4.3:
        - upgrade to zlib-1.2.beta7.
        - fix: short option help missing string terminator.
index c521d118563caefee136f04d71aa4fc0ccdc77e7..7e6ef2de77f4aa3bc69aa23c7e570c475b4bbaf9 100644 (file)
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -62,7 +62,8 @@ int rpmVersionCompare(Header first, Header second)
 {
     const char * one, * two;
     int_32 * epochOne, * epochTwo;
-    int rc;
+    int_32 * btOne, * btTwo;
+    int rc = 0;
 
     if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL))
        epochOne = NULL;
@@ -70,17 +71,19 @@ int rpmVersionCompare(Header first, Header second)
        epochTwo = NULL;
 
     if (epochOne != NULL && epochTwo == NULL)
-       return 1;
+       rc = 1;
     else if (epochOne == NULL && epochTwo != NULL)
-       return -1;
+       rc = -1;
     else if (epochOne != NULL && epochTwo != NULL) {
 /*@-boundsread@*/
        if (*epochOne < *epochTwo)
-           return -1;
+           rc = -1;
        else if (*epochOne > *epochTwo)
-           return 1;
+           rc = 1;
 /*@=boundsread@*/
     }
+    if (rc)
+       return rc;
 
     rc = headerGetEntry(first, RPMTAG_VERSION, NULL, (void **) &one, NULL);
     rc = headerGetEntry(second, RPMTAG_VERSION, NULL, (void **) &two, NULL);
@@ -92,7 +95,22 @@ int rpmVersionCompare(Header first, Header second)
     rc = headerGetEntry(first, RPMTAG_RELEASE, NULL, (void **) &one, NULL);
     rc = headerGetEntry(second, RPMTAG_RELEASE, NULL, (void **) &two, NULL);
 
-    return rpmvercmp(one, two);
+    rc = rpmvercmp(one, two);
+    if (rc)
+       return rc;
+
+    if (!headerGetEntry(first, RPMTAG_BUILDTIME, NULL, (void **) &btOne, NULL))
+       btOne = NULL;
+    if (!headerGetEntry(second, RPMTAG_BUILDTIME, NULL, (void **) &btTwo, NULL))
+       btTwo = NULL;
+
+    if (btOne != NULL && btTwo != NULL && *btOne > 0 && *btTwo > 0) {
+/*@-boundsread@*/
+       rc = (*btOne < *btTwo ? -1 : (*btOne == *btTwo ? 0 : -1));
+/*@=boundsread@*/
+    }
+
+    return rc;
 }
 
 /**
index 2677e20a994c232cfa23f836eee3ea4c91d42cb4..1c8dc44f8365bda73f78bcf577d8300d02b598f1 100644 (file)
@@ -118,6 +118,8 @@ rpmds rpmdsNew(Header h, rpmTag tagN, int scareMem)
 {
     HGE_t hge =
        (scareMem ? (HGE_t) headerGetEntryMinMemory : (HGE_t) headerGetEntry);
+    rpmTag tagBT = RPMTAG_BUILDTIME;
+    int_32 BTt, * BTp;
     rpmTag tagEVR, tagF;
     rpmds ds = NULL;
     const char * Type;
@@ -175,6 +177,8 @@ rpmds rpmdsNew(Header h, rpmTag tagN, int scareMem)
        if (!scareMem && ds->Flags != NULL)
            ds->Flags = memcpy(xmalloc(ds->Count * sizeof(*ds->Flags)),
                                 ds->Flags, ds->Count * sizeof(*ds->Flags));
+       xx = hge(h, tagBT, &BTt, (void **) &BTp, NULL);
+       ds->BT = (xx && BTp != NULL && BTt == RPM_INT32_TYPE ? *BTp : 0);
 /*@=boundsread@*/
        ds->Color = xcalloc(Count, sizeof(*ds->Color));
        ds->Refs = xcalloc(Count, sizeof(*ds->Refs));
@@ -347,6 +351,9 @@ rpmds rpmdsSingle(rpmTag tagN, const char * N, const char * EVR, int_32 Flags)
     ds->h = NULL;
     ds->Type = Type;
     ds->tagN = tagN;
+    {  time_t now = time(NULL);
+       ds->BT = now;
+    }
     ds->Count = 1;
     /*@-assignexpose@*/
 /*@-boundswrite@*/
@@ -452,6 +459,24 @@ rpmTag rpmdsTagN(const rpmds ds)
     return tagN;
 }
 
+time_t rpmdsBT(const rpmds ds)
+{
+    time_t BT = 0;
+    if (ds != NULL && ds->BT > 0)
+       BT = ds->BT;
+    return BT;
+}
+
+time_t rpmdsSetBT(const rpmds ds, time_t BT)
+{
+    time_t oBT = 0;
+    if (ds != NULL) {
+       oBT = ds->BT;
+       ds->BT = BT;
+    }
+    return oBT;
+}
+
 int rpmdsNoPromote(const rpmds ds)
 {
     int nopromote = 0;
@@ -879,6 +904,8 @@ int rpmdsCompare(const rpmds A, const rpmds B)
        sense = rpmvercmp(aV, bV);
        if (sense == 0 && aR && *aR && bR && *bR) {
            sense = rpmvercmp(aR, bR);
+           if (sense == 0 && A->BT > 0 && B->BT > 0)
+               sense = (A->BT < B->BT ? -1 : (A->BT == B->BT ? 0 : -1));
        }
     }
 /*@=boundsread@*/
index 9a027f0cd4de589768a03929414b19ed358cb1a1..eddcd320265fdbca30075b177dca673d3ca42c74 100644 (file)
@@ -43,6 +43,7 @@ struct rpmds_s {
     uint_32 * Color;           /*!< Bit(s) calculated from file color(s). */
 /*@only@*/ /*@null@*/
     int_32 * Refs;             /*!< No. of file refs. */
+    int_32 BT;                 /*!< Package build time tie breaker. */
     rpmTag tagN;               /*!< Header tag. */
     rpmTagType Nt, EVRt, Ft;   /*!< Tag data types. */
     int_32 Count;              /*!< No. of elements */
@@ -216,6 +217,22 @@ int_32 rpmdsFlags(/*@null@*/ const rpmds ds)
 rpmTag rpmdsTagN(/*@null@*/ const rpmds ds)
        /*@*/;
 
+/**
+ * Return dependency build time.
+ * @param ds           dependency set
+ * @return             dependency build time, 0 on invalid
+ */
+time_t rpmdsBT(/*@null@*/ const rpmds ds)
+       /*@*/;
+
+/**
+ * Set dependency build time.
+ * @param ds           dependency set
+ * @return             dependency build time, 0 on invalid
+ */
+time_t rpmdsSetBuildtime(/*@null@*/ const rpmds ds, time_t BT)
+       /*@modifies ds @*/;
+
 /**
  * Return current "Don't promote Epoch:" flag.
  *
index 46bd8d7289b4dc38b535b831f67ba5c0b3eb9ff1..f4ac5f02137f80323ed4bee04efeed024ee61dfb 100644 (file)
@@ -127,6 +127,15 @@ rpmds_Flags(rpmdsObject * s, PyObject * args)
     return Py_BuildValue("i", rpmdsFlags(s->ds));
 }
 
+/*@null@*/
+static PyObject *
+rpmds_BT(rpmdsObject * s, PyObject * args)
+       /*@*/
+{
+    if (!PyArg_ParseTuple(args, ":BT")) return NULL;
+    return Py_BuildValue("i", (int) rpmdsBT(s->ds));
+}
+
 /*@null@*/
 static PyObject *
 rpmds_TagN(rpmdsObject * s, PyObject * args)
@@ -338,6 +347,8 @@ static struct PyMethodDef rpmds_methods[] = {
        "ds.EVR -> EVR          - Return current EVR.\n" },
  {"Flags",     (PyCFunction)rpmds_Flags,       METH_VARARGS,
        "ds.Flags -> Flags      - Return current Flags.\n" },
+ {"BT",                (PyCFunction)rpmds_BT,          METH_VARARGS,
+       "ds.BT -> BT    - Return build time.\n" },
  {"TagN",      (PyCFunction)rpmds_TagN,        METH_VARARGS,
        "ds.TagN -> TagN        - Return current TagN.\n" },
  {"Color",     (PyCFunction)rpmds_Color,       METH_VARARGS,