From 3cfac308be04a96a192afa8be8f6a7c08bfbdfba Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 12 Nov 2008 19:24:58 +0200 Subject: [PATCH] Take advantage of headerGetInstance() in rpmte - rpmte db_instance and dboffset are exactly the same thing, unify - pull rpmte->db_instance from header directly, ignore dboffset argument to rpmteNew() (removing the arg would just break api needlessly, otoh it's unlikely that anything outside rpm actually uses rpmteNew()) - eliminate the now unnecessary added/removed union from te struct - rpmteDBOffset() is now just an alias for rpmteDBInstance(), deprecate? --- lib/depends.c | 2 +- lib/rpmte.c | 24 +++++++++--------------- lib/rpmte.h | 2 +- lib/rpmte_internal.h | 11 ++--------- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/lib/depends.c b/lib/depends.c index 852135a..746c8fc 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -96,7 +96,7 @@ static int removePackage(rpmts ts, Header h, int dboffset, ts->order = xrealloc(ts->order, sizeof(*ts->order) * ts->orderAlloced); } - p = rpmteNew(ts, h, TR_REMOVED, NULL, NULL, dboffset, depends); + p = rpmteNew(ts, h, TR_REMOVED, NULL, NULL, -1, depends); ts->order[ts->orderCount] = p; ts->orderCount++; diff --git a/lib/rpmte.c b/lib/rpmte.c index ff13426..8c885e2 100644 --- a/lib/rpmte.c +++ b/lib/rpmte.c @@ -126,10 +126,7 @@ static void addTE(rpmts ts, rpmte p, Header h, p->relocs[i].newPath = NULL; } - /* Set db_instance to 0 as it has not been installed - * necessarily yet. - */ - p->db_instance = 0; + p->db_instance = headerGetInstance(h); p->key = key; p->fd = NULL; @@ -172,30 +169,27 @@ rpmte rpmteNew(const rpmts ts, Header h, struct rpmtd_s size; p->type = type; + p->pkgKey = pkgKey; addTE(ts, p, h, key, relocs); switch (type) { case TR_ADDED: - p->u.addedKey = pkgKey; headerGet(h, RPMTAG_SIGSIZE, &size, HEADERGET_DEFAULT); if ((ep = rpmtdGetUint32(&size))) { p->pkgFileSize += 96 + 256 + *ep; } break; case TR_REMOVED: - p->u.removed.dependsOnKey = pkgKey; - p->u.removed.dboffset = dboffset; + /* nothing to do */ break; } return p; } -/* Get the DB Instance value */ unsigned int rpmteDBInstance(rpmte te) { return (te != NULL ? te->db_instance : 0); } -/* Set the DB Instance value */ void rpmteSetDBInstance(rpmte te, unsigned int instance) { if (te != NULL) @@ -400,15 +394,15 @@ void rpmteNewTSI(rpmte te) rpmalKey rpmteAddedKey(rpmte te) { - return (te != NULL ? te->u.addedKey : RPMAL_NOMATCH); + return (te != NULL && te->type == TR_ADDED ? te->pkgKey : RPMAL_NOMATCH); } rpmalKey rpmteSetAddedKey(rpmte te, rpmalKey npkgKey) { rpmalKey opkgKey = RPMAL_NOMATCH; - if (te != NULL) { - opkgKey = te->u.addedKey; - te->u.addedKey = npkgKey; + if (te != NULL && te->type == TR_ADDED) { + opkgKey = te->pkgKey; + te->pkgKey = npkgKey; } return opkgKey; } @@ -416,12 +410,12 @@ rpmalKey rpmteSetAddedKey(rpmte te, rpmalKey npkgKey) rpmalKey rpmteDependsOnKey(rpmte te) { - return (te != NULL ? te->u.removed.dependsOnKey : RPMAL_NOMATCH); + return (te != NULL && te->type == TR_REMOVED ? te->pkgKey : RPMAL_NOMATCH); } int rpmteDBOffset(rpmte te) { - return (te != NULL ? te->u.removed.dboffset : 0); + return rpmteDBInstance(te); } const char * rpmteEVR(rpmte te) diff --git a/lib/rpmte.h b/lib/rpmte.h index 5cc3a02..c1136b4 100644 --- a/lib/rpmte.h +++ b/lib/rpmte.h @@ -48,7 +48,7 @@ rpmte rpmteFree(rpmte te); * @param type TR_ADDED/TR_REMOVED * @param key (TR_ADDED) package retrieval key (e.g. file name) * @param relocs (TR_ADDED) package file relocations - * @param dboffset (TR_REMOVED) rpmdb instance + * @param dboffset unused * @param pkgKey associated added package (if any) * @return new transaction element */ diff --git a/lib/rpmte_internal.h b/lib/rpmte_internal.h index e12cec7..fc22874 100644 --- a/lib/rpmte_internal.h +++ b/lib/rpmte_internal.h @@ -44,7 +44,7 @@ struct rpmte_s { int tree; /*!< Tree index. */ int depth; /*!< Depth in dependency tree. */ int breadth; /*!< Breadth in dependency tree. */ - unsigned int db_instance; /*!< Database Instance after add */ + unsigned int db_instance; /*!< Database instance (of removed pkgs) */ tsortInfo tsi; /*!< Dependency ordering chains. */ rpmds this; /*!< This package's provided NEVR. */ @@ -62,14 +62,7 @@ struct rpmte_s { int nrelocs; /*!< (TR_ADDED) No. of relocations. */ FD_t fd; /*!< (TR_ADDED) Payload file descriptor. */ - union { - rpmalKey addedKey; - struct { - rpmalKey dependsOnKey; - int dboffset; - } removed; - } u; - + rpmalKey pkgKey; }; /** -- 2.7.4