From 63f24f2307426106a0bccde91c1b8cfa8bc5da36 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 28 May 2008 09:35:13 +0300 Subject: [PATCH] Unify rpmdbAdd() and rpmdbRemove() debug logging - move the debugging out of the loop, we only print once for a given tag anyway - dumb helper function for prepping the actual output --- lib/rpmdb.c | 54 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/lib/rpmdb.c b/lib/rpmdb.c index fc7d9f2..a1bb89e 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -2399,6 +2399,22 @@ static int td2key(rpmtd tagdata, DBT *key) return 1; } +static void logAddRemove(int removing, rpmtd tagdata) +{ + rpm_count_t c = rpmtdCount(tagdata); + if (c == 1 && rpmtdType(tagdata) == RPM_STRING_TYPE) { + rpmlog(RPMLOG_DEBUG, "%s \"%s\" %s %s index.\n", + removing ? "removing" : "adding", rpmtdGetString(tagdata), + removing ? "from" : "to", + rpmTagGetName(rpmtdTag(tagdata))); + } else if (c > 0) { + rpmlog(RPMLOG_DEBUG, "%s %d entries %s %s index.\n", + removing ? "removing" : "adding", c, + removing ? "from" : "to", + rpmTagGetName(rpmtdTag(tagdata))); + } +} + /* XXX psm.c */ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum, rpmts ts, @@ -2449,7 +2465,7 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum, for (dbix = 0; dbix < dbiTags.max; dbix++) { dbiIndex dbi; rpmTag rpmtag; - int xx, printed = 0; + int xx = 0; struct rpmtd_s tagdata; dbi = NULL; @@ -2495,6 +2511,9 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum, xx = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, DB_WRITECURSOR); rpmtdInit(&tagdata); + + logAddRemove(1, &tagdata); + while (rpmtdNext(&tagdata) >= 0) { dbiIndexSet set; @@ -2502,21 +2521,6 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum, continue; } - if (!printed) { - int stringvalued = (rpmtdType(&tagdata) == RPM_STRING_TYPE); - rpm_count_t c = rpmtdCount(&tagdata); - if (c == 1 && stringvalued) { - rpmlog(RPMLOG_DEBUG, - "removing \"%s\" from %s index.\n", - (char *)key.data, rpmTagGetName(rpmtag)); - } else { - rpmlog(RPMLOG_DEBUG, - "removing %d entries from %s index.\n", - c, rpmTagGetName(rpmtag)); - } - printed++; - } - /* XXX * This is almost right, but, if there are duplicate tag * values, there will be duplicate attempts to remove @@ -2781,10 +2785,9 @@ int rpmdbAdd(rpmdb db, int iid, Header h, dbi = dbiOpen(db, rpmtag, 0); if (dbi != NULL) { - int printed = 0; - xx = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, DB_WRITECURSOR); + logAddRemove(0, &tagdata); while (rpmtdNext(&tagdata) >= 0) { dbiIndexSet set; int i; @@ -2822,21 +2825,6 @@ int rpmdbAdd(rpmdb db, int iid, Header h, continue; } - if (!printed) { - int stringvalued = (rpmtdType(&tagdata) == RPM_STRING_TYPE); - rpm_count_t c = rpmtdCount(&tagdata); - if (c == 1 && stringvalued) { - rpmlog(RPMLOG_DEBUG, - "adding \"%s\" to %s index.\n", - (char *)key.data, rpmTagGetName(rpmtag)); - } else { - rpmlog(RPMLOG_DEBUG, - "adding %d entries to %s index.\n", - c, rpmTagGetName(rpmtag)); - } - printed++; - } - /* * XXX with duplicates, an accurate data value and * DB_GET_BOTH is needed. -- 2.7.4