]> git.pld-linux.org Git - packages/poldek.git/commitdiff
- make "uniq package names" works again
authorJan Rękorajski <baggins@pld-linux.org>
Mon, 16 Mar 2020 17:46:14 +0000 (18:46 +0100)
committerJan Rękorajski <baggins@pld-linux.org>
Mon, 16 Mar 2020 17:46:14 +0000 (18:46 +0100)
- rel 2

poldek.spec
uniqe-package-names.patch [new file with mode: 0644]

index 73f18521425d74030f47d485f8ca77476a110cd7..bc32ac18dfdb903c0e90d20e87c1ccc1e4fd9eda 100644 (file)
@@ -25,7 +25,7 @@
 %define                ver_rpm         5.4.10
 %endif
 
-%define                rel     1
+%define                rel     2
 Summary:       RPM packages management helper tool
 Summary(hu.UTF-8):     RPM csomagkezelést segítő eszköz
 Summary(pl.UTF-8):     Pomocnicze narzędzie do zarządzania pakietami RPM
@@ -55,6 +55,7 @@ Patch0:               %{name}-config.patch
 Patch1:                pm-hooks.patch
 Patch2:                %{name}-ext-down-enable.patch
 Patch3:                %{name}-pc.patch
+Patch4:                uniqe-package-names.patch
 URL:           http://poldek.pld-linux.org/
 BuildRequires: %{db_pkg}-devel >= %{ver_db}
 BuildRequires: autoconf >= 2.63
@@ -228,6 +229,7 @@ Moduły języka Python dla poldka.
 %patch1 -p1
 %patch2 -p1
 %patch3 -p1
+%patch4 -p1
 
 %{__rm} m4/libtool.m4 m4/lt*.m4
 
diff --git a/uniqe-package-names.patch b/uniqe-package-names.patch
new file mode 100644 (file)
index 0000000..fa317ba
--- /dev/null
@@ -0,0 +1,383 @@
+From 53e0408ad2acd72c684eb7d69a4fe4f1da9aca8b Mon Sep 17 00:00:00 2001
+From: mis <mis@pld-linux.org>
+Date: Mon, 16 Mar 2020 14:24:26 +0100
+Subject: [PATCH] fix: make "uniq package names" works again; closes #4
+
+---
+ Makefile.am       |  20 +++----
+ lib_pkgset.c      |  10 ++--
+ pkgmisc.h         |   3 +-
+ pkgset.c          |  36 ++-----------
+ pkguniq.c         |  56 ++++++++++++++++++++
+ tests/sh/09-repos | 130 ++++++++++++++++++++++++++++++++++++++++++++++
+ 6 files changed, 209 insertions(+), 46 deletions(-)
+ create mode 100644 pkguniq.c
+ create mode 100755 tests/sh/09-repos
+
+diff --git a/Makefile.am b/Makefile.am
+index e896c4e..25ddf14 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -24,13 +24,13 @@ libpoldek_la_SOURCES = \
+         compiler.h    \
+         log.c log.h      \
+         poldek_term.c poldek_term.h   \
+-        minfo.c                           \
++        minfo.c                       \
+         misc.c misc.h                 \
+-        pkgmisc.c pkgmisc.h                   \
+-        depdirs.c depdirs.h   \
+-        pkg.c pkgiter.c pkg.h                 \
++        pkgmisc.c pkgmisc.h           \
++        depdirs.c depdirs.h           \
++        pkg.c pkgiter.c pkg.h         \
+         pkgcmp.c pkgcmp.h             \
+-        pkgu.c pkgu.h         \
++        pkgu.c pkgu.h                 \
+         pkgfl.c pkgfl.h               \
+         fileindex.c fileindex.h       \
+         capreqidx.c capreqidx.h       \
+@@ -38,10 +38,12 @@ libpoldek_la_SOURCES = \
+         pkgset-load.c                 \
+         pkgset.c pkgset.h             \
+         pkgset-req.c pkgset-req.h     \
+-        pkgset-order.c        \
+-        arg_packages.c arg_packages.h         \
+-        conf.c conf.h conf_intern.h conf_sections.c \
+-        split.c split.h               \
++        pkgset-order.c                \
++        pkguniq.c                     \
++        arg_packages.c arg_packages.h \
++        conf.c conf.h                 \
++        conf_intern.h conf_sections.c \
++        split.c split.h       \
+         pkgroup.c pkgroup.h   \
+         pkgscore.c            \
+         pkgfetch.c            \
+diff --git a/lib_pkgset.c b/lib_pkgset.c
+index 6fed521..96cbada 100644
+--- a/lib_pkgset.c
++++ b/lib_pkgset.c
+@@ -43,7 +43,7 @@ int poldek__load_sources_internal(struct poldek_ctx *ctx, unsigned ps_setup_flag
+ {
+     struct pkgset *ps;
+     struct poldek_ts *ts;
+-    unsigned ps_flags = 0, ldflags = 0;
++    unsigned ldflags = 0;
+     n_assert(ctx->pmctx);
+     n_assert(ctx->ps == NULL);
+@@ -95,7 +95,7 @@ int poldek__load_sources_internal(struct poldek_ctx *ctx, unsigned ps_setup_flag
+     ctx->pkgdirs = n_ref(ps->pkgdirs);
+     if (ts->getop(ts, POLDEK_OP_UNIQN))
+-        ps_flags |= PSET_UNIQ_PKGNAME;
++        ps_setup_flags |= PSET_UNIQ_PKGNAME;
+     pkgset_setup(ps, ps_setup_flags);
+@@ -144,9 +144,11 @@ tn_array *poldek_load_stubs(struct poldek_ctx *ctx)
+                 n_array_push(stubpkgs, pkg);
+         }
+     }
++    n_array_sort(stubpkgs);
++    n_array_isort_ex(stubpkgs, (tn_fn_cmp)pkg_cmp_name_evr_arch_rev_srcpri);
+-    n_array_sort_ex(stubpkgs, (tn_fn_cmp)pkg_deepcmp_name_evr_rev);
+-    n_array_uniq_ex(stubpkgs, (tn_fn_cmp)pkg_cmp_uniq_name_evr_arch);
++    struct poldek_ts *ts = ctx->ts;
++    packages_uniq(stubpkgs, ts->getop(ts, POLDEK_OP_UNIQN) ? true : false);
+     return stubpkgs;
+ }
+diff --git a/pkgmisc.h b/pkgmisc.h
+index 074ec34..9b387d1 100644
+--- a/pkgmisc.h
++++ b/pkgmisc.h
+@@ -15,7 +15,7 @@
+ #include <stdint.h>
+ #include <trurl/narray.h>
+-
++#include <stdbool.h>
+ #ifndef EXPORT
+ # define EXPORT extern
+ #endif
+@@ -36,6 +36,7 @@ EXPORT int packages_score_ignore(tn_array *pkgs, tn_array *patterns, int remove)
+ /*  === utils ===  */
+ EXPORT int packages_dump(tn_array *pkgs, const char *path, int fqfn);
++EXPORT int packages_uniq(tn_array *pkgs, bool by_name);
+ struct pm_ctx;
+diff --git a/pkgset.c b/pkgset.c
+index 4ad7dfb..714355f 100644
+--- a/pkgset.c
++++ b/pkgset.c
+@@ -33,6 +33,7 @@
+ #include "log.h"
+ #include "capreq.h"
+ #include "pkg.h"
++#include "pkgmisc.h"
+ #include "pkgset.h"
+ #include "misc.h"
+ #include "pkgset-req.h"
+@@ -205,26 +206,6 @@ static int pkgset_index(struct pkgset *ps)
+     return 0;
+ }
+-static
+-int do_pkg_cmp_uniq_nevr(const struct pkg *p1, struct pkg *p2)
+-{
+-    register int rc;
+-
+-    if ((rc = pkg_cmp_uniq_name_evr(p1, p2)) == 0)
+-        pkg_score(p2, PKG_IGNORED_UNIQ);
+-    return rc;
+-}
+-
+-static
+-int do_pkg_cmp_uniq_n(const struct pkg *p1, struct pkg *p2)
+-{
+-    register int rc;
+-
+-    if ((rc = pkg_cmp_uniq_name(p1, p2)) == 0)
+-        pkg_score(p2, PKG_IGNORED_UNIQ);
+-    return rc;
+-}
+-
+ int pkgset_setup_deps(struct pkgset *ps, unsigned flags)
+ {
+     int strict = ps->flags & PSET_VRFY_MERCY ? 0 : 1;
+@@ -262,29 +243,20 @@ int pkgset_setup_deps(struct pkgset *ps, unsigned flags)
+     return 1;
+ }
++
+ static int pkgset_setup_index(struct pkgset *ps, unsigned flags)
+ {
+-    int n;
+     void *t = timethis_begin();
+     msgn(2, "Preparing package set...");
+     MEMINF("before setup");
+-
+     ps->flags |= flags;
+-    n = n_array_size(ps->pkgs);
+     n_array_sort(ps->pkgs);
+-
+     n_array_isort_ex(ps->pkgs, (tn_fn_cmp)pkg_cmp_name_evr_arch_rev_srcpri);
++    int n = packages_uniq(ps->pkgs, (flags & PSET_UNIQ_PKGNAME) ? true : false);
+-    if (flags & PSET_UNIQ_PKGNAME) {
+-        n_array_uniq_ex(ps->pkgs, (tn_fn_cmp)do_pkg_cmp_uniq_n);
+-    } else {
+-        n_array_uniq_ex(ps->pkgs, (tn_fn_cmp)do_pkg_cmp_uniq_nevr);
+-    }
+-
+-    if (n != n_array_size(ps->pkgs)) {
+-        n -= n_array_size(ps->pkgs);
++    if (n != 0) {
+         msgn(1, ngettext(
+                          "Removed %d duplicate package from available set",
+                          "Removed %d duplicate packages from available set", n), n);
+diff --git a/pkguniq.c b/pkguniq.c
+new file mode 100644
+index 0000000..f600789
+--- /dev/null
++++ b/pkguniq.c
+@@ -0,0 +1,56 @@
++/*
++  Copyright (C) 2000 - 2008 Pawel A. Gajda <mis@pld-linux.org>
++
++  This program is free software; you can redistribute it and/or modify
++  it under the terms of the GNU General Public License, version 2 as
++  published by the Free Software Foundation (see file COPYING for details).
++
++  You should have received a copy of the GNU General Public License along
++  with this program; if not, write to the Free Software Foundation, Inc.,
++  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
++*/
++
++#ifdef HAVE_CONFIG_H
++# include "config.h"
++#endif
++
++#include <stdbool.h>
++#include <trurl/narray.h>
++
++#include "pkg.h"
++#include "pkgcmp.h"
++
++static
++int do_pkg_cmp_uniq_name_evr(const struct pkg *p1, struct pkg *p2)
++{
++    register int rc;
++
++    if ((rc = pkg_cmp_uniq_name_evr(p1, p2)) == 0)
++        pkg_score(p2, PKG_IGNORED_UNIQ);
++
++    return rc;
++}
++
++static
++int do_pkg_cmp_uniq_name(const struct pkg *p1, struct pkg *p2)
++{
++    register int rc;
++
++    if ((rc = pkg_cmp_uniq_name(p1, p2)) == 0)
++        pkg_score(p2, PKG_IGNORED_UNIQ);
++
++    return rc;
++}
++
++int packages_uniq(tn_array *pkgs, bool names)
++{
++    int n = n_array_size(pkgs);
++
++    if (names) {
++        n_array_uniq_ex(pkgs, (tn_fn_cmp)do_pkg_cmp_uniq_name);
++    } else {
++        n_array_uniq_ex(pkgs, (tn_fn_cmp)do_pkg_cmp_uniq_name_evr);
++    }
++
++    return n - n_array_size(pkgs);
++}
+diff --git a/tests/sh/09-repos b/tests/sh/09-repos
+new file mode 100755
+index 0000000..a420bf9
+--- /dev/null
++++ b/tests/sh/09-repos
+@@ -0,0 +1,130 @@
++#!/bin/sh
++# $Id$
++
++. ./sh/lib/setup
++. ./sh/lib/repo-setup
++. ./sh/lib/solver-setup         # for build_package
++
++ORIGREPO=
++DESTINATION_REPO=
++DEPENDENCY_SOLVER=3
++
++setUp() {
++    [ -z "$ORIGREPO" ] && ORIGREPO=$REPO
++    [ -z "$ORIGREPO" ] && fail "empty REPO env variable"
++    rm -rf $ORIGREPO/*
++
++    REPO="$ORIGREPO/repo1"
++    REPO2="$ORIGREPO/repo2"
++
++    rm -rf $REPO $REPO2
++
++    mkdir -p $REPO || fail "mkdir $REPO failed"
++    mkdir -p $REPO2 || fail "mkdir $REPO2 failed"
++
++    mkidx $REPO
++    mkidx $REPO2
++
++    RAW_POLDEK="$POLDEK_NOCONF"
++    rm -rf $CACHEDIR
++}
++
++build() {
++   build_package $REPO $@
++}
++
++build2() {
++   build_package $REPO2 $@
++}
++
++mkidx() {
++    local repo=$1
++    $POLDEK_NOCONF -s $repo --mkidx --mt pndir || fail "mkidx $repo failed"
++}
++
++expect_count() {
++    local expected=$1
++    shift
++
++    is_verbose_mode && echo "$RAW_POLDEK -v -s $REPO -s $REPO2 $@ --cmd ls"
++    is_verbose_mode && $RAW_POLDEK -v -s $REPO -s $REPO2 $@ --cmd ls
++    n=$($RAW_POLDEK -q -s $REPO -s $REPO2 $@ --cmd ls | grep -P '^\w+-\d+-\d+\.\w+$' | wc -l)
++
++    assertEquals "invalid number of packages found (expected $expected, got $n)" "$n" "$expected"
++    [ "$n" == "$expected" ]
++}
++
++expect_package() {
++    local expected=$1
++    shift
++
++    is_verbose_mode && echo "$RAW_POLDEK -v -s $REPO -s $REPO2 --cmd ls"
++    is_verbose_mode && $RAW_POLDEK -v -s $REPO -s $REPO2 --cmd ls
++    n=$($RAW_POLDEK -q -s $REPO -s $REPO2 $@ --cmd ls | grep "^$expected" | wc -l)
++
++    assertEquals "$expected package not found" "$n" "1"
++    [ "$n" == "1" ]
++}
++
++testUniquePackages()
++{
++    msgn "Preparing repository..."
++    build a -v 1
++    build a -v 2
++    build b
++    build c
++    mkidx $REPO
++
++    msgn "Testing..."
++    expect_count 4
++    expect_count 3 -Ounique_package_names=y
++    expect_package "a-2-1.noarch" -Ounique_package_names=y
++}
++
++testUniquePackagesDifferentArch()
++{
++    msgn "Preparing repository..."
++
++    for i in i686 x86_64; do
++        build a 1-1 -a $i -f "/hello.$i"
++        build a 2-2 -a $i -f "/hello.$i"
++    done
++
++    for i in i686 x86_64; do
++        build b -a $i -f "/hello.$i"
++        build c -a $i -f "/hello.$i"
++    done
++
++    mkidx $REPO
++    msgn "Testing..."
++    expect_count 8
++    expect_count 3 -Ounique_package_names=y
++    expect_package "a-2-2" -Ounique_package_names=y
++}
++
++testUniquePackagesDifferentRepos()
++{
++    msgn "Preparing repositories..."
++
++    build a 1-1
++    build2 a 2-2
++
++    build b 2-2
++    build2 b 1-1
++
++    build c 1-1
++    build2 c 1-1
++
++    mkidx $REPO
++    mkidx $REPO2
++
++    msgn "Testing..."
++    expect_count 5
++    expect_count 3 -Ounique_package_names=y
++    expect_package "a-2-2" -Ounique_package_names=y
++    expect_package "b-2-2" -Ounique_package_names=y
++    expect_package "c-1-1" -Ounique_package_names=y
++}
++
++
++. ./sh/lib/shunit2
This page took 0.194495 seconds and 4 git commands to generate.