diff options
author | Michael Schroeder <mls@suse.de> | 2017-08-03 13:45:02 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2018-03-28 13:25:23 +0300 |
commit | ae432f26645d068b8ef2774c1cbb88396b46268d (patch) | |
tree | c25edb2423ab77f645e45dd15417ff6ad220562c | |
parent | 5dd23a7894d7c9ac49428e27e190db51752f2056 (diff) | |
download | rpm-ae432f26645d068b8ef2774c1cbb88396b46268d.tar.gz |
Change hdrNumCmp to use the tagNum as secondary sort key
This brings rpmdbSortIterator in line with its documentation.
Note that there is a catch: this change also makes the dbiIndexSetPrune
function work different! It used to delete all items that had a
matching hdrNum, after the change only the one is deleted that also
has a matching tagNum. I consider this a bug fix.
Note that dbiIndexSetPrune is only used in the db3.c backend to remove
index entires, if we really want the old behavior we should add a
new dbiIndexSetPruneHdrnum function.
Also remove assertion when trying to sort an empty set.
(cherry picked from commit eb6b13f9a75ba744c88f5a74f183a210554a5c0c)
-rw-r--r-- | lib/backend/dbiset.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/backend/dbiset.c b/lib/backend/dbiset.c index 0ac514582..8fb922ef7 100644 --- a/lib/backend/dbiset.c +++ b/lib/backend/dbiset.c @@ -31,11 +31,12 @@ void dbiIndexSetGrow(dbiIndexSet set, unsigned int nrecs) } } -/* XXX assumes hdrNum is first int in dbiIndexItem */ static int hdrNumCmp(const void * one, const void * two) { - const unsigned int * a = one, * b = two; - return (*a - *b); + const struct dbiIndexItem_s *a = one, *b = two; + if (a->hdrNum - b->hdrNum != 0) + return a->hdrNum - b->hdrNum; + return a->tagNum - b->tagNum; } void dbiIndexSetSort(dbiIndexSet set) @@ -59,7 +60,8 @@ void dbiIndexSetUniq(dbiIndexSet set, int sorted) unsigned int to = 0; unsigned int num = set->count; - assert(set->count > 0); + if (set->count < 2) + return; if (!sorted) dbiIndexSetSort(set); |