]> git.pld-linux.org Git - packages/poldek.git/blob - uniqe-package-names.patch
- make "uniq package names" works again
[packages/poldek.git] / uniqe-package-names.patch
1 From 53e0408ad2acd72c684eb7d69a4fe4f1da9aca8b Mon Sep 17 00:00:00 2001
2 From: mis <mis@pld-linux.org>
3 Date: Mon, 16 Mar 2020 14:24:26 +0100
4 Subject: [PATCH] fix: make "uniq package names" works again; closes #4
5
6 ---
7  Makefile.am       |  20 +++----
8  lib_pkgset.c      |  10 ++--
9  pkgmisc.h         |   3 +-
10  pkgset.c          |  36 ++-----------
11  pkguniq.c         |  56 ++++++++++++++++++++
12  tests/sh/09-repos | 130 ++++++++++++++++++++++++++++++++++++++++++++++
13  6 files changed, 209 insertions(+), 46 deletions(-)
14  create mode 100644 pkguniq.c
15  create mode 100755 tests/sh/09-repos
16
17 diff --git a/Makefile.am b/Makefile.am
18 index e896c4e..25ddf14 100644
19 --- a/Makefile.am
20 +++ b/Makefile.am
21 @@ -24,13 +24,13 @@ libpoldek_la_SOURCES = \
22           compiler.h    \
23           log.c log.h      \
24           poldek_term.c poldek_term.h   \
25 -         minfo.c                           \
26 +         minfo.c                       \
27           misc.c misc.h                 \
28 -         pkgmisc.c pkgmisc.h                   \
29 -         depdirs.c depdirs.h   \
30 -         pkg.c pkgiter.c pkg.h                 \
31 +         pkgmisc.c pkgmisc.h           \
32 +         depdirs.c depdirs.h           \
33 +         pkg.c pkgiter.c pkg.h         \
34           pkgcmp.c pkgcmp.h             \
35 -         pkgu.c pkgu.h         \
36 +         pkgu.c pkgu.h                 \
37           pkgfl.c pkgfl.h               \
38           fileindex.c fileindex.h       \
39           capreqidx.c capreqidx.h       \
40 @@ -38,10 +38,12 @@ libpoldek_la_SOURCES = \
41           pkgset-load.c                 \
42           pkgset.c pkgset.h             \
43           pkgset-req.c pkgset-req.h     \
44 -         pkgset-order.c        \
45 -         arg_packages.c arg_packages.h         \
46 -         conf.c conf.h conf_intern.h conf_sections.c \
47 -         split.c split.h               \
48 +         pkgset-order.c                \
49 +         pkguniq.c                     \
50 +         arg_packages.c arg_packages.h \
51 +         conf.c conf.h                 \
52 +         conf_intern.h conf_sections.c \
53 +         split.c split.h       \
54           pkgroup.c pkgroup.h   \
55           pkgscore.c            \
56           pkgfetch.c            \
57 diff --git a/lib_pkgset.c b/lib_pkgset.c
58 index 6fed521..96cbada 100644
59 --- a/lib_pkgset.c
60 +++ b/lib_pkgset.c
61 @@ -43,7 +43,7 @@ int poldek__load_sources_internal(struct poldek_ctx *ctx, unsigned ps_setup_flag
62  {
63      struct pkgset *ps;
64      struct poldek_ts *ts;
65 -    unsigned ps_flags = 0, ldflags = 0;
66 +    unsigned ldflags = 0;
67  
68      n_assert(ctx->pmctx);
69      n_assert(ctx->ps == NULL);
70 @@ -95,7 +95,7 @@ int poldek__load_sources_internal(struct poldek_ctx *ctx, unsigned ps_setup_flag
71      ctx->pkgdirs = n_ref(ps->pkgdirs);
72  
73      if (ts->getop(ts, POLDEK_OP_UNIQN))
74 -        ps_flags |= PSET_UNIQ_PKGNAME;
75 +        ps_setup_flags |= PSET_UNIQ_PKGNAME;
76  
77      pkgset_setup(ps, ps_setup_flags);
78  
79 @@ -144,9 +144,11 @@ tn_array *poldek_load_stubs(struct poldek_ctx *ctx)
80                  n_array_push(stubpkgs, pkg);
81          }
82      }
83 +    n_array_sort(stubpkgs);
84 +    n_array_isort_ex(stubpkgs, (tn_fn_cmp)pkg_cmp_name_evr_arch_rev_srcpri);
85  
86 -    n_array_sort_ex(stubpkgs, (tn_fn_cmp)pkg_deepcmp_name_evr_rev);
87 -    n_array_uniq_ex(stubpkgs, (tn_fn_cmp)pkg_cmp_uniq_name_evr_arch);
88 +    struct poldek_ts *ts = ctx->ts;
89 +    packages_uniq(stubpkgs, ts->getop(ts, POLDEK_OP_UNIQN) ? true : false);
90  
91      return stubpkgs;
92  }
93 diff --git a/pkgmisc.h b/pkgmisc.h
94 index 074ec34..9b387d1 100644
95 --- a/pkgmisc.h
96 +++ b/pkgmisc.h
97 @@ -15,7 +15,7 @@
98  
99  #include <stdint.h>
100  #include <trurl/narray.h>
101 -
102 +#include <stdbool.h>
103  #ifndef EXPORT
104  # define EXPORT extern
105  #endif
106 @@ -36,6 +36,7 @@ EXPORT int packages_score_ignore(tn_array *pkgs, tn_array *patterns, int remove)
107  
108  /*  === utils ===  */
109  EXPORT int packages_dump(tn_array *pkgs, const char *path, int fqfn);
110 +EXPORT int packages_uniq(tn_array *pkgs, bool by_name);
111  
112  
113  struct pm_ctx;
114 diff --git a/pkgset.c b/pkgset.c
115 index 4ad7dfb..714355f 100644
116 --- a/pkgset.c
117 +++ b/pkgset.c
118 @@ -33,6 +33,7 @@
119  #include "log.h"
120  #include "capreq.h"
121  #include "pkg.h"
122 +#include "pkgmisc.h"
123  #include "pkgset.h"
124  #include "misc.h"
125  #include "pkgset-req.h"
126 @@ -205,26 +206,6 @@ static int pkgset_index(struct pkgset *ps)
127      return 0;
128  }
129  
130 -static
131 -int do_pkg_cmp_uniq_nevr(const struct pkg *p1, struct pkg *p2)
132 -{
133 -    register int rc;
134 -
135 -    if ((rc = pkg_cmp_uniq_name_evr(p1, p2)) == 0)
136 -        pkg_score(p2, PKG_IGNORED_UNIQ);
137 -    return rc;
138 -}
139 -
140 -static
141 -int do_pkg_cmp_uniq_n(const struct pkg *p1, struct pkg *p2)
142 -{
143 -    register int rc;
144 -
145 -    if ((rc = pkg_cmp_uniq_name(p1, p2)) == 0)
146 -        pkg_score(p2, PKG_IGNORED_UNIQ);
147 -    return rc;
148 -}
149 -
150  int pkgset_setup_deps(struct pkgset *ps, unsigned flags)
151  {
152      int strict = ps->flags & PSET_VRFY_MERCY ? 0 : 1;
153 @@ -262,29 +243,20 @@ int pkgset_setup_deps(struct pkgset *ps, unsigned flags)
154      return 1;
155  }
156  
157 +
158  static int pkgset_setup_index(struct pkgset *ps, unsigned flags)
159  {
160 -    int n;
161      void *t = timethis_begin();
162  
163      msgn(2, "Preparing package set...");
164      MEMINF("before setup");
165 -
166      ps->flags |= flags;
167  
168 -    n = n_array_size(ps->pkgs);
169      n_array_sort(ps->pkgs);
170 -
171      n_array_isort_ex(ps->pkgs, (tn_fn_cmp)pkg_cmp_name_evr_arch_rev_srcpri);
172 +    int n = packages_uniq(ps->pkgs, (flags & PSET_UNIQ_PKGNAME) ? true : false);
173  
174 -    if (flags & PSET_UNIQ_PKGNAME) {
175 -        n_array_uniq_ex(ps->pkgs, (tn_fn_cmp)do_pkg_cmp_uniq_n);
176 -    } else {
177 -        n_array_uniq_ex(ps->pkgs, (tn_fn_cmp)do_pkg_cmp_uniq_nevr);
178 -    }
179 -
180 -    if (n != n_array_size(ps->pkgs)) {
181 -        n -= n_array_size(ps->pkgs);
182 +    if (n != 0) {
183          msgn(1, ngettext(
184                           "Removed %d duplicate package from available set",
185                           "Removed %d duplicate packages from available set", n), n);
186 diff --git a/pkguniq.c b/pkguniq.c
187 new file mode 100644
188 index 0000000..f600789
189 --- /dev/null
190 +++ b/pkguniq.c
191 @@ -0,0 +1,56 @@
192 +/*
193 +  Copyright (C) 2000 - 2008 Pawel A. Gajda <mis@pld-linux.org>
194 +
195 +  This program is free software; you can redistribute it and/or modify
196 +  it under the terms of the GNU General Public License, version 2 as
197 +  published by the Free Software Foundation (see file COPYING for details).
198 +
199 +  You should have received a copy of the GNU General Public License along
200 +  with this program; if not, write to the Free Software Foundation, Inc.,
201 +  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
202 +*/
203 +
204 +#ifdef HAVE_CONFIG_H
205 +# include "config.h"
206 +#endif
207 +
208 +#include <stdbool.h>
209 +#include <trurl/narray.h>
210 +
211 +#include "pkg.h"
212 +#include "pkgcmp.h"
213 +
214 +static
215 +int do_pkg_cmp_uniq_name_evr(const struct pkg *p1, struct pkg *p2)
216 +{
217 +    register int rc;
218 +
219 +    if ((rc = pkg_cmp_uniq_name_evr(p1, p2)) == 0)
220 +        pkg_score(p2, PKG_IGNORED_UNIQ);
221 +
222 +    return rc;
223 +}
224 +
225 +static
226 +int do_pkg_cmp_uniq_name(const struct pkg *p1, struct pkg *p2)
227 +{
228 +    register int rc;
229 +
230 +    if ((rc = pkg_cmp_uniq_name(p1, p2)) == 0)
231 +        pkg_score(p2, PKG_IGNORED_UNIQ);
232 +
233 +    return rc;
234 +}
235 +
236 +int packages_uniq(tn_array *pkgs, bool names)
237 +{
238 +    int n = n_array_size(pkgs);
239 +
240 +    if (names) {
241 +        n_array_uniq_ex(pkgs, (tn_fn_cmp)do_pkg_cmp_uniq_name);
242 +    } else {
243 +        n_array_uniq_ex(pkgs, (tn_fn_cmp)do_pkg_cmp_uniq_name_evr);
244 +    }
245 +
246 +    return n - n_array_size(pkgs);
247 +}
248 diff --git a/tests/sh/09-repos b/tests/sh/09-repos
249 new file mode 100755
250 index 0000000..a420bf9
251 --- /dev/null
252 +++ b/tests/sh/09-repos
253 @@ -0,0 +1,130 @@
254 +#!/bin/sh
255 +# $Id$
256 +
257 +. ./sh/lib/setup
258 +. ./sh/lib/repo-setup
259 +. ./sh/lib/solver-setup         # for build_package
260 +
261 +ORIGREPO=
262 +DESTINATION_REPO=
263 +DEPENDENCY_SOLVER=3
264 +
265 +setUp() {
266 +    [ -z "$ORIGREPO" ] && ORIGREPO=$REPO
267 +    [ -z "$ORIGREPO" ] && fail "empty REPO env variable"
268 +    rm -rf $ORIGREPO/*
269 +
270 +    REPO="$ORIGREPO/repo1"
271 +    REPO2="$ORIGREPO/repo2"
272 +
273 +    rm -rf $REPO $REPO2
274 +
275 +    mkdir -p $REPO || fail "mkdir $REPO failed"
276 +    mkdir -p $REPO2 || fail "mkdir $REPO2 failed"
277 +
278 +    mkidx $REPO
279 +    mkidx $REPO2
280 +
281 +    RAW_POLDEK="$POLDEK_NOCONF"
282 +    rm -rf $CACHEDIR
283 +}
284 +
285 +build() {
286 +   build_package $REPO $@
287 +}
288 +
289 +build2() {
290 +   build_package $REPO2 $@
291 +}
292 +
293 +mkidx() {
294 +    local repo=$1
295 +    $POLDEK_NOCONF -s $repo --mkidx --mt pndir || fail "mkidx $repo failed"
296 +}
297 +
298 +expect_count() {
299 +    local expected=$1
300 +    shift
301 +
302 +    is_verbose_mode && echo "$RAW_POLDEK -v -s $REPO -s $REPO2 $@ --cmd ls"
303 +    is_verbose_mode && $RAW_POLDEK -v -s $REPO -s $REPO2 $@ --cmd ls
304 +    n=$($RAW_POLDEK -q -s $REPO -s $REPO2 $@ --cmd ls | grep -P '^\w+-\d+-\d+\.\w+$' | wc -l)
305 +
306 +    assertEquals "invalid number of packages found (expected $expected, got $n)" "$n" "$expected"
307 +    [ "$n" == "$expected" ]
308 +}
309 +
310 +expect_package() {
311 +    local expected=$1
312 +    shift
313 +
314 +    is_verbose_mode && echo "$RAW_POLDEK -v -s $REPO -s $REPO2 --cmd ls"
315 +    is_verbose_mode && $RAW_POLDEK -v -s $REPO -s $REPO2 --cmd ls
316 +    n=$($RAW_POLDEK -q -s $REPO -s $REPO2 $@ --cmd ls | grep "^$expected" | wc -l)
317 +
318 +    assertEquals "$expected package not found" "$n" "1"
319 +    [ "$n" == "1" ]
320 +}
321 +
322 +testUniquePackages()
323 +{
324 +    msgn "Preparing repository..."
325 +    build a -v 1
326 +    build a -v 2
327 +    build b
328 +    build c
329 +    mkidx $REPO
330 +
331 +    msgn "Testing..."
332 +    expect_count 4
333 +    expect_count 3 -Ounique_package_names=y
334 +    expect_package "a-2-1.noarch" -Ounique_package_names=y
335 +}
336 +
337 +testUniquePackagesDifferentArch()
338 +{
339 +    msgn "Preparing repository..."
340 +
341 +    for i in i686 x86_64; do
342 +        build a 1-1 -a $i -f "/hello.$i"
343 +        build a 2-2 -a $i -f "/hello.$i"
344 +    done
345 +
346 +    for i in i686 x86_64; do
347 +        build b -a $i -f "/hello.$i"
348 +        build c -a $i -f "/hello.$i"
349 +    done
350 +
351 +    mkidx $REPO
352 +    msgn "Testing..."
353 +    expect_count 8
354 +    expect_count 3 -Ounique_package_names=y
355 +    expect_package "a-2-2" -Ounique_package_names=y
356 +}
357 +
358 +testUniquePackagesDifferentRepos()
359 +{
360 +    msgn "Preparing repositories..."
361 +
362 +    build a 1-1
363 +    build2 a 2-2
364 +
365 +    build b 2-2
366 +    build2 b 1-1
367 +
368 +    build c 1-1
369 +    build2 c 1-1
370 +
371 +    mkidx $REPO
372 +    mkidx $REPO2
373 +
374 +    msgn "Testing..."
375 +    expect_count 5
376 +    expect_count 3 -Ounique_package_names=y
377 +    expect_package "a-2-2" -Ounique_package_names=y
378 +    expect_package "b-2-2" -Ounique_package_names=y
379 +    expect_package "c-1-1" -Ounique_package_names=y
380 +}
381 +
382 +
383 +. ./sh/lib/shunit2
This page took 0.463256 seconds and 3 git commands to generate.