+++ /dev/null
---- poldek-0.30-cvs20080820.23/pkg.c~ 2009-01-14 17:33:56.297011561 +0200
-+++ poldek-0.30-cvs20080820.23/pkg.c 2009-01-14 17:33:59.170397703 +0200
-@@ -1451,15 +1451,13 @@
-
- struct pkg *pkg_link(struct pkg *pkg)
- {
--#if ENABLE_TRACE
-- if (strcmp(pkg->name, "XX") == 0) {
-- DBGF("%p %s (pdir %s, na->refcnt=%d), refcnt=%d (%p)\n",
-+ if (pkg->_refcnt >= INT16_MAX - 1) {
-+ trace(1, "%p %s (pdir %s, na->refcnt=%d), refcnt=%d (%p)\n",
- pkg, pkg_snprintf_s(pkg),
- pkg->pkgdir ? pkgdir_idstr(pkg->pkgdir) : "<none>",
- pkg->na ? pkg->na->_refcnt : -1,
- pkg->_refcnt, &pkg->_refcnt);
- }
--#endif
- n_assert(pkg->_refcnt < INT16_MAX - 1);
- pkg->_refcnt++;
- return pkg;
+++ /dev/null
---- poldek-0.30-cvs20080820.23/pkgu.c~ 2009-01-26 20:12:20.700457198 +0200
-+++ poldek-0.30-cvs20080820.23/pkgu.c 2009-01-26 20:12:00.937750881 +0200
-@@ -576,8 +576,9 @@
- nbuf = n_buf_new(1024);
- for (i=0; i < e_name.cnt; i++) {
- char ts[32];
-+ time_t t = times[i];
-
-- strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", gmtime((time_t*)×[i]));
-+ strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", gmtime((time_t*)&t));
-
- n_buf_printf(nbuf, "* %s %s\n", ts, names[i]);
- n_buf_printf(nbuf, "%s\n\n", texts[i]);
+++ /dev/null
---- poldek-0.21-cvs20070703.00/pm/rpm/rpm.c~ 2007-07-02 00:04:27.000000000 +0300
-+++ poldek-0.21-cvs20070703.00/pm/rpm/rpm.c 2008-02-15 05:28:23.107186566 +0200
-@@ -221,6 +221,7 @@
- logn(LOGERR, _("%s%s: open rpm database failed"),
- rootdir ? rootdir:"", dbpath ? dbpath : pm->default_dbpath);
- rc = 0;
-+ abort(); // XXX maybe re-exec ourselves after poldek binary upgrade?
- }
-
- #if ENABLE_TRACE
+++ /dev/null
-diff --git a/conf/poldek.conf b/conf/poldek.conf
-index 13b1e21..24c34a0 100644
---- a/conf/poldek.conf
-+++ b/conf/poldek.conf
-@@ -130,9 +130,11 @@
- choose equivalents manually = yes
-
- # Prevent package listed from being upgraded if they are already installed.
-+# hold = kernel* foo*.i686 th-test:* *-smp-* th-ready:bar*.x86_64
- hold = kernel*
-
- # Ignore package list - packages fits given mask will be invisible.
-+# Masks are same as above.
- # ignore = *-smp-* foo*
- ignore = vserver-packages
- #ignore =
-diff --git a/pkgscore.c b/pkgscore.c
-index f2a527c..0908410 100644
---- a/pkgscore.c
-+++ b/pkgscore.c
-@@ -113,23 +113,28 @@ void pkgscore_match_init(struct pkgscore_s *psc, struct pkg *pkg)
- n += n_snprintf(psc->pkgbuf, sizeof(psc->pkgbuf),
- "%s:", pkg->pkgdir->name);
-
-+ // pkgname_off - size of pkgdir_name
- psc->pkgname_off = n;
-+ // pkgbuf - "repo_name:name-ver-rel.arch"
-
-- pkg_snprintf(&psc->pkgbuf[n], sizeof(psc->pkgbuf) - n, pkg);
-+ n_snprintf(&psc->pkgbuf[n], sizeof(psc->pkgbuf) - n, "%s-%s-%s.%s", pkg->name, pkg->ver, pkg->rel, pkg_arch(pkg));
- psc->pkg = pkg;
- }
-
-
--
-+// return 0 if not match
- int pkgscore_match(struct pkgscore_s *psc, const char *mask)
- {
-+ // match name
- if (fnmatch(mask, psc->pkg->name, 0) == 0)
- return 1;
-
-+ // match name-ver-rel.arch as string
- if (psc->pkgname_off &&
- fnmatch(mask, &psc->pkgbuf[psc->pkgname_off], 0) == 0)
- return 1;
-
-+ // match "repo_name:name-ver-rel.arch" as string
- return fnmatch(mask, psc->pkgbuf, 0) == 0;
- }
-
+++ /dev/null
-commit 7ac464b1d6d1cbeb6f6bcdaf4b477f0c21e3e334
-Author: Marcin Banasiak <megabajt@pld-linux.org>
-Date: Thu Apr 9 19:11:23 2009 +0200
-
- Enable checking for duplicates before adding new pkg to capreq_idx
-
- This change partially fixes lp#270503 on systems where multilib is not
- used (see https://bugs.launchpad.net/poldek/+bug/270503/comments/1) and
- in candidates is the only one package, but specified several times.
-
-diff --git a/capreqidx.c b/capreqidx.c
-index 1af3a5f..7c31825 100644
---- a/capreqidx.c
-+++ b/capreqidx.c
-@@ -92,7 +92,11 @@ int capreq_idx_add(struct capreq_idx *idx, const char *capname,
- if (ent->_size == 1) /* crent_pkgs is NOT allocated */
- capreq_idx_ent_transform_to_array(ent);
-
--#if 0 /* not happens in fact */
-+ /*
-+ * Sometimes, there are duplicates, especially in dotnet-* packages
-+ * which provides multiple versions of one cap. For example dotnet-mono-zeroconf
-+ * provides: mono(Mono.Zeroconf) = 1.0.0.0, mono(Mono.Zeroconf) = 2.0.0.0, etc.
-+ */
- if (idx->flags & CAPREQ_IDX_CAP) { /* check for duplicates */
- register int i;
- for (i=0; i < ent->items; i++) {
-@@ -100,7 +104,6 @@ int capreq_idx_add(struct capreq_idx *idx, const char *capname,
- return 1;
- }
- }
--#endif
-
- if (ent->items == ent->_size) {
- ent->_size *= 2;
+++ /dev/null
---- poldek-0.30-cvs20080820.23/misc.c.old 2008-12-10 10:49:26.000000000 +0100
-+++ poldek-0.30-cvs20080820.23/misc.c 2008-12-10 10:49:56.000000000 +0100
-@@ -646,6 +646,15 @@ static char *cut_country_code (const cha
- return newlang;
- }
-
-+static inline void n_array_push_check_dup(tn_array *langs, char *value)
-+{
-+ int i;
-+
-+ for (i = 0; i < n_array_size(langs); i++)
-+ if (strcmp(n_array_nth(langs, i), value) == 0) return;
-+ n_array_push(langs, n_strdup(value));
-+}
-+
- /*
- * lang_match_avlangs:
- *
-@@ -656,24 +665,33 @@ static char *cut_country_code (const cha
- static inline void lang_match_avlangs(tn_array *avlangs, tn_array *r_langs,
- const char *lang, int *has_C)
- {
-+ char lang_utf8[32];
- char *cut = NULL;
--
-+
- /* first try */
- if (n_array_bsearch(avlangs, lang)) {
- if (strcmp(lang, "C") == 0)
- *has_C = 1;
--
-- n_array_push(r_langs, n_strdup(lang));
-+
-+ n_array_push_check_dup(r_langs, lang);
- }
--
-+ n_snprintf(lang_utf8, sizeof(lang_utf8), "%s.UTF-8", lang);
-+ if (n_array_bsearch(avlangs, lang_utf8))
-+ n_array_push_check_dup(r_langs, lang_utf8);
-+
- /* second try, without country code */
- if ((cut = cut_country_code(lang))) {
- if (n_array_bsearch(avlangs, cut)) {
- if (strcmp(cut, "C") == 0)
- *has_C = 1;
--
-- n_array_push(r_langs, cut);
-+
-+ n_array_push_check_dup(r_langs, cut);
- }
-+ n_snprintf(lang_utf8, sizeof(lang_utf8), "%s.UTF-8", cut);
-+ if (n_array_bsearch(avlangs, lang_utf8))
-+ n_array_push_check_dup(r_langs, lang_utf8);
-+
-+ free(cut);
- }
- }
-
+++ /dev/null
-commit c59795d297536a43c8047dfab2ddea7bef3eb91e
-Author: Bartlomiej Zimon <uzi18@o2.pl>
-Date: Tue Jun 1 05:42:21 2010 +0200
-
- - add --caplookup to install command in interactive mode
-
- Signed-off-by: Bartlomiej Zimon <uzi18@o2.pl>
-
-diff --git a/cli/install.c b/cli/install.c
-index ee83515..19fcb40 100644
---- a/cli/install.c
-+++ b/cli/install.c
-@@ -69,6 +69,7 @@ static int install(struct cmdctx *cmdctx);
- #define OPT_INST_NOFETCH (OPT_GID + 36)
- #define OPT_INST_PARSABLETS (OPT_GID + 37)
- #define OPT_INST_MKDIR (OPT_GID + 38)
-+#define OPT_INST_CAPLOOKUP (OPT_GID + 39)
-
- static struct argp_option options[] = {
- {0, 'I', 0, 0, N_("Install, not upgrade packages"), OPT_GID },
-@@ -138,7 +139,10 @@ N_("Same as --force but applied to PM (rpm) only)"), OPT_GID },
-
- /* hidden, for debugging/testing purposes */
- {"nofetch", OPT_INST_NOFETCH, 0, OPTION_HIDDEN,
-- N_("Do not download packages"), OPT_GID },
-+ N_("Do not download packages"), OPT_GID },
-+
-+{"caplookup", OPT_INST_CAPLOOKUP, 0, 0,
-+N_("Look into package capabilities and files to resolve packages"), OPT_GID },
-
- { 0, 0, 0, 0, 0, 0 },
- };
-@@ -490,6 +494,10 @@ error_t parse_opt(int key, char *arg, struct argp_state *state)
- ts->setop(ts, POLDEK_OP_NOFETCH, 1);
- break;
-
-+ case OPT_INST_CAPLOOKUP:
-+ ts->setop(ts, POLDEK_OP_CAPLOOKUP, 1);
-+ break;
-+
- case OPT_INST_FETCH:
- if (arg) {
- if (!poldek_util_is_rwxdir(arg)) {
+++ /dev/null
-diff -urN poldek-0.30-cvs20080820.23/misc.c poldek-0.30-cvs20080820.23.new/misc.c
---- poldek-0.30-cvs20080820.23/misc.c 2008-07-19 11:52:31.000000000 +0200
-+++ poldek-0.30-cvs20080820.23.new/misc.c 2008-11-23 15:54:42.835970687 +0100
-@@ -626,7 +626,7 @@
- */
- static char *cut_country_code (const char *lang)
- {
-- char *p, *q, *newlang;
-+ char *c, *p, *q, *newlang;
-
- if ((q = strchr(lang, '_')) == NULL)
- return NULL;
-@@ -636,10 +636,12 @@
-
- p = n_strncpy(newlang, lang, q - lang + 1);
-
-- if ((q = strchr(lang, '.')))
-- n_strncpy(p, q, strlen(q) + 1);
-- else if ((q = strchr(lang, '@')))
-- n_strncpy(p, q, strlen(q) + 1);
-+ if ((c = strchr(q, '.')))
-+ n_strncpy(p, c, strlen(c) + 1);
-+ else if ((c = strchr(q, '@')))
-+ n_strncpy(p, c, strlen(c) + 1);
-+
-+ n_assert(strlen(lang) > strlen(newlang));
-
- return newlang;
- }
+++ /dev/null
---- install3/requirements.c~ 2008-11-20 13:23:07.000000000 +0100
-+++ install3/requirements.c 2008-11-20 13:35:39.909464403 +0100
-@@ -613,7 +613,8 @@
- }
- }
-
-- if (!autochoice && !i3_is_user_choosable_equiv(ictx->ts))
-+ /* if we have errors already, don't bug the user with more questions */
-+ if ((!autochoice && !i3_is_user_choosable_equiv(ictx->ts)) || i3_get_nerrors(ictx, I3ERR_CLASS_DEP|I3ERR_CLASS_CNFL))
- return NULL;
-
- tracef(indent, "%s", pkg_id(pkg));
+++ /dev/null
-diff --git a/install3/requirements.c b/install3/requirements.c
-index ea9df61..fee15db 100644
---- a/install3/requirements.c
-+++ b/install3/requirements.c
-@@ -386,7 +392,7 @@ static int process_orphan_req(int indent, struct i3ctx *ictx,
- }
-
- /* try upgrade orphan */
-- if (ts->getop(ts, POLDEK_OP_GREEDY)) {
-+ if (ts->getop(ts, POLDEK_OP_GREEDY) && (tomark == NULL)) {
- if (try_to_upgrade_orphan(indent, ictx, pkg, req, tomark))
- goto l_end;
- }
+++ /dev/null
-diff -urN a/install3/misc.c b/install3/misc.c
---- a/install3/misc.c 2009-11-22 01:39:59.000000000 +0100
-+++ b/install3/misc.c 2009-11-22 01:35:25.795536883 +0100
-@@ -319,7 +319,7 @@
- for (i=0; i < n_array_size(candidates); i++) {
- struct pkg *cand = n_array_nth(candidates, i);
-
-- if (pkg_is_colored_like(cand, marker)) {
-+ if (!pkg_isset_mf(ictx->processed, cand, PKGMARK_BLACK) && pkg_is_colored_like(cand, marker)) {
- if (tmp == NULL)
- tmp = n_array_clone(candidates);
-
-@@ -354,7 +354,7 @@
- struct pkg **best_pkg, tn_array *candidates)
- {
- tn_array *suspkgs = NULL, *tmpkgs;
-- int found = 0;
-+ int found = 0, i;
-
- *best_pkg = NULL;
- found = pkgset_find_match_packages(ictx->ps, pkg, req, &suspkgs, 1);//ictx->strict);
-@@ -391,6 +391,16 @@
-
- //trace(indent, "after removed rmmarked -> %d package(s)",
- // n_array_size(suspkgs));
-+
-+ /* remove marked as BLACK from suspected packages, they have broken deps */
-+ for (i = 0; i < n_array_size(suspkgs); i++) {
-+ struct pkg *suspkg = n_array_nth(suspkgs, i);
-+
-+ if (pkg_isset_mf(ictx->processed, suspkg, PKGMARK_BLACK)) {
-+ trace(indent, "- marked as BLACK %s", pkg_id(suspkg));
-+ n_array_remove_nth(suspkgs, i--);
-+ }
-+ }
-
- if (n_array_size(suspkgs) == 0) {
- found = 0;
-diff -urN a/install3/process.c b/install3/process.c
---- a/install3/process.c 2009-11-22 01:39:38.000000000 +0100
-+++ b/install3/process.c 2009-11-22 19:41:42.862076125 +0100
-@@ -77,6 +77,11 @@
- i3_forget_error(ictx, pkg);
- }
- }
-+
-+ /* this package may be used again and we have to process it (do not
-+ * stop on the first condition in i3_process_package()) to generate
-+ * new ->obsoletedby as we removed them here. */
-+ pkg_clr_mf(ictx->processed, i3pkg->pkg, PKGMARK_GRAY);
-
- if (i3pkg->markedby) {
- indent = inc_indent(indent);
+++ /dev/null
-diff --git a/install3/requirements.c b/install3/requirements.c
-index 406b37e..0b5a654 100644
---- a/install3/requirements.c
-+++ b/install3/requirements.c
-@@ -696,11 +696,9 @@ int i3_process_pkg_requirements(int indent, struct i3ctx *ictx,
- struct pkg *pkg = i3pkg->pkg;
- struct pkg_req_iter *it = NULL;
- const struct capreq *req = NULL;
-- tn_array *suggests = NULL;
- unsigned itflags = PKG_ITER_REQIN;
- int nerrors = 0, backtrack = 0;
-
--
- pkg = i3pkg->pkg;
- n_assert(pkg);
- n_assert(pkg->reqs);
-@@ -710,22 +708,10 @@ int i3_process_pkg_requirements(int indent, struct i3ctx *ictx,
- return 0;
-
- tracef(indent, "%s as NEW", pkg_id(pkg));
--
-- if (ts->getop(ts, POLDEK_OP_SUGGESTS)) {
-- suggests = with_suggests(indent + 2, ictx, pkg);
-- if (suggests)
-- itflags |= PKG_ITER_REQSUG;
-- }
-
- it = pkg_req_iter_new(pkg, itflags);
- while ((req = pkg_req_iter_get(it))) {
-- unsigned t;
- int rc;
--
-- /* install only reasonable/choosen suggests */
-- t = pkg_req_iter_current_req_type(it);
-- if (t == PKG_ITER_REQSUG && !suggests_contains(suggests, req))
-- continue;
-
- if ((rc = process_req(indent, ictx, i3pkg, req)) <= 0) {
- nerrors++;
-@@ -738,7 +724,33 @@ int i3_process_pkg_requirements(int indent, struct i3ctx *ictx,
- }
-
- pkg_req_iter_free(it);
-- n_array_cfree(&suggests);
-+
-+ /* check for Suggests after processing Requires. Prevent cases where poldek
-+ asks for suggested package, even though it is required. */
-+ if (ts->getop(ts, POLDEK_OP_SUGGESTS) && nerrors == 0) {
-+ tn_array *suggests = NULL;
-+ int i;
-+
-+ suggests = with_suggests(indent + 2, ictx, pkg);
-+
-+ if (suggests) {
-+ for (i = 0; i < n_array_size(suggests); i++) {
-+ int rc;
-+
-+ req = n_array_nth(suggests, i);
-+
-+ if ((rc = process_req(indent, ictx, i3pkg, req)) <= 0) {
-+ nerrors++;
-+ if (rc < 0) {
-+ backtrack = 1;
-+ if (i3pkg->flags & I3PKG_BACKTRACKABLE)
-+ break;
-+ }
-+ }
-+ }
-+ }
-+ n_array_cfree(&suggests);
-+ }
-
- if (backtrack && (i3pkg->flags & I3PKG_CROSSROAD)) {
- logn(LOGNOTICE, "Retrying to process %s", pkg_id(i3pkg->pkg));
+++ /dev/null
-Index: libpoldek.sym
-===================================================================
-RCS file: /cvsroot/poldek/poldek/libpoldek.sym,v
-retrieving revision 1.37
-retrieving revision 1.38
-diff -u -r1.37 -r1.38
---- libpoldek.sym 25 May 2008 09:25:31 -0000 1.37
-+++ libpoldek.sym 2 Jan 2009 17:28:42 -0000 1.38
-@@ -180,6 +180,7 @@
- pkguinf_set
- pm_dbmtime
- pm_dbpath
-+pm_dbrec_nevr
- pm_verify_signature
- poldek_BANNER
- poldek_BUG_MAILADDR
+++ /dev/null
-diff -ruN poldek-0.30-cvs20080604.13./install3/iset.c poldek-0.30-cvs20080604.13/install3/iset.c
---- poldek-0.30-cvs20080604.13./install3/iset.c 2008-02-03 20:07:42.000000000 +0100
-+++ poldek-0.30-cvs20080604.13/install3/iset.c 2008-07-17 23:13:25.449260760 +0200
-@@ -47,7 +47,7 @@
- pkg_set_mf(iset->pms, pkg, mflag);
- }
-
--inline int iset_ismarkedf(struct iset *iset, const struct pkg *pkg,
-+int iset_ismarkedf(struct iset *iset, const struct pkg *pkg,
- unsigned mflag)
- {
- return pkg_isset_mf(iset->pms, pkg, mflag);
+++ /dev/null
---- install3/misc.c~ 2008-08-18 11:26:41.000000000 +0200
-+++ install3/misc.c 2008-11-19 15:47:48.471454682 +0100
-@@ -365,7 +365,7 @@
-
- /* possible when the same package exists in both available
- and already installed set */
-- if (i3_is_marked_for_removal(ictx, suspkg)) {
-+ if (i3_is_marked_for_removal(ictx, suspkg) && !i3_is_marked(ictx, suspkg)) {
- pkg_free(suspkg);
- continue;
- }
+++ /dev/null
---- configure.in.old 2010-06-03 04:15:33.000000000 +0200
-+++ configure.in 2010-06-03 05:20:29.000000000 +0200
-@@ -421,7 +421,7 @@
- if test -n "$TRURL_DIR"; then
- AC_MSG_CHECKING(for local trurlib copy in $TRURL_DIR)
- AC_MSG_RESULT([yes])
-- TRURL_INCLUDE="-I\$(top_srcdir)/$TRURL_DIR/include"
-+ TRURL_INCLUDE="-I\$(top_srcdir)/$TRURL_DIR/include -I./$TRURL_DIR/include"
- TRURL_LDFLAG="-L\$(top_srcdir)/$TRURL_DIR/"
- LDFLAGS="$LDFLAGS $TRURL_LDFLAG"
- CPPFLAGS="$CPPFLAGS $TRURL_INCLUDE"
+++ /dev/null
-with ls -lu (llu), last column name (size) did not fit in one line.
-
---- poldek-0.30-cvs20080604.13/cli/ls.c~ 2008-06-03 21:29:38.000000000 +0200
-+++ poldek-0.30-cvs20080604.13/cli/ls.c 2008-08-04 21:10:40.375270267 +0200
-@@ -427,7 +427,7 @@
- } else {
- snprintf(fmt_hdr, sizeof(fmt_hdr), "%%-%ds%%-%ds %%-%ds%%%ds\n",
- (term_width/2) - 1, (term_width/6) - 1,
-- (term_width/6) - 1, (term_width/5) - 1);
-+ (term_width/6) - 1, (term_width/6) - 1);
-
- snprintf(fmt_pkg, sizeof(fmt_pkg), "%%-%ds%%-%ds %%-%ds %%%ds\n",
- (term_width/2) - 1, (term_width/6) - 1,
+++ /dev/null
-commit 4b027294335c0672311f021f2dc76edaab049b11
-Author: Marcin Banasiak <marcin.banasiak@gmail.com>
-Date: Sun Dec 13 20:50:11 2009 +0100
-
- Support for query format in ls command.
-
- Syntax of the queryfmt is almost the same as in rpm except query
- expressions which are not (yet) supported.
-
- To see supported tags type:
- ls --querytags
-
-diff --git a/cli/Makefile.am b/cli/Makefile.am
-index 53fcdfd..4a32e01 100644
---- a/cli/Makefile.am
-+++ b/cli/Makefile.am
-@@ -28,6 +28,7 @@ libpoclidek_la_SOURCES = \
- op_split.c \
- op_verify.c \
- ls.c \
-+ ls_queryfmt.c ls_queryfmt.h \
- install.c \
- uninstall.c \
- desc.c \
-diff --git a/cli/ls_queryfmt.c b/cli/ls_queryfmt.c
-new file mode 100644
-index 0000000..1a0c02f
---- /dev/null
-+++ b/cli/ls_queryfmt.c
-@@ -0,0 +1,1096 @@
-+/*
-+ Copyright (C) 2009 Marcin Banasiak <megabajt@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., 675 Mass Ave, Cambridge, MA 02139, USA.
-+*/
-+
-+#ifdef HAVE_CONFIG_H
-+# include "config.h"
-+#endif
-+
-+/* for asprintf() from stdio.h */
-+#define _GNU_SOURCE
-+
-+/* FIXME: nbuf.h should include stdint.h */
-+#include <stdint.h>
-+
-+#include <sys/stat.h>
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <string.h>
-+#include <time.h>
-+
-+#include <trurl/trurl.h>
-+
-+#include "capreq.h"
-+#include "i18n.h"
-+#include "log.h"
-+#include "ls_queryfmt.h"
-+#include "pkgu.h"
-+#include "pkgfl.h"
-+
-+#define n_strcase_eq(s, p) (strcasecmp(s, p) == 0)
-+
-+static const char *invalid_format = N_("invalid format:");
-+
-+enum LsqfParseMode {
-+ LSQF_PARSE_NORMAL = 0,
-+ LSQF_PARSE_ARRAY
-+};
-+
-+/* Tags have to be in alphabetical order. */
-+enum {
-+ LSQF_TAG_UNKNOWN = -1,
-+
-+ LSQF_TAG_ARCH = 0,
-+ LSQF_TAG_BASENAMES,
-+ LSQF_TAG_BUILDHOST,
-+ LSQF_TAG_BUILDTIME,
-+ LSQF_TAG_CONFLICTFLAGS,
-+ LSQF_TAG_CONFLICTS,
-+ LSQF_TAG_CONFLICTVERSION,
-+ LSQF_TAG_DESCRIPTION,
-+ LSQF_TAG_DIRNAMES,
-+ LSQF_TAG_EPOCH,
-+ LSQF_TAG_FILELINKTOS,
-+ LSQF_TAG_FILEMODES,
-+ LSQF_TAG_FILENAMES,
-+ LSQF_TAG_FILESIZES,
-+ LSQF_TAG_GROUP,
-+ LSQF_TAG_LICENSE,
-+ LSQF_TAG_NAME,
-+ LSQF_TAG_NVRA,
-+ LSQF_TAG_OBSOLETEFLAGS,
-+ LSQF_TAG_OBSOLETES,
-+ LSQF_TAG_OBSOLETEVERSION,
-+ LSQF_TAG_PACKAGECOLOR,
-+ LSQF_TAG_PROVIDEFLAGS,
-+ LSQF_TAG_PROVIDES,
-+ LSQF_TAG_PROVIDEVERSION,
-+ LSQF_TAG_RELEASE,
-+ LSQF_TAG_REQUIREFLAGS,
-+ LSQF_TAG_REQUIRES,
-+ LSQF_TAG_REQUIREVERSION,
-+ LSQF_TAG_SIZE,
-+ LSQF_TAG_SOURCERPM,
-+ LSQF_TAG_SUGGESTSFLAGS,
-+ LSQF_TAG_SUGGESTS,
-+ LSQF_TAG_SUGGESTSVERSION,
-+ LSQF_TAG_SUMMARY,
-+ LSQF_TAG_URL,
-+ LSQF_TAG_VENDOR,
-+ LSQF_TAG_VERSION,
-+
-+ LSQF_N_TAGS
-+};
-+
-+enum {
-+ LSQF_TAG_OUTFMTFN_NONE = 0,
-+
-+ LSQF_TAG_OUTFMTFN_DATE,
-+ LSQF_TAG_OUTFMTFN_DAY,
-+ LSQF_TAG_OUTFMTFN_DEPFLAGS
-+};
-+
-+struct lsqf_tags {
-+ int tagid;
-+ int is_array : 1;
-+ int need_uinf : 1;
-+ int need_flist : 1;
-+ const char *tagname[4];
-+};
-+
-+/*
-+ * LSQF_TAG_* have to be added in the same sequence as in enumeration
-+ * (LSQF_TAG_ value is an index in lsqf_tags[] array).
-+ */
-+static const struct lsqf_tags lsqf_tags[] = {
-+ { LSQF_TAG_ARCH, 0, 0, 0, { "ARCH", NULL } },
-+ { LSQF_TAG_BASENAMES, 1, 0, 1, { "BASENAMES", NULL } },
-+ { LSQF_TAG_BUILDHOST, 0, 1, 0, { "BUILDHOST", NULL } },
-+ { LSQF_TAG_BUILDTIME, 0, 0, 0, { "BUILDTIME", NULL } },
-+ { LSQF_TAG_CONFLICTFLAGS, 1, 0, 0, { "CONFLICTFLAGS", NULL } },
-+ { LSQF_TAG_CONFLICTS, 1, 0, 0, { "C", "CONFLICTNAME", "CONFLICTS", NULL } },
-+ { LSQF_TAG_CONFLICTVERSION, 1, 0, 0, { "CONFLICTVERSION", NULL } },
-+ { LSQF_TAG_DESCRIPTION, 0, 1, 0, { "DESCRIPTION", NULL } },
-+ { LSQF_TAG_DIRNAMES, 1, 0, 1, { "DIRNAMES", NULL } },
-+ { LSQF_TAG_EPOCH, 0, 0, 0, { "E", "EPOCH", NULL } },
-+ { LSQF_TAG_FILELINKTOS, 1, 0, 1, { "FILELINKTOS", NULL } },
-+ { LSQF_TAG_FILEMODES, 1, 0, 1, { "FILEMODES", NULL } },
-+ { LSQF_TAG_FILENAMES, 1, 0, 1, { "FILENAMES", NULL } },
-+ { LSQF_TAG_FILESIZES, 1, 0, 1, { "FILESIZES", NULL } },
-+ { LSQF_TAG_GROUP, 0, 0, 0, { "GROUP", NULL } },
-+ { LSQF_TAG_LICENSE, 0, 1, 0, { "LICENSE", NULL } },
-+ { LSQF_TAG_NAME, 0, 0, 0, { "N", "NAME", NULL } },
-+ { LSQF_TAG_NVRA, 0, 0, 0, { "NVRA", NULL } },
-+ { LSQF_TAG_OBSOLETEFLAGS, 1, 0, 0, { "OBSOLETEFLAGS", NULL } },
-+ { LSQF_TAG_OBSOLETES, 1, 0, 0, { "O", "OBSOLETENAME", "OBSOLETES", NULL } },
-+ { LSQF_TAG_OBSOLETEVERSION, 1, 0, 0, { "OBSOLETEVERSION", NULL } },
-+ { LSQF_TAG_PACKAGECOLOR, 0, 0, 0, { "PACKAGECOLOR", NULL } },
-+ { LSQF_TAG_PROVIDEFLAGS, 1, 0, 0, { "PROVIDEFLAGS", NULL } },
-+ { LSQF_TAG_PROVIDES, 1, 0, 0, { "P", "PROVIDENAME", "PROVIDES", NULL } },
-+ { LSQF_TAG_PROVIDEVERSION, 1, 0, 0, { "PROVIDEVERSION", NULL } },
-+ { LSQF_TAG_RELEASE, 0, 0, 0, { "R", "RELEASE", NULL } },
-+ { LSQF_TAG_REQUIREFLAGS, 1, 0, 0, { "REQUIREFLAGS", NULL } },
-+ { LSQF_TAG_REQUIRES, 1, 0, 0, { "REQUIRENAME", "REQUIRES", NULL } },
-+ { LSQF_TAG_REQUIREVERSION, 1, 0, 0, { "REQUIREVERSION", NULL } },
-+ { LSQF_TAG_SIZE, 0, 0, 0, { "SIZE", NULL } },
-+ { LSQF_TAG_SOURCERPM, 0, 0, 0, { "SOURCERPM", NULL } },
-+ { LSQF_TAG_SUGGESTSFLAGS, 1, 0, 0, { "SUGGESTSFLAGS", NULL } },
-+ { LSQF_TAG_SUGGESTS, 1, 0, 0, { "SUGGESTS", "SUGGESTSNAME", NULL } },
-+ { LSQF_TAG_SUGGESTSVERSION, 1, 0, 0, { "SUGGESTSVERSION", NULL } },
-+ { LSQF_TAG_SUMMARY, 0, 1, 0, { "SUMMARY", NULL } },
-+ { LSQF_TAG_URL, 0, 1, 0, { "URL", NULL } },
-+ { LSQF_TAG_VENDOR, 0, 1, 0, { "VENDOR", NULL } },
-+ { LSQF_TAG_VERSION, 0, 0, 0, { "V", "VERSION", NULL } },
-+ { LSQF_N_TAGS, 0, 0, 0, { NULL } }
-+};
-+
-+struct lsqf_pkgdata {
-+ const struct pkg *pkg;
-+ struct pkgflist *flist;
-+ struct pkguinf *uinf;
-+};
-+
-+static struct lsqf_pkgdata *lsqf_pkgdata_new(const struct pkg *pkg)
-+{
-+ struct lsqf_pkgdata *pkgdata = NULL;
-+
-+ pkgdata = n_malloc(sizeof(struct lsqf_pkgdata));
-+
-+ if (pkgdata) {
-+ pkgdata->pkg = pkg;
-+ pkgdata->flist = NULL;
-+ pkgdata->uinf = NULL;
-+ }
-+
-+ return pkgdata;
-+}
-+
-+static struct pkgflist *lsqf_pkgdata_flist(struct lsqf_pkgdata *pkgdata)
-+{
-+ if (pkgdata->flist == NULL)
-+ pkgdata->flist = pkg_get_flist(pkgdata->pkg);
-+
-+ return pkgdata->flist;
-+}
-+
-+static struct pkguinf *lsqf_pkgdata_uinf(struct lsqf_pkgdata *pkgdata)
-+{
-+ if (pkgdata->uinf == NULL)
-+ pkgdata->uinf = pkg_uinf(pkgdata->pkg);
-+
-+ return pkgdata->uinf;
-+}
-+
-+static void lsqf_pkgdata_free(struct lsqf_pkgdata *pkgdata)
-+{
-+ if (pkgdata) {
-+ if (pkgdata->flist)
-+ pkgflist_free(pkgdata->flist);
-+
-+ if (pkgdata->uinf)
-+ pkguinf_free(pkgdata->uinf);
-+
-+ n_free(pkgdata);
-+ }
-+}
-+
-+static int get_tagid_by_name(char *tag)
-+{
-+ if (tag) {
-+ unsigned int i, j;
-+
-+ for (i = 0; i < LSQF_N_TAGS; i++) {
-+ for (j = 0; lsqf_tags[i].tagname[j]; j++) {
-+ if (n_strcase_eq(tag, lsqf_tags[i].tagname[j])) {
-+ return lsqf_tags[i].tagid;
-+ }
-+ }
-+ }
-+ }
-+
-+ return LSQF_TAG_UNKNOWN;
-+}
-+
-+static int get_outfmtfnid_by_name(char *outfmtfn)
-+{
-+ if (outfmtfn && *outfmtfn) {
-+ if (n_str_eq(outfmtfn, "date"))
-+ return LSQF_TAG_OUTFMTFN_DATE;
-+ if (n_str_eq(outfmtfn, "day"))
-+ return LSQF_TAG_OUTFMTFN_DAY;
-+ if (n_str_eq(outfmtfn, "depflags"))
-+ return LSQF_TAG_OUTFMTFN_DEPFLAGS;
-+ }
-+
-+ return LSQF_TAG_OUTFMTFN_NONE;
-+}
-+
-+/* TODO: move to capreq.c */
-+static int capreq_snprintf_evr(char *str, size_t size, const struct capreq *cr)
-+{
-+ int n = 0;
-+
-+ n_assert(size > 0);
-+
-+ if (capreq_has_epoch(cr))
-+ n += n_snprintf(&str[n], size - n, "%d:", capreq_epoch(cr));
-+
-+ if (capreq_has_ver(cr))
-+ n += n_snprintf(&str[n], size - n, "%s", capreq_ver(cr));
-+
-+ if (capreq_has_rel(cr)) {
-+ n_assert(capreq_has_ver(cr));
-+
-+ n += n_snprintf(&str[n], size - n, "-%s", capreq_rel(cr));
-+ }
-+
-+ return n;
-+}
-+
-+static char *format_date(int outfmtfnid, uint32_t time)
-+{
-+ char *buf = NULL, datestr[32];;
-+
-+ if (outfmtfnid == LSQF_TAG_OUTFMTFN_DATE) {
-+ strftime(datestr, sizeof(datestr), "%c", gmtime((time_t *)&time));
-+ asprintf(&buf, "%s", datestr);
-+ } else if (outfmtfnid == LSQF_TAG_OUTFMTFN_DAY) {
-+ strftime(datestr, sizeof(datestr), "%a %b %d %Y", gmtime((time_t *)&time));
-+ asprintf(&buf, "%s", datestr);
-+ } else {
-+ asprintf(&buf, "%u", time);
-+ }
-+
-+ return buf;
-+}
-+
-+static char *format_flags(int outfmtfnid, struct capreq *cr)
-+{
-+ char *buf = NULL;
-+
-+ if (outfmtfnid == LSQF_TAG_OUTFMTFN_DEPFLAGS) {
-+ char relstr[3], *p;
-+
-+ p = relstr;
-+ *p = '\0';
-+
-+ if (cr->cr_relflags & REL_LT)
-+ *p++ = '<';
-+ else if (cr->cr_relflags & REL_GT)
-+ *p++ = '>';
-+
-+ if (cr->cr_relflags & REL_EQ)
-+ *p++ = '=';
-+
-+ *p = '\0';
-+
-+ asprintf(&buf, " %s ", relstr);
-+ } else {
-+ asprintf(&buf, "%u", cr->cr_relflags);
-+ }
-+
-+ return buf;
-+}
-+
-+static char *get_str_by_tagid(const struct lsqf_ent *ent, struct lsqf_pkgdata *pkgdata, unsigned int num)
-+{
-+ const struct pkg *pkg = pkgdata->pkg;
-+ struct capreq *c = NULL;
-+ char *buf = NULL, evr[32];
-+ unsigned int i;
-+
-+ if (lsqf_tags[ent->tag.id].need_uinf) {
-+ struct pkguinf *pkgu = lsqf_pkgdata_uinf(pkgdata);
-+ const char *str = NULL;
-+
-+ switch (ent->tag.id) {
-+ case LSQF_TAG_BUILDHOST:
-+ str = pkguinf_get(pkgu, PKGUINF_BUILDHOST);
-+ break;
-+
-+ case LSQF_TAG_DESCRIPTION:
-+ str = pkguinf_get(pkgu, PKGUINF_DESCRIPTION);
-+ break;
-+
-+ case LSQF_TAG_LICENSE:
-+ str = pkguinf_get(pkgu, PKGUINF_LICENSE);
-+ break;
-+
-+ case LSQF_TAG_SUMMARY:
-+ str = pkguinf_get(pkgu, PKGUINF_SUMMARY);
-+ break;
-+
-+ case LSQF_TAG_URL:
-+ str = pkguinf_get(pkgu, PKGUINF_URL);
-+ break;
-+
-+ case LSQF_TAG_VENDOR:
-+ str = pkguinf_get(pkgu, PKGUINF_VENDOR);
-+ break;
-+
-+ default:
-+ n_assert(0);
-+ }
-+
-+ if (str)
-+ buf = n_strdup(str);
-+ else
-+ buf = n_strdup("(none)");
-+
-+ } else if (lsqf_tags[ent->tag.id].need_flist) {
-+ struct pkgflist *flist = lsqf_pkgdata_flist(pkgdata);
-+ struct pkgfl_ent *flent;
-+
-+ if (flist) {
-+ switch (ent->tag.id) {
-+ case LSQF_TAG_BASENAMES:
-+ case LSQF_TAG_FILELINKTOS:
-+ case LSQF_TAG_FILEMODES:
-+ case LSQF_TAG_FILENAMES:
-+ case LSQF_TAG_FILESIZES:
-+ for (i = 0; i < n_tuple_size(flist->fl); i++) {
-+ flent = n_tuple_nth(flist->fl, i);
-+
-+ if (flent->items <= num)
-+ num -= flent->items;
-+ else
-+ break;
-+ }
-+
-+ if (ent->tag.id == LSQF_TAG_BASENAMES)
-+ buf = n_strdup(flent->files[num]->basename);
-+ else if (ent->tag.id == LSQF_TAG_FILEMODES)
-+ asprintf(&buf, "%u", flent->files[num]->mode);
-+ else if (ent->tag.id == LSQF_TAG_FILENAMES) {
-+ if (*flent->dirname == '/')
-+ asprintf(&buf, "%s%s", flent->dirname, flent->files[num]->basename);
-+ else
-+ asprintf(&buf, "/%s%s%s", flent->dirname,
-+ *flent->files[num]->basename ? "/" : "",
-+ flent->files[num]->basename);
-+ } else if (ent->tag.id == LSQF_TAG_FILESIZES)
-+ asprintf(&buf, "%u", flent->files[num]->size);
-+ else
-+ if (S_ISLNK(flent->files[num]->mode))
-+ buf = n_strdup(flent->files[num]->basename + strlen(flent->files[num]->basename) + 1);
-+
-+ break;
-+
-+ case LSQF_TAG_DIRNAMES:
-+ flent = n_tuple_nth(flist->fl, num);
-+
-+ asprintf(&buf, "%s%s", *flent->dirname == '/' ? "" : "/",
-+ flent->dirname);
-+ break;
-+
-+ default:
-+ n_assert(0);
-+ }
-+ }
-+ } else {
-+ switch (ent->tag.id) {
-+ case LSQF_TAG_ARCH:
-+ buf = n_strdup(pkg_arch(pkg));
-+ break;
-+
-+ case LSQF_TAG_BUILDTIME:
-+ buf = format_date(ent->tag.outfmtfnid, pkg->btime);
-+ break;
-+
-+ case LSQF_TAG_CONFLICTFLAGS:
-+ case LSQF_TAG_CONFLICTS:
-+ case LSQF_TAG_CONFLICTVERSION:
-+ case LSQF_TAG_OBSOLETEFLAGS:
-+ case LSQF_TAG_OBSOLETES:
-+ case LSQF_TAG_OBSOLETEVERSION:
-+ {
-+ unsigned int n = 0;
-+
-+ for (i = 0; i < n_array_size(pkg->cnfls); i++) {
-+ struct capreq *cr = n_array_nth(pkg->cnfls, i);
-+
-+ if (ent->tag.id == LSQF_TAG_CONFLICTS || ent->tag.id == LSQF_TAG_CONFLICTFLAGS) {
-+ if (!capreq_is_obsl(cr)) {
-+ if (n == num) {
-+ c = cr;
-+ break;
-+ }
-+
-+ n++;
-+ }
-+ } else {
-+ if (capreq_is_obsl(cr)) {
-+ if (n == num) {
-+ c = cr;
-+ break;
-+ }
-+
-+ n++;
-+ }
-+ }
-+ }
-+
-+ if (c) {
-+ if (ent->tag.id == LSQF_TAG_CONFLICTS || ent->tag.id == LSQF_TAG_OBSOLETES)
-+ buf = n_strdup(capreq_name(c));
-+ else if (ent->tag.id == LSQF_TAG_CONFLICTFLAGS || ent->tag.id == LSQF_TAG_OBSOLETEFLAGS)
-+ buf = format_flags(ent->tag.outfmtfnid, c);
-+ else if (ent->tag.id == LSQF_TAG_CONFLICTVERSION || ent->tag.id == LSQF_TAG_OBSOLETEVERSION)
-+ if (capreq_snprintf_evr(evr, sizeof(evr), c) > 0)
-+ buf = n_strdup(evr);
-+
-+ }
-+ break;
-+ }
-+
-+ case LSQF_TAG_EPOCH:
-+ asprintf(&buf, "%d", pkg->epoch);
-+ break;
-+
-+ case LSQF_TAG_GROUP:
-+ buf = n_strdup(pkg_group(pkg));
-+ break;
-+
-+ case LSQF_TAG_NAME:
-+ buf = n_strdup(pkg->name);
-+ break;
-+
-+ case LSQF_TAG_NVRA:
-+ buf = n_strdup(pkg_id(pkg));
-+ break;
-+
-+ case LSQF_TAG_PACKAGECOLOR:
-+ asprintf(&buf, "%d", pkg->color);
-+ break;
-+
-+ case LSQF_TAG_PROVIDEFLAGS:
-+ buf = format_flags(ent->tag.outfmtfnid, n_array_nth(pkg->caps, num));
-+ break;
-+
-+ case LSQF_TAG_PROVIDES:
-+ c = n_array_nth(pkg->caps, num);
-+ buf = n_strdup(capreq_name(c));
-+ break;
-+
-+ case LSQF_TAG_PROVIDEVERSION:
-+ c = n_array_nth(pkg->caps, num);
-+
-+ if (capreq_snprintf_evr(evr, sizeof(evr), c) > 0)
-+ buf = n_strdup(evr);
-+
-+ break;
-+
-+ case LSQF_TAG_RELEASE:
-+ buf = n_strdup(pkg->rel);
-+ break;
-+
-+ case LSQF_TAG_REQUIREFLAGS:
-+ buf = format_flags(ent->tag.outfmtfnid, n_array_nth(pkg->reqs, num));
-+ break;
-+
-+ case LSQF_TAG_REQUIRES:
-+ c = n_array_nth(pkg->reqs, num);
-+
-+ if (capreq_is_rpmlib(c))
-+ asprintf(&buf, "rpmlib(%s)", capreq_name(c));
-+ else
-+ buf = n_strdup(capreq_name(c));
-+
-+ break;
-+
-+ case LSQF_TAG_REQUIREVERSION:
-+ c = n_array_nth(pkg->reqs, num);
-+
-+ if (capreq_snprintf_evr(evr, sizeof(evr), c) > 0)
-+ buf = n_strdup(evr);
-+
-+ break;
-+
-+ case LSQF_TAG_VERSION:
-+ buf = n_strdup(pkg->ver);
-+ break;
-+
-+ case LSQF_TAG_SIZE:
-+ asprintf(&buf, "%u", pkg->size);
-+ break;
-+
-+ case LSQF_TAG_SOURCERPM:
-+ buf = n_strdup(pkg_srcfilename_s(pkg));
-+ break;
-+
-+ case LSQF_TAG_SUGGESTSFLAGS:
-+ buf = format_flags(ent->tag.outfmtfnid, n_array_nth(pkg->sugs, num));
-+ break;
-+
-+ case LSQF_TAG_SUGGESTS:
-+ c = n_array_nth(pkg->sugs, num);
-+ buf = n_strdup(capreq_name(c));
-+ break;
-+
-+ case LSQF_TAG_SUGGESTSVERSION:
-+ c = n_array_nth(pkg->sugs, num);
-+
-+ if (capreq_snprintf_evr(evr, sizeof(evr), c) > 0)
-+ buf = n_strdup(evr);
-+
-+ break;
-+
-+ default:
-+ n_assert(0);
-+ }
-+ }
-+
-+ return buf;
-+}
-+
-+static char get_escaped_char(char zn)
-+{
-+ switch (zn) {
-+ case 'a': return '\a';
-+ case 'b': return '\b';
-+ case 'f': return '\f';
-+ case 'n': return '\n';
-+ case 'r': return '\r';
-+ case 't': return '\t';
-+ case 'v': return '\v';
-+ default: return zn;
-+ }
-+}
-+
-+static struct lsqf_ent *lsqf_ent_new(int type)
-+{
-+ struct lsqf_ent *ent = NULL;
-+
-+ ent = n_malloc(sizeof(struct lsqf_ent));
-+
-+ if (ent) {
-+ ent->type = type;
-+
-+ switch (type) {
-+ case LSQF_ENT_TYPE_TAG:
-+ ent->tag.id = 0;
-+ ent->tag.iterate = 0;
-+ ent->tag.countArray = 0;
-+ ent->tag.pad = 0;
-+ break;
-+
-+ case LSQF_ENT_TYPE_STRING:
-+ ent->string = NULL;
-+ break;
-+
-+ case LSQF_ENT_TYPE_ARRAY:
-+ ent->array = lsqf_ent_array_new();
-+ break;
-+
-+ default:
-+ n_assert(0);
-+ }
-+ }
-+
-+ return ent;
-+}
-+
-+static void lsqf_ent_free(struct lsqf_ent *ent)
-+{
-+ if (ent) {
-+ switch (ent->type) {
-+ case LSQF_ENT_TYPE_TAG:
-+ break;
-+
-+ case LSQF_ENT_TYPE_STRING:
-+ if (ent->string)
-+ n_free(ent->string);
-+
-+ break;
-+
-+ case LSQF_ENT_TYPE_ARRAY:
-+ lsqf_ent_array_free(ent->array);
-+ break;
-+ }
-+
-+ n_free(ent);
-+ }
-+}
-+
-+struct lsqf_ent_array *lsqf_ent_array_new(void)
-+{
-+ struct lsqf_ent_array *array = NULL;
-+
-+ array = n_malloc(sizeof(struct lsqf_ent_array));
-+
-+ if (array) {
-+ array->ents = NULL;
-+ array->items = 0;
-+ }
-+
-+ return array;
-+}
-+
-+void lsqf_ent_array_free(struct lsqf_ent_array *array)
-+{
-+ unsigned int i;
-+
-+ if (array) {
-+ for (i = 0; i < array->items; i++) {
-+ struct lsqf_ent *ent = array->ents[i];
-+
-+ lsqf_ent_free(ent);
-+ }
-+
-+ if (array->ents)
-+ n_free(array->ents);
-+
-+ n_free(array);
-+ }
-+}
-+
-+static void lsqf_ent_array_add_ent(struct lsqf_ent_array *array, struct lsqf_ent *ent)
-+{
-+ array->ents = n_realloc(array->ents, (array->items + 1) * sizeof(struct lsqf_ent *));
-+
-+ if (array->ents) {
-+ array->ents[array->items] = ent;
-+
-+ array->items++;
-+ }
-+}
-+
-+static void lsqf_ent_array_add_ent_string(struct lsqf_ent_array *array, tn_buf *nbuf)
-+{
-+ struct lsqf_ent *ent = NULL;
-+
-+ if (n_buf_size(nbuf) > 0) {
-+ n_buf_putc(nbuf, '\0');
-+
-+ if ((ent = lsqf_ent_new(LSQF_ENT_TYPE_STRING))) {
-+ ent->string = n_strdup(n_buf_ptr(nbuf));
-+
-+ lsqf_ent_array_add_ent(array, ent);
-+
-+ n_buf_clean(nbuf);
-+ }
-+ }
-+}
-+
-+/**
-+ * do_parse:
-+ *
-+ * Returns: 1 on error.
-+ **/
-+static int do_parse(struct lsqf_ent_array *array, char *fmt, char **endfmt, enum LsqfParseMode mode)
-+{
-+ struct lsqf_ent *ent;
-+ tn_buf *nbuf = NULL;
-+ int done = 0, error = 0;
-+ char *end;
-+
-+ if (fmt == NULL)
-+ return 1;
-+
-+ nbuf = n_buf_new(8);
-+
-+ while (*fmt && !done && !error) {
-+ switch (*fmt) {
-+ case '%':
-+ {
-+ char *p, *outfmtfn;
-+ int tagid, pad, countArray = 0, iterate = 0;
-+
-+ fmt++;
-+
-+ /* catch %% */
-+ if (*fmt == '%') {
-+ n_buf_putc(nbuf, '%');
-+ break;
-+ }
-+
-+ pad = strtoul(fmt, &p, 10);
-+
-+ fmt = p;
-+
-+ if (*fmt != '{') {
-+ logn(LOGERR, _("%s missing { after %%"), invalid_format);
-+ error = 1;
-+ break;
-+ }
-+
-+ fmt++;
-+
-+ if (*fmt == '#') {
-+ countArray = 1;
-+ fmt++;
-+ } else if (*fmt == '=') {
-+ iterate = 1;
-+ fmt++;
-+ }
-+
-+ if ((p = strchr(fmt, '}')) == NULL) {
-+ logn(LOGERR, _("%s missing } after %%{"), invalid_format);
-+ error = 1;
-+ break;
-+ }
-+
-+ *p = '\0';
-+
-+ if (*fmt == '\0') {
-+ logn(LOGERR, _("%s empty tag name"), invalid_format);
-+ error = 1;
-+ break;
-+ }
-+
-+ /* check if another output format is requested */
-+ if ((outfmtfn = strchr(fmt, ':')) != NULL) {
-+ *outfmtfn = '\0';
-+ outfmtfn++;
-+ }
-+
-+ if ((tagid = get_tagid_by_name(fmt)) == LSQF_TAG_UNKNOWN) {
-+ logn(LOGERR, _("%s unknown tag: \'%s\'"), invalid_format, fmt);
-+ error = 1;
-+ break;
-+ }
-+
-+ /* create new ent with a string that is currently stored in nbuf */
-+ lsqf_ent_array_add_ent_string(array, nbuf);
-+
-+ ent = lsqf_ent_new(LSQF_ENT_TYPE_TAG);
-+ ent->tag.id = tagid;
-+ ent->tag.pad = pad;
-+ ent->tag.countArray = countArray;
-+ ent->tag.iterate = iterate;
-+ ent->tag.outfmtfnid = get_outfmtfnid_by_name(outfmtfn);
-+
-+ lsqf_ent_array_add_ent(array, ent);
-+
-+ fmt = p;
-+
-+ break;
-+ }
-+ case '[':
-+ fmt++;
-+
-+ lsqf_ent_array_add_ent_string(array, nbuf);
-+
-+ ent = lsqf_ent_new(LSQF_ENT_TYPE_ARRAY);
-+ lsqf_ent_array_add_ent(array, ent);
-+
-+ if (do_parse(ent->array, fmt, &end, LSQF_PARSE_ARRAY)) {
-+ error = 1;
-+ break;
-+ }
-+
-+ if (*end == '\0') {
-+ logn(LOGERR, _("%s missing ] at end of array"), invalid_format);
-+ error = 1;
-+ break;
-+ }
-+
-+ fmt = end;
-+
-+ break;
-+
-+ case ']':
-+ if (mode != LSQF_PARSE_ARRAY) {
-+ logn(LOGERR, _("%s unexpected ]"), invalid_format);
-+ error = 1;
-+ break;
-+ }
-+
-+ /* found end of array -> stop parsing */
-+ done = 1;
-+
-+ /* save address of the last character we parsed */
-+ *endfmt = fmt;
-+
-+ break;
-+
-+ case '}':
-+ logn(LOGERR, _("%s unexpected }"), invalid_format);
-+ error = 1;
-+ break;
-+
-+ default:
-+ if (fmt[0] == '\\' && fmt[1] != '\0') {
-+ fmt++;
-+
-+ n_buf_putc(nbuf, get_escaped_char(*fmt));
-+
-+ } else {
-+ n_buf_putc(nbuf, *fmt);
-+ }
-+ }
-+
-+ fmt++;
-+ }
-+
-+ if (error) {
-+ n_buf_free(nbuf);
-+ return 1;
-+ }
-+
-+ lsqf_ent_array_add_ent_string(array, nbuf);
-+
-+ if (!done && endfmt)
-+ *endfmt = fmt;
-+
-+ n_buf_free(nbuf);
-+
-+ return 0;
-+}
-+
-+/**
-+ * lsqf_parse:
-+ *
-+ * Returns: On success, pointer to structure which is a base to display requested information or NULL when parsing failed.
-+ **/
-+struct lsqf_ent_array *lsqf_parse(char *fmt)
-+{
-+ struct lsqf_ent_array *array = NULL;
-+
-+ if ((array = lsqf_ent_array_new())) {
-+ if (do_parse(array, fmt, NULL, LSQF_PARSE_NORMAL)) {
-+ lsqf_ent_array_free(array);
-+ array = NULL;
-+ }
-+ }
-+
-+ return array;
-+}
-+
-+static int get_tag_array_size(const struct lsqf_ent *ent, struct lsqf_pkgdata *pkgdata)
-+{
-+ const struct pkg *pkg = pkgdata->pkg;
-+ unsigned int i;
-+ int size = 1;
-+
-+ n_assert(ent->type == LSQF_ENT_TYPE_TAG);
-+
-+ if (lsqf_tags[ent->tag.id].is_array) {
-+ size = 0;
-+
-+ if (lsqf_tags[ent->tag.id].need_flist) {
-+ struct pkgflist *flist = lsqf_pkgdata_flist(pkgdata);
-+
-+ if (flist) {
-+ switch (ent->tag.id) {
-+ case LSQF_TAG_BASENAMES:
-+ case LSQF_TAG_FILELINKTOS:
-+ case LSQF_TAG_FILEMODES:
-+ case LSQF_TAG_FILENAMES:
-+ case LSQF_TAG_FILESIZES:
-+ for (i = 0; i < n_tuple_size(flist->fl); i++) {
-+ struct pkgfl_ent *flent = n_tuple_nth(flist->fl, i);
-+
-+ size += flent->items;
-+ }
-+
-+ break;
-+
-+ case LSQF_TAG_DIRNAMES:
-+ size = n_tuple_size(flist->fl);
-+ break;
-+
-+ default:
-+ n_assert(0);
-+ }
-+ }
-+ } else {
-+ switch (ent->tag.id) {
-+ case LSQF_TAG_CONFLICTFLAGS:
-+ case LSQF_TAG_CONFLICTS:
-+ case LSQF_TAG_CONFLICTVERSION:
-+ case LSQF_TAG_OBSOLETEFLAGS:
-+ case LSQF_TAG_OBSOLETES:
-+ case LSQF_TAG_OBSOLETEVERSION:
-+ if (pkg->cnfls) {
-+ int nobsl = 0, ncnfls = 0;
-+
-+ for (i = 0; i < n_array_size(pkg->cnfls); i++) {
-+ struct capreq *cr = n_array_nth(pkg->cnfls, i);
-+
-+ if (capreq_is_obsl(cr))
-+ nobsl++;
-+ else
-+ ncnfls++;
-+ }
-+
-+ if (ent->tag.id == LSQF_TAG_CONFLICTFLAGS || ent->tag.id == LSQF_TAG_CONFLICTS
-+ || ent->tag.id == LSQF_TAG_CONFLICTVERSION)
-+ size = ncnfls;
-+ else
-+ size = nobsl;
-+ }
-+
-+ break;
-+
-+ case LSQF_TAG_PROVIDEFLAGS:
-+ case LSQF_TAG_PROVIDES:
-+ case LSQF_TAG_PROVIDEVERSION:
-+ if (pkg->caps)
-+ size = n_array_size(pkg->caps);
-+ break;
-+
-+ case LSQF_TAG_REQUIREFLAGS:
-+ case LSQF_TAG_REQUIRES:
-+ case LSQF_TAG_REQUIREVERSION:
-+ if (pkg->reqs)
-+ size = n_array_size(pkg->reqs);
-+ break;
-+
-+ case LSQF_TAG_SUGGESTSFLAGS:
-+ case LSQF_TAG_SUGGESTS:
-+ case LSQF_TAG_SUGGESTSVERSION:
-+ if (pkg->sugs)
-+ size = n_array_size(pkg->sugs);
-+ break;
-+
-+ default:
-+ n_assert(0);
-+ }
-+ }
-+ }
-+
-+ return size;
-+}
-+
-+/**
-+ * Returns 1 when arrays size differ.
-+ **/
-+static int check_size(const struct lsqf_ent_array *array, struct lsqf_pkgdata *pkgdata, unsigned int *s)
-+{
-+ unsigned int i;
-+ int size = 1, prev_size = -1;
-+
-+ for (i = 0; i < array->items; i++) {
-+ struct lsqf_ent *ent = array->ents[i];
-+
-+ if (ent->type == LSQF_ENT_TYPE_TAG) {
-+ if (lsqf_tags[ent->tag.id].is_array) {
-+ size = get_tag_array_size(ent, pkgdata);
-+ } else {
-+ /* check whether we want to print this tag with every iteration */
-+ if (ent->tag.iterate)
-+ continue;
-+
-+ size = 1;
-+ }
-+
-+ if (prev_size < 0)
-+ prev_size = size;
-+
-+ if (prev_size != size)
-+ return 1;
-+ }
-+ }
-+
-+ *s = size;
-+
-+ return 0;
-+}
-+
-+static void add_tagstr_to_nbuf(tn_buf *nbuf, const struct lsqf_ent *ent, struct lsqf_pkgdata *pkgdata, unsigned int num)
-+{
-+ char *str = NULL, fmt[16];
-+
-+ if (ent->tag.countArray) {
-+ n_snprintf(fmt, sizeof(fmt), "%%%dd", ent->tag.pad);
-+ n_buf_printf(nbuf, fmt, get_tag_array_size(ent, pkgdata));
-+
-+ } else if ((str = get_str_by_tagid(ent, pkgdata, num))) {
-+ n_snprintf(fmt, sizeof(fmt), "%%%ds", ent->tag.pad);
-+ n_buf_printf(nbuf, fmt, str);
-+
-+ n_free(str);
-+ }
-+}
-+
-+/**
-+ * tags_size - number of items in tags. It's mostly used by tag-arrays (for example REQUIRES)
-+ */
-+static int ent_array_to_string(const struct lsqf_ent_array *array,
-+ struct lsqf_pkgdata *pkgdata,
-+ tn_buf *nbuf, int tags_size)
-+{
-+ unsigned int i, j, size = 0;
-+
-+ for (j = 0; j < tags_size; j++) {
-+ for (i = 0; i < array->items; i++) {
-+ struct lsqf_ent *ent = array->ents[i];
-+ int ret = 1;
-+
-+ switch (ent->type) {
-+ case LSQF_ENT_TYPE_TAG:
-+ add_tagstr_to_nbuf(nbuf, ent, pkgdata, j);
-+ break;
-+
-+ case LSQF_ENT_TYPE_STRING:
-+ n_buf_puts_z(nbuf, ent->string);
-+ break;
-+
-+ case LSQF_ENT_TYPE_ARRAY:
-+ if (check_size(ent->array, pkgdata, &size)) {
-+ logn(LOGERR, _("%s array iterator used with different sized arrays"), invalid_format);
-+ ret = 0;
-+ } else {
-+ ret = ent_array_to_string(ent->array, pkgdata, nbuf, size);
-+ }
-+
-+ break;
-+
-+ default:
-+ n_assert(0);
-+ }
-+
-+ /* break on error */
-+ if (ret == 0)
-+ return 0;
-+ }
-+ }
-+
-+ return 1;
-+}
-+
-+char *lsqf_to_string(const struct lsqf_ent_array *array, const struct pkg *pkg)
-+{
-+ struct lsqf_pkgdata *pkgdata = NULL;
-+ tn_buf *nbuf = NULL;
-+ char *buf = NULL;
-+
-+ pkgdata = lsqf_pkgdata_new(pkg);
-+ nbuf = n_buf_new(64);
-+
-+ /* In the first array there can't be more than one item per tag,
-+ * so force tags_size = 1 */
-+ if (ent_array_to_string(array, pkgdata, nbuf, 1)) {
-+ buf = n_strdup(n_buf_ptr(nbuf));
-+ }
-+
-+ n_buf_free(nbuf);
-+ lsqf_pkgdata_free(pkgdata);
-+
-+ return buf;
-+}
-+
-+/**
-+ * lsqf_show_querytags:
-+ *
-+ * Print all supported tags.
-+ */
-+void lsqf_show_querytags(struct cmdctx *cmdctx)
-+{
-+ int i, j;
-+
-+ for (i = 0; i < LSQF_N_TAGS; i++) {
-+ for (j = 0; lsqf_tags[i].tagname[j]; j++) {
-+ cmdctx_printf(cmdctx, "%s\n", lsqf_tags[i].tagname[j]);
-+ }
-+ }
-+}
-diff --git a/cli/ls_queryfmt.h b/cli/ls_queryfmt.h
-new file mode 100644
-index 0000000..43d3858
---- /dev/null
-+++ b/cli/ls_queryfmt.h
-@@ -0,0 +1,47 @@
-+#ifndef POCLIDEK_LS_QUERYFMT_H
-+#define POCLIDEK_LS_QUERYFMT_H
-+
-+#include "cmd.h"
-+#include "pkg.h"
-+
-+struct lsqf_ent;
-+
-+struct lsqf_ent_array {
-+ struct lsqf_ent **ents;
-+ unsigned int items;
-+};
-+
-+struct lsqf_ent {
-+ enum {
-+ LSQF_ENT_TYPE_TAG = 1,
-+ LSQF_ENT_TYPE_STRING,
-+ LSQF_ENT_TYPE_ARRAY
-+ } type;
-+
-+ union {
-+ struct {
-+ int id;
-+
-+ int iterate;
-+ int countArray;
-+ int pad;
-+ int outfmtfnid;
-+ } tag;
-+
-+ char *string;
-+
-+ struct lsqf_ent_array *array;
-+ };
-+};
-+
-+
-+
-+struct lsqf_ent_array *lsqf_parse(char *fmt);
-+char *lsqf_to_string(const struct lsqf_ent_array *array, const struct pkg *pkg);
-+
-+struct lsqf_ent_array *lsqf_ent_array_new(void);
-+void lsqf_ent_array_free(struct lsqf_ent_array *array);
-+
-+void lsqf_show_querytags(struct cmdctx *cmdctx);
-+
-+#endif /* POCLIDEK_LS_QUERYFMT_H */
-diff --git a/cli/ls.c b/cli/ls.c
-index 0fe548c..e956e40 100644
---- a/cli/ls.c
-+++ b/cli/ls.c
-@@ -24,6 +24,7 @@
- #include "pkgu.h"
- #include "cli.h"
- #include "log.h"
-+#include "ls_queryfmt.h"
-
- static int ls(struct cmdctx *cmdctx);
- static
-@@ -51,6 +52,8 @@
- #define OPT_LS_NAMES_ONLY (1 << 11)
- #define OPT_LS_SOURCERPM (1 << 12)
-
-+#define OPT_LS_QUERYFMT (1 << 13)
-+#define OPT_LS_QUERYTAGS (1 << 14)
-
- #define OPT_LS_ERR (1 << 16);
-
-@@ -69,7 +72,9 @@
- { NULL, 'G', 0, 0, N_("Print package groups"), 1},
- { NULL, 'O', 0, 0, N_("Print package summaries"), 1},
- { "source-rpm", 's', 0, 0,N_("Print package source rpm"), 1},
--// { NULL, 'i', 0, OPTION_ALIAS, 0, 1 },
-+ { 0, 0, 0, 0, N_("Query format options:"), 2},
-+ { "qf", OPT_LS_QUERYFMT, "QUERYFMT", 0, N_("Use the following query format"), 2},
-+ { "querytags", OPT_LS_QUERYTAGS, 0, 0, N_("Show supported tags"), 2},
- { 0, 0, 0, 0, 0, 0 },
- };
-
-@@ -152,7 +157,25 @@
- case 'n':
- cmdctx->_flags |= OPT_LS_NAMES_ONLY;
- break;
--
-+
-+ case OPT_LS_QUERYFMT:
-+ cmdctx->_flags |= OPT_LS_QUERYFMT;
-+
-+ if (arg) {
-+ struct lsqf_ent_array *array = NULL;
-+
-+ if ((array = lsqf_parse(arg)) == NULL)
-+ return EINVAL;
-+
-+ cmdctx->_data = array;
-+ }
-+
-+ break;
-+
-+ case OPT_LS_QUERYTAGS:
-+ lsqf_show_querytags(cmdctx);
-+ return EINVAL;
-+
- default:
- return ARGP_ERR_UNKNOWN;
- }
-@@ -368,6 +391,10 @@
-
-
- l_end:
-+ if (cmdctx->_flags & OPT_LS_QUERYFMT) {
-+ lsqf_ent_array_free(cmdctx->_data);
-+ cmdctx->_data = NULL;
-+ }
-
- if (ls_ents)
- n_array_free(ls_ents);
-@@ -524,6 +524,16 @@
- else if (flags & OPT_LS_SOURCERPM) {
- const char *srcrpm = pkg_srcfilename_s(pkg);
- cmdctx_printf(cmdctx, fmt_pkg, pkg_name, srcrpm ? srcrpm : "(unset)");
-+
-+ } else if (flags & OPT_LS_QUERYFMT) {
-+ char *queryfmt = NULL;
-+
-+ if ((queryfmt = lsqf_to_string(cmdctx->_data, pkg))) {
-+ cmdctx_printf(cmdctx, "%s", queryfmt);
-+
-+ n_free(queryfmt);
-+ }
-+
- } else if ((flags & OPT_LS_LONG) == 0) {
- cmdctx_printf(cmdctx, "%s\n", pkg_name);
-
+++ /dev/null
-diff --git a/cli/ls.c b/cli/ls.c
-index 86b755d..1fa55ba 100644
---- a/cli/ls.c
-+++ b/cli/ls.c
-@@ -49,6 +49,7 @@ int pkg_cmp_lookup(struct pkg *lpkg, tn_array *pkgs, int compare_ver,
- #define OPT_LS_GROUP (1 << 9)
- #define OPT_LS_SUMMARY (1 << 10)
- #define OPT_LS_NAMES_ONLY (1 << 11)
-+#define OPT_LS_SOURCERPM (1 << 12)
-
-
- #define OPT_LS_ERR (1 << 16);
-@@ -67,7 +68,8 @@ static struct argp_option options[] = {
- { NULL, 'n', 0, 0, N_("Print only package names"), 1},
- { NULL, 'G', 0, 0, N_("Print package groups"), 1},
- { NULL, 'O', 0, 0, N_("Print package summaries"), 1},
--// { NULL, 'i', 0, OPTION_ALIAS, 0, 1 },
-+ { "source-rpm", 's', 0, 0,N_("Print package source rpm"), 1},
-+// { NULL, 'i', 0, OPTION_ALIAS, 0, 1 },
- { 0, 0, 0, 0, 0, 0 },
- };
-
-@@ -84,7 +86,7 @@ static
- error_t parse_opt(int key, char *arg, struct argp_state *state)
- {
- struct cmdctx *cmdctx = state->input;
-- const char *errmsg_excl = _("ls: -l and -G are exclusive");
-+ const char *errmsg_excl = _("ls: -l,-s and -G are exclusive");
- arg = arg;
-
- switch (key) {
-@@ -102,14 +104,23 @@ error_t parse_opt(int key, char *arg, struct argp_state *state)
- break;
-
- case 'G':
-- if (cmdctx->_flags & OPT_LS_LONG) {
-+ if (cmdctx->_flags & OPT_LS_LONG || cmdctx->_flags & OPT_LS_SOURCERPM) {
- logn(LOGERR, errmsg_excl);
- return EINVAL;
- }
-
- cmdctx->_flags |= OPT_LS_GROUP;
- break;
--
-+
-+ case 's':
-+ if (cmdctx->_flags & OPT_LS_LONG || cmdctx->_flags & OPT_LS_GROUP) {
-+ logn(LOGERR, errmsg_excl);
-+ return EINVAL;
-+ }
-+
-+ cmdctx->_flags |= OPT_LS_SOURCERPM;
-+ break;
-+
- case 't':
- cmdctx->_flags |= OPT_LS_SORTBUILDTIME;
- break;
-@@ -403,15 +414,17 @@ int do_ls(const tn_array *ents, struct cmdctx *cmdctx, const tn_array *evrs)
-
- *hdr = '\0';
-
-- if (flags & OPT_LS_GROUP) {
-+ if (flags & OPT_LS_GROUP || flags & OPT_LS_SOURCERPM) {
- snprintf(fmt_hdr, sizeof(fmt_hdr), "%%-%ds%%-%ds\n",
- term_width_div2 + term_width_div2/10, (term_width/7));
-
- snprintf(fmt_pkg, sizeof(fmt_pkg), "%%-%ds%%-%ds\n",
- term_width_div2 + term_width_div2/10, (term_width/7));
--
-- snprintf(hdr, sizeof(hdr), fmt_hdr, _("package"), _("group"));
-
-+ if (flags & OPT_LS_GROUP)
-+ snprintf(hdr, sizeof(hdr), fmt_hdr, _("package"), _("group"));
-+ else
-+ snprintf(hdr, sizeof(hdr), fmt_hdr, _("package"), _("source rpm"));
- } else if (flags & OPT_LS_LONG) {
- if ((flags & OPT_LS_UPGRADEABLE) == 0) {
- snprintf(fmt_hdr, sizeof(fmt_hdr), "%%-%ds %%-%ds%%%ds\n",
-@@ -480,7 +493,10 @@ int do_ls(const tn_array *ents, struct cmdctx *cmdctx, const tn_array *evrs)
- if (flags & OPT_LS_GROUP) {
- const char *group = pkg_group(pkg);
- cmdctx_printf(cmdctx, fmt_pkg, pkg_name, group ? group : "(unset)");
--
-+ }
-+ else if (flags & OPT_LS_SOURCERPM) {
-+ const char *srcrpm = pkg_srcfilename_s(pkg);
-+ cmdctx_printf(cmdctx, fmt_pkg, pkg_name, srcrpm ? srcrpm : "(unset)");
- } else if ((flags & OPT_LS_LONG) == 0) {
- cmdctx_printf(cmdctx, "%s\n", pkg_name);
-
+++ /dev/null
-diff --git a/install3/misc.c b/install3/misc.c
-index e3d238e..ded4de0 100644
---- a/install3/misc.c
-+++ b/install3/misc.c
-@@ -16,11 +16,15 @@
-
- #include "ictx.h"
-
--int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc)
-+int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc)
- {
- tn_array *dbpkgs = NULL;
-- int n;
--
-+ int n = 0, freshen = 0;
-+ freshen = ts->getop(ts, POLDEK_OP_FRESHEN)
-+ || poldek_ts_issetf(ts, POLDEK_TS_UPGRADE)
-+ || poldek_ts_issetf(ts, POLDEK_TS_DOWNGRADE)
-+ || poldek_ts_issetf(ts, POLDEK_TS_UPGRADEDIST);
-+
- n = pkgdb_search(ts->db, &dbpkgs, PMTAG_NAME, pkg->name, NULL, PKG_LDNEVR);
- n_assert(n >= 0);
-
-@@ -30,17 +34,25 @@ int i3_is_pkg_installed(struct poldek_ts *ts, struct pkg *pkg, int *cmprc)
- }
-
- if (poldek_conf_MULTILIB) { /* filter out different architectures */
-- int i;
- tn_array *arr = n_array_clone(dbpkgs);
-
- //DBGF("pkg = %s\n", pkg_id(pkg));
- //pkgs_array_dump(dbpkgs, "before_multilib");
-- for (i=0; i < n_array_size(dbpkgs); i++) {
-+ for (unsigned int i=0; i < n_array_size(dbpkgs); i++) {
- struct pkg *dbpkg = n_array_nth(dbpkgs, i);
-- if (pkg_is_kind_of(dbpkg, pkg))
-- n_array_push(arr, pkg_link(dbpkg));
-+
-+ msgn(4, "from pkg %s.%s => to pkg %s-%s-%s.%s freshen:%d kind:%d up_arch:%d",
-+ pkg_snprintf_s(dbpkg), pkg_arch(dbpkg), pkg->name, pkg->ver, pkg->rel, pkg_arch(pkg),
-+ freshen, pkg_is_kind_of(dbpkg, pkg), pkg_is_arch_compat(dbpkg, pkg));
-+
-+ // if freshen (upgrade) preffer same arch but
-+ // change from/to noarch depends on which pkg is noarch
-+ // add package if pkg_is_kind_of (have same name and color)
-+ if (pkg_is_kind_of(dbpkg, pkg)
-+ && !(freshen && !pkg_is_arch_compat(dbpkg, pkg)))
-+ n_array_push(arr, pkg_link(dbpkg));
- }
--
-+
- n_array_cfree(&dbpkgs);
- dbpkgs = arr;
- n = n_array_size(arr);
-diff --git a/libpoldek.sym b/libpoldek.sym
-index 6c2a356..26e05d5 100644
---- a/libpoldek.sym
-+++ b/libpoldek.sym
-@@ -71,6 +71,7 @@ pkg_id_snprintf
- pkg_idevr_snprintf
- pkg_is_colored_like
- pkg_is_kind_of
-+pkg_is_arch_compat
- pkg_link
- pkg_localpath
- pkg_match_req
-diff --git a/pkg.h b/pkg.h
-index 8a1d0b2..77acf0a 100644
---- a/pkg.h
-+++ b/pkg.h
-@@ -43,6 +43,8 @@ struct pkgdir; /* defined in pkgdir/pkgdir.h */
- ((pkg)->flags & color)
- #endif /* POLDEK_PKG_DAG_COLOURS */
-
-+#define pkg_is_noarch(pkg) (0 == strcmp(pkg_arch((pkg)), "noarch"))
-+
- #define pkg_set_prereqed(pkg) ((pkg)->flags |= PKG_ORDER_PREREQ)
- #define pkg_clr_prereqed(pkg) ((pkg)->flags &= ~PKG_ORDER_PREREQ)
- #define pkg_is_prereqed(pkg) ((pkg)->flags & PKG_ORDER_PREREQ)
-diff --git a/pkgcmp.c b/pkgcmp.c
-index f123e03..7bf34d4 100644
---- a/pkgcmp.c
-+++ b/pkgcmp.c
-@@ -88,7 +88,19 @@ int pkg_is_colored_like(const struct pkg *candidate, const struct pkg *pkg)
- return 1;
- }
-
--int pkg_eq_capreq(const struct pkg *pkg, const struct capreq *cr)
-+/* ret : 1 if pkg is cappable to upgrade arch<=>arch, arch<=>noarch */
-+int pkg_is_arch_compat(const struct pkg *candidate, const struct pkg *pkg)
-+{
-+ // if upgrade preffer same arch but
-+ // change from/to noarch depends on which pkg is noarch
-+
-+ int cmp_arch = pkg_cmp_arch(candidate, pkg);
-+ return ( cmp_arch == 0
-+ || (cmp_arch > 0 && pkg_is_noarch(candidate))
-+ || (cmp_arch < 0 && pkg_is_noarch(pkg)));
-+}
-+
-+int pkg_eq_capreq(const struct pkg *pkg, const struct capreq *cr)
- {
- return strcmp(pkg->name, capreq_name(cr)) == 0 &&
- strcmp(pkg->ver, capreq_ver(cr)) == 0 &&
-diff --git a/pkgcmp.h b/pkgcmp.h
-index 6b1b75a..980f675 100644
---- a/pkgcmp.h
-+++ b/pkgcmp.h
-@@ -17,6 +17,9 @@ int pkg_is_colored_like(const struct pkg *candidate, const struct pkg *pkg);
- /* same name && arch */
- int pkg_is_kind_of(const struct pkg *candidate, const struct pkg *pkg);
-
-+/* ret : 0 if pkg is cappable to upgrade arch<=>arch, arch<=>noarch */
-+int pkg_is_arch_compat(const struct pkg *candidate, const struct pkg *pkg);
-+
- /* strncmp(p1->name, p2->name, strlen(p2->name)) */
- extern__inline int pkg_ncmp_name(const struct pkg *p1, const struct pkg *p2);
-
-@@ -27,7 +30,7 @@ int pkg_cmp_name(const struct pkg *p1, const struct pkg *p2);
- extern__inline int pkg_cmp_id(const struct pkg *p1, const struct pkg *p2);
-
-
--/* versions only */
-+/* versions only (+epoch) */
- int pkg_cmp_ver(const struct pkg *p1, const struct pkg *p2);
- /* EVR only */
- int pkg_cmp_evr(const struct pkg *p1, const struct pkg *p2);
-diff --git a/upgrade-dist.c b/upgrade-dist.c
-index 458b764..00f34fc 100644
---- a/upgrade-dist.c
-+++ b/upgrade-dist.c
-@@ -64,8 +64,18 @@ int process_pkg(const struct pkg *dbpkg, struct poldek_ts *ts,
-
- if (!ts->getop(ts, POLDEK_OP_MULTILIB))
- break;
--
-- if (pkg_is_kind_of(pkg, dbpkg))
-+
-+ if (0 != strcmp(dbpkg->name, pkg->name))
-+ {
-+ pkg = NULL;
-+ break;
-+ }
-+
-+ msgn(4, "UPGRADE-DIST from pkg %s.%s => to pkg %s-%s-%s.%s kind:%d up_arch:%d",
-+ pkg_snprintf_s(dbpkg), pkg_arch(dbpkg), pkg->name, pkg->ver, pkg->rel, pkg_arch(pkg),
-+ pkg_is_kind_of(dbpkg, pkg), pkg_is_arch_compat(dbpkg, pkg));
-+
-+ if (pkg_cmp_evr(pkg, dbpkg) > 0 && pkg_is_kind_of(pkg, dbpkg) && pkg_is_arch_compat(pkg, dbpkg))
- break;
-
- i++;
+++ /dev/null
-diff -urN poldek-0.30-cvs20080820.23/pkgcmp.h poldek-0.30-cvs20080820.23.new/pkgcmp.h
---- poldek-0.30-cvs20080820.23/pkgcmp.h 2008-01-27 19:42:14.000000000 +0100
-+++ poldek-0.30-cvs20080820.23.new/pkgcmp.h 2009-02-23 16:33:50.000000000 +0100
-@@ -21,7 +21,7 @@
- extern__inline int pkg_ncmp_name(const struct pkg *p1, const struct pkg *p2);
-
- /* strcmp(p1->name, p2->name) */
--extern__inline int pkg_cmp_name(const struct pkg *p1, const struct pkg *p2);
-+int pkg_cmp_name(const struct pkg *p1, const struct pkg *p2);
-
- /* strcmp(pkg_id(p1), pkg_id(p2) */
- extern__inline int pkg_cmp_id(const struct pkg *p1, const struct pkg *p2);
-diff -urN poldek-0.30-cvs20080820.23/pkg.h poldek-0.30-cvs20080820.23.new/pkg.h
---- poldek-0.30-cvs20080820.23/pkg.h 2008-05-25 11:25:31.000000000 +0200
-+++ poldek-0.30-cvs20080820.23.new/pkg.h 2009-02-23 16:33:41.000000000 +0100
-@@ -144,7 +144,7 @@
- # define extern__inline extern inline
- #endif
-
--extern__inline struct pkg *pkg_link(struct pkg *pkg);
-+struct pkg *pkg_link(struct pkg *pkg);
-
- int pkg_set_arch(struct pkg *pkg, const char *arch);
- const char *pkg_arch(const struct pkg *pkg);
+++ /dev/null
---- pkgcmp.c~ 2008-11-19 01:12:49.000000000 +0100
-+++ pkgcmp.c 2008-11-19 01:13:36.125519583 +0100
-@@ -82,13 +82,10 @@
- return 1;
-
- if (pkg->color && candidate->color)
-- return pkg->color & candidate->color;
-+ return (pkg->color & candidate->color) > 0;
-
-- /* same name and candidate without color -> promote candidate */
-- if (pkg->color && pkg_is_kind_of(candidate, pkg))
-- return 1;
--
-- return 0;
-+ /* either new or old package contains no binary files, let it happen */
-+ return 1;
- }
-
- int pkg_eq_capreq(const struct pkg *pkg, const struct capreq *cr)
+++ /dev/null
-diff --git a/poldek_term.c b/poldek_term.c
-index 2ee6b66..fec05de 100644
---- a/poldek_term.c
-+++ b/poldek_term.c
-@@ -287,6 +287,10 @@ int poldek_term_ask(int fd, const char *validchrs, const char *msg)
- if ((read(fd, &c, sizeof(c)) == 1) && strchr(validchrs, c))
- break;
-
-+ // terminal lost - so prevent loop
-+ if (!isatty(fd))
-+ return 0;
-+
- if (msg)
- printf("%s\n", msg);
- }
+++ /dev/null
---- poldek-0.30-cvs20080820.23/pkgdir/pndir/description.c.old 2008-12-10 15:50:49.000000000 +0100
-+++ poldek-0.30-cvs20080820.23/pkgdir/pndir/description.c 2008-12-10 15:52:39.000000000 +0100
-@@ -165,9 +165,8 @@ struct pkguinf *pndir_load_pkguinf(tn_al
- /* start from the end => the last loaded one will be set as
- pkguinf default (see pkguinf_restore_i18n()) */
- for (i = n_array_size(langs) - 1; i >= 0; i--) {
-- const char *lang, *loaded_lang = NULL;
-+ const char *lang;
- struct tndb *db;
-- char lang_utf8[32];
- char dkey[512];
- int dklen;
-
-@@ -178,26 +177,17 @@ struct pkguinf *pndir_load_pkguinf(tn_al
- if ((db = pndir_db_dscr_h_get(db_dscr_h, lang)) == NULL)
- continue;
-
-- n_snprintf(lang_utf8, sizeof(lang_utf8), "%s.UTF-8", lang);
-- loaded_lang = lang_utf8;
--
-- dklen = n_snprintf(dkey, sizeof(dkey), "%s%s", key, lang_utf8);
-+ dklen = n_snprintf(dkey, sizeof(dkey), "%s%s", key, lang);
- vlen = tndb_get(db, dkey, dklen, val, sizeof(val));
--
-- if (vlen == 0) { /* not exists */
-- dklen = n_snprintf(dkey, sizeof(dkey), "%s%s", key, lang);
-- vlen = tndb_get(db, dkey, dklen, val, sizeof(val));
-- loaded_lang = lang;
-- }
--
-- DBGF("ld %s: %s (%d)\n", pkg_id(pkg), loaded_lang ? loaded_lang : lang, vlen);
-+
-+ DBGF("ld %s: %s (%d)\n", pkg_id(pkg), lang, vlen);
-
- if (vlen > 0) {
- tn_buf_it it;
- n_buf_clean(nbuf);
- n_buf_init(nbuf, val, vlen);
- n_buf_it_init(&it, nbuf);
-- pkguinf_restore_i18n(pkgu, &it, loaded_lang);
-+ pkguinf_restore_i18n(pkgu, &it, lang);
- }
- }
- }
+++ /dev/null
-commit c9bfac52591027f6f87de0663d120ce26fe6b56a
-Author: Marcin Banasiak <megabajt@pld-linux.org>
-Date: Thu Aug 7 10:47:03 2008 +0200
-
- - added POLDEK_OP_LDALLDESC; loading of all i18n descriptions can be forced now.
-
-diff --git a/lib_pkgset.c b/lib_pkgset.c
-index ef7ecb4..bea738a 100644
---- a/lib_pkgset.c
-+++ b/lib_pkgset.c
-@@ -63,6 +63,9 @@ int poldek__load_sources_internal(struct poldek_ctx *ctx)
-
- if (ctx->ts->getop(ctx->ts, POLDEK_OP_LDFULLFILELIST))
- ldflags |= PKGDIR_LD_FULLFLIST;
-+
-+ if (ctx->ts->getop(ctx->ts, POLDEK_OP_LDALLDESC))
-+ ldflags |= PKGDIR_LD_ALLDESC;
-
- #if 0 /* XXX now files are loaded on demand */
- if (strcmp(pm_get_name(ctx->pmctx), "pset") == 0)
-diff --git a/pkgdir/dir/dir.c b/pkgdir/dir/dir.c
-index 2aa7e65..0b720c1 100644
---- a/pkgdir/dir/dir.c
-+++ b/pkgdir/dir/dir.c
-@@ -159,7 +159,6 @@ struct pkguinf *load_pkguinf(tn_alloc *na, const struct pkg *pkg,
- Header h;
-
- ptr = ptr; /* unused pkgdir_data */
-- langs = langs; /* ignored, selective retrieving no supported */
-
- snprintf(path, sizeof(path), "%s/%s", pkg->pkgdir->idxpath,
- pkg_filename_s(pkg));
-@@ -172,7 +171,7 @@ struct pkguinf *load_pkguinf(tn_alloc *na, const struct pkg *pkg,
- return NULL;
- }
-
-- pkgu = pkguinf_ldrpmhdr(na, h);
-+ pkgu = pkguinf_ldrpmhdr(na, h, langs);
-
- pm_rpmhdr_free(h);
- return pkgu;
-@@ -269,7 +268,7 @@ int load_dir(struct pkgdir *pkgdir,
- pkg->groupid = pkgroup_idx_update_rpmhdr(pkgroups, h);
-
- if (ldflags & PKGDIR_LD_DESC) {
-- pkg->pkg_pkguinf = pkguinf_ldrpmhdr(na, h);
-+ pkg->pkg_pkguinf = pkguinf_ldrpmhdr(na, h, NULL);
- pkg_set_ldpkguinf(pkg);
- }
- }
-diff --git a/pkgdir/hdrl/hdrl.c b/pkgdir/hdrl/hdrl.c
-index 495e363..5d7a1b8 100644
---- a/pkgdir/hdrl/hdrl.c
-+++ b/pkgdir/hdrl/hdrl.c
-@@ -106,7 +106,7 @@ static int do_load(struct pkgdir *pkgdir, unsigned ldflags)
-
- if ((pkg = pm_rpm_ldhdr(pkgdir->na, h, NULL, 0, PKG_LDWHOLE))) {
- if (ldflags & PKGDIR_LD_DESC) {
-- pkg->pkg_pkguinf = pkguinf_ldrpmhdr(pkgdir->na, h);
-+ pkg->pkg_pkguinf = pkguinf_ldrpmhdr(pkgdir->na, h, NULL);
- pkg_set_ldpkguinf(pkg);
- }
-
-diff --git a/pkgdir/pkgdir.c b/pkgdir/pkgdir.c
-index 634a2a4..ca2d7a8 100644
---- a/pkgdir/pkgdir.c
-+++ b/pkgdir/pkgdir.c
-@@ -496,7 +496,6 @@ struct pkgdir *pkgdir_open_ext(const char *path, const char *pkg_prefix,
- n_array_sort(pkgdir->depdirs);
- }
-
-- pkgdir->flags |= flags;
- return pkgdir;
- }
-
-diff --git a/pkgdir/pkgdir.h b/pkgdir/pkgdir.h
-index e1c88d0..7535d16 100644
---- a/pkgdir/pkgdir.h
-+++ b/pkgdir/pkgdir.h
-@@ -108,6 +108,9 @@ struct pkgdir *pkgdir_open(const char *path, const char *pkg_prefix,
- #define PKGDIR_LD_NOUNIQ (1 << 3) /* don't perform pkgdir_uniq() */
- #define PKGDIR_LD_DOIGNORE (1 << 4) /* honour src->ign_patterns */
- #define PKGDIR_LD_DIRINDEX (1 << 5) /* handle rpm 4.4.6 auto deps */
-+#define PKGDIR_LD_ALLDESC (1 << 6) /* load all i18n descriptions
-+ (see PKGDIR_OPEN_ALLDESC)
-+ */
-
- int pkgdir_load(struct pkgdir *pkgdir, tn_array *depdirs, unsigned ldflags);
-
-diff --git a/pkgdir/rpmdb/rpmdb.c b/pkgdir/rpmdb/rpmdb.c
-index 635e354..b602a07 100644
---- a/pkgdir/rpmdb/rpmdb.c
-+++ b/pkgdir/rpmdb/rpmdb.c
-@@ -110,9 +110,8 @@ struct pkguinf *load_pkguinf(tn_alloc *na, const struct pkg *pkg,
- struct pkguinf *pkgu = NULL;
- Header h;
-
-- langs = langs; /* ignored, no support */
- if ((h = ldhdr(pkg, ptr))) {
-- pkgu = pkguinf_ldrpmhdr(na, h);
-+ pkgu = pkguinf_ldrpmhdr(na, h, langs);
- pm_rpmhdr_free(h);
- }
-
-diff --git a/pkgdir/rpmdb/rpmdbcache.c b/pkgdir/rpmdb/rpmdbcache.c
-index 224b4b3..70a25ce 100644
---- a/pkgdir/rpmdb/rpmdbcache.c
-+++ b/pkgdir/rpmdb/rpmdbcache.c
-@@ -134,11 +134,9 @@ struct pkguinf *dbcache_load_pkguinf(tn_alloc *na, const struct pkg *pkg,
- {
- struct pkguinf *pkgu = NULL;
- Header h;
--
-- langs = langs; /* ignored, no support */
-
- if ((h = ldhdr(pkg, ptr))) {
-- pkgu = pkguinf_ldrpmhdr(na, h);
-+ pkgu = pkguinf_ldrpmhdr(na, h, langs);
- pm_rpmhdr_free(h);
- }
-
-diff --git a/pkgdir/yum/yum.c b/pkgdir/yum/yum.c
-index a7e48d7..f3e5c36 100644
---- a/pkgdir/yum/yum.c
-+++ b/pkgdir/yum/yum.c
-@@ -269,7 +269,7 @@ struct pkg *do_loadpkg(tn_alloc *na, Header h, int ldflags, const char *pkgfn)
- struct pkg *pkg;
- if ((pkg = pm_rpm_ldhdr(na, h, pkgfn, 0, PKG_LDWHOLE))) {
- if (ldflags & PKGDIR_LD_DESC) {
-- pkg->pkg_pkguinf = pkguinf_ldrpmhdr(na, h);
-+ pkg->pkg_pkguinf = pkguinf_ldrpmhdr(na, h, NULL);
- pkg_set_ldpkguinf(pkg);
- }
- }
-@@ -287,7 +287,6 @@ struct pkguinf *load_pkguinf(tn_alloc *na, const struct pkg *pkg,
- char path[PATH_MAX], *hdrpath;
- Header h;
-
-- langs = langs; /* ignored, no support */
- if (!pkg->pkgdir)
- return NULL;
-
-@@ -297,7 +296,7 @@ struct pkguinf *load_pkguinf(tn_alloc *na, const struct pkg *pkg,
-
- pkg = pkg;
- if ((h = do_loadrpmhdr(path, vfmode, n_basenam(path)))) {
-- pkgu = pkguinf_ldrpmhdr(na, h);
-+ pkgu = pkguinf_ldrpmhdr(na, h, langs);
- headerFree(h);
- }
-
-diff --git a/pkgset-load.c b/pkgset-load.c
-index f2f0d3c..7ac3762 100644
---- a/pkgset-load.c
-+++ b/pkgset-load.c
-@@ -32,9 +32,13 @@
- int pkgset_load(struct pkgset *ps, int ldflags, tn_array *sources)
- {
- int i, j, iserr = 0;
-+ unsigned openflags = 0;
-
- n_array_isort_ex(sources, (tn_fn_cmp)source_cmp_pri);
-
-+ if (ldflags & PKGDIR_LD_ALLDESC)
-+ openflags |= PKGDIR_OPEN_ALLDESC;
-+
- for (i=0; i < n_array_size(sources); i++) {
- struct source *src = n_array_nth(sources, i);
- struct pkgdir *pkgdir = NULL;
-@@ -47,7 +51,7 @@ int pkgset_load(struct pkgset *ps, int ldflags, tn_array *sources)
- source_set_type(src, poldek_conf_PKGDIR_DEFAULT_TYPE);
-
-
-- pkgdir = pkgdir_srcopen(src, 0);
-+ pkgdir = pkgdir_srcopen(src, openflags);
-
- /* trying dir */
- if (pkgdir == NULL && !source_is_type(src, "dir") &&
-@@ -56,7 +60,7 @@ int pkgset_load(struct pkgset *ps, int ldflags, tn_array *sources)
- logn(LOGNOTICE, _("trying to scan directory %s..."), src->path);
-
- source_set_type(src, "dir");
-- pkgdir = pkgdir_srcopen(src, 0);
-+ pkgdir = pkgdir_srcopen(src, openflags);
- }
-
- if (pkgdir == NULL) {
-diff --git a/pkgu.c b/pkgu.c
-index 6ea077e..26bb647 100644
---- a/pkgu.c
-+++ b/pkgu.c
-@@ -639,7 +639,7 @@ char *load_changelog_from_rpmhdr(tn_alloc *na, void *hdr)
- return changelog;
- }
-
--struct pkguinf *pkguinf_ldrpmhdr(tn_alloc *na, void *hdr)
-+struct pkguinf *pkguinf_ldrpmhdr(tn_alloc *na, void *hdr, tn_array *loadlangs)
- {
- tn_array *langs;
- char **summs, **descrs;
-@@ -653,7 +653,7 @@ struct pkguinf *pkguinf_ldrpmhdr(tn_alloc *na, void *hdr)
-
- if ((langs = pm_rpmhdr_langs(h))) {
- tn_array *sl_langs = NULL;
-- char *sl_lang;
-+ char *lc_lang = NULL, *sl_lang = NULL;
-
- pm_rpmhdr_get_raw_entry(h, RPMTAG_SUMMARY, (void*)&summs, &nsumms);
- pm_rpmhdr_get_raw_entry(h, RPMTAG_DESCRIPTION, (void*)&descrs, &ndescrs);
-@@ -685,7 +685,23 @@ struct pkguinf *pkguinf_ldrpmhdr(tn_alloc *na, void *hdr)
- langs = n_array_remove_nth(langs, i - 1);
- }
-
-- sl_langs = lc_lang_select(langs, lc_messages_lang());
-+ if (loadlangs) {
-+ for (i = 0; i < n_array_size(loadlangs); i++) {
-+ const char *loadlang = n_array_nth(loadlangs, i);
-+
-+ if (loadlang == NULL)
-+ continue;
-+
-+ if (lc_lang == NULL)
-+ lc_lang = n_strdup(loadlang);
-+ else {
-+ lc_lang = n_str_concat(lc_lang, ":", loadlang, NULL);
-+ }
-+ }
-+ } else
-+ lc_lang = n_strdup(lc_messages_lang());
-+
-+ sl_langs = lc_lang_select(langs, lc_lang);
- if (sl_langs == NULL)
- sl_lang = "C";
- else
-@@ -703,6 +719,7 @@ struct pkguinf *pkguinf_ldrpmhdr(tn_alloc *na, void *hdr)
- n_array_free(langs);
- n_array_cfree(&sl_langs);
-
-+ free(lc_lang);
- free(summs);
- free(descrs);
- }
-@@ -1160,7 +1177,7 @@ struct pkguinf *pkguinf_restore_rpmhdr_st(tn_alloc *na,
- }
-
- if ((hdr = headerLoad(rawhdr)) != NULL) {
-- pkgu = pkguinf_ldrpmhdr(na, hdr);
-+ pkgu = pkguinf_ldrpmhdr(na, hdr, NULL);
- headerFree(hdr); //rpm's memleak
- }
-
-diff --git a/pkgu.h b/pkgu.h
-index 9a7bb86..2ced69a 100644
---- a/pkgu.h
-+++ b/pkgu.h
-@@ -41,7 +41,7 @@ int pkguinf_skip_rpmhdr(tn_stream *st);
- struct pkguinf *pkguinf_restore_rpmhdr_st(tn_alloc *na,
- tn_stream *st, off_t offset);
-
--struct pkguinf *pkguinf_ldrpmhdr(tn_alloc *na, void *hdr);
-+struct pkguinf *pkguinf_ldrpmhdr(tn_alloc *na, void *hdr, tn_array *loadlangs);
-
- tn_buf *pkguinf_store(const struct pkguinf *pkgu, tn_buf *nbuf,
- const char *lang);
-diff --git a/poldek_ts.h b/poldek_ts.h
-index ab43ccf..b98cfe8 100644
---- a/poldek_ts.h
-+++ b/poldek_ts.h
-@@ -41,6 +41,7 @@ enum poldek_ts_opt {
- POLDEK_OP_VRFY_FILEMISSDEPS, /* --verify=file-missing-deps */
- POLDEK_OP_DEPGRAPH, /* --dependency-graph */
-
-+ POLDEK_OP_LDALLDESC, /* internal, load all i18n descriptions */
- POLDEK_OP_LDFULLFILELIST, /* internal, load whole file database */
-
- POLDEK_OP_VRFYMERCY, /* --mercy */
+++ /dev/null
---- poldek-0.30-cvs20080820.23/arg_packages.c~ 2009-03-04 00:02:23.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/arg_packages.c 2009-03-04 00:02:34.012264942 +0200
-@@ -428,7 +428,7 @@
- if (poldek_VERBOSE > 1) {
- int i;
-
-- msgn(2, "%s: %d package(s) found:", mask, n_array_size(pkgs));
-+ msgn(2, _("%s: %d package(s) found:"), mask, n_array_size(pkgs));
- for (i=0; i < n_array_size(pkgs); i++)
- msgn(2, " - %s", pkg_snprintf_s(n_array_nth(pkgs, i)));
- }
-@@ -628,10 +628,10 @@
- }
- }
-
-- if (poldek_VERBOSE > 2)
-- msgn(1, "%s: choosen %s among %d packages", key,
-+ if (poldek_VERBOSE > 2)
-+ msgn(1, _("%s: choosen %s among %d packages"), key,
- pkg_snprintf_s(pkg), n_array_size(pkgs));
--
-+
- n_array_push(topkgs, pkg_link(pkg));
- }
-
---- poldek-0.30-cvs20080820.23/./cli/alias.c~ 2008-02-02 22:39:01.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/./cli/alias.c 2009-03-04 00:03:40.535590911 +0200
-@@ -159,7 +159,7 @@
- logn(LOGWARN, _("%s: could not determine aliased command"),
- cmd->name);
- else
-- msgn(3, "%s => aliased %s", cmd->name, cmd->aliasto);
-+ msgn(3, _("%s => aliased %s"), cmd->name, cmd->aliasto);
- }
- }
-
---- poldek-0.30-cvs20080820.23/./cli/su.c~ 2008-02-02 23:16:37.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/./cli/su.c 2009-03-04 00:04:00.512262048 +0200
-@@ -115,7 +115,7 @@
- return 0;
- }
-
-- msgn(2, "Running as user '%s'\n", user);
-+ msgn(2, _("Running as user '%s'\n"), user);
- return 1;
- }
-
---- poldek-0.30-cvs20080820.23/./conf.c~ 2008-05-24 23:59:54.000000000 +0300
-+++ poldek-0.30-cvs20080820.23/./conf.c 2009-03-04 00:04:41.845626927 +0200
-@@ -1133,11 +1133,11 @@
- add_param(ht_sect, sectnam, name, value, addparam_flags,
- af->path, nline);
- } else
-- msgn(1, "%s: skipped %s::%s", af->path, sectnam, name);
-+ msgn(1, _("%s: skipped %s::%s"), af->path, sectnam, name);
- }
-
-
-- msgn(3, "-- %s EOF --", af->path);
-+ msgn(3, _("-- %s EOF --"), af->path);
-
-
- if (ht) {
---- poldek-0.30-cvs20080820.23/./fileindex.c~ 2008-01-23 01:59:52.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/./fileindex.c 2009-03-04 00:05:59.365623692 +0200
-@@ -335,7 +335,7 @@
- if ((c1 || c2) && verbose > 0) {
- char buf[256];
- pkg_snprintf(buf, sizeof(buf), pkg1);
-- msgn(1, "add cnfl: %s %c-%c %s", buf, c2 ? :' ', c1 ? :' ',
-+ msgn(1, _("add cnfl: %s %c-%c %s"), buf, c2 ? :' ', c1 ? :' ',
- pkg_snprintf_s(pkg2));
- }
- #endif
-@@ -527,7 +527,7 @@
- continue;
- }
- if (pathprinted == 0) {
-- msgn(0, "\nPath: %s%s", *cnfl->path == '/' ? "" : "/",
-+ msgn(0, _("\nPath: %s%s"), *cnfl->path == '/' ? "" : "/",
- cnfl->path);
- pathprinted = 1;
- }
-@@ -537,7 +537,7 @@
- }
- }
- n_array_free(paths);
-- msgn(0, "%d file conflicts found", nconflicts);
-+ msgn(0, _("%d file conflicts found"), nconflicts);
- return nconflicts;
- }
-
-@@ -643,11 +643,11 @@
-
- if (n_array_size(opkgs) > 5)
- n += n_snprintf(&pkgstr[n], sizeof(pkgstr) - n,
-- "[%d packages left]", n_array_size(opkgs) - 5);
-- logn(LOGERR, "%s: orphaned directory from %s", path, pkgstr);
-+ _("[%d packages left]"), n_array_size(opkgs) - 5);
-+ logn(LOGERR, _("%s: orphaned directory from %s"), path, pkgstr);
- }
- norphans = n_array_size(paths);
-- msgn(0, "%d orphaned directories found", norphans);
-+ msgn(0, _("%d orphaned directories found"), norphans);
- n_array_free(paths);
- n_hash_free(orphanh);
-
-@@ -721,7 +721,7 @@
- for (i=0; i < size; i++) {
- char key[PATH_MAX];
-
-- msgn(2, "Looking for path %s -> %s (%s)", pkg_id(pkg), pkg_id(ptab[i]),
-+ msgn(2, _("Looking for path %s -> %s (%s)"), pkg_id(pkg), pkg_id(ptab[i]),
- path);
-
- n_snprintf(key, sizeof(key), "%s -> %s", pkg_id(pkg), pkg_id(ptab[i]));
-@@ -843,12 +843,12 @@
- n += n_snprintf(&pkgstr[n], sizeof(pkgstr) - n,
- "...", mreq->ncandidates - 3);
-
-- logn(LOGERR, "%s: %s: directory not in required packages "
-- "(missing Requires: %s?)", id, mreq->path, pkgstr);
-+ logn(LOGERR, _("%s: %s: directory not in required packages "
-+ "(missing Requires: %s?)"), id, mreq->path, pkgstr);
- norphans++;
- }
- }
-- msgn(0, "%d semi-orphaned directories found", norphans);
-+ msgn(0, _("%d semi-orphaned directories found"), norphans);
- n_array_free(pkgids);
- n_hash_free(missreqh);
- return norphans;
---- poldek-0.30-cvs20080820.23/./pkgdir/dir/dir.c~ 2009-03-02 18:36:49.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/./pkgdir/dir/dir.c 2009-03-04 00:06:39.086835080 +0200
-@@ -221,7 +221,7 @@
- if (mtime_index) {
- pkg = search_in_mtime_index(mtime_index, ent->d_name, &st);
- if (pkg) {
-- msgn(3, "%s: file seems untouched, loaded from previous index",
-+ msgn(3, _("%s: file seems untouched, loaded from previous index"),
- pkg_filename_s(pkg));
- pkg = pkg_link(pkg);
- remap_groupid(pkg, pkgroups, prev_pkgdir);
-@@ -230,7 +230,7 @@
-
- if (pkg == NULL) { /* mtime changed, but try compare content */
- if (!pm_rpmhdr_loadfile(path, &h)) {
-- logn(LOGWARN, "%s: read header failed, skipped", path);
-+ logn(LOGWARN, _("%s: read header failed, skipped"), path);
- continue;
- }
-
-@@ -240,7 +240,7 @@
- if (prev_pkgdir) {
- pkg = search_in_prev(prev_pkgdir, h, ent->d_name, &st);
- if (pkg) {
-- msgn(3, "%s: seems untouched, loaded from previous index",
-+ msgn(3, _("%s: seems untouched, loaded from previous index"),
- pkg_snprintf_s(pkg));
- pkg = pkg_link(pkg);
- remap_groupid(pkg, pkgroups, prev_pkgdir);
-@@ -253,7 +253,7 @@
-
- nnew++;
- n_assert(h); /* loaded in previous if block */
-- msgn(3, "%s: loading header...", n_basenam(path));
-+ msgn(3, _("%s: loading header..."), n_basenam(path));
- pkg = pm_rpm_ldhdr(na, h, n_basenam(path), st.st_size, PKG_LDWHOLE);
- n_assert(pkg);
-
---- poldek-0.30-cvs20080820.23/./pkgdir/pndir/update.c~ 2007-06-24 14:48:07.000000000 +0300
-+++ poldek-0.30-cvs20080820.23/./pkgdir/pndir/update.c 2009-03-04 00:07:11.142236416 +0200
-@@ -304,7 +304,7 @@
- if (memcmp(md, current_md, TNIDX_DIGEST_SIZE) == 0)
- first_patch_found = 1;
- else {
-- msgn(2, "Check diff (ts = %ld, %ld) %s (searching %s)\n",
-+ msgn(2, _("Check diff (ts = %ld, %ld) %s (searching %s)\n"),
- (long)pkgdir->ts, (long)ts, md, current_md);
-
- if (poldek_verbose() > 3) {
---- poldek-0.30-cvs20080820.23/./pkgset.c~ 2008-01-22 14:36:39.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/./pkgset.c 2009-03-04 00:08:12.872782026 +0200
-@@ -391,7 +391,7 @@
- if (verb && poldek_VERBOSE > 2) {
- int i;
-
-- msg(2, "Installation order:\n");
-+ msg(2, _("Installation order:\n"));
- for (i=0; i < n_array_size(ps->ordered_pkgs); i++) {
- struct pkg *pkg = n_array_nth(ps->ordered_pkgs, i);
- msg(2, "%d. %s\n", i, pkg->name);
-@@ -697,7 +697,7 @@
- n_buf_free(nbuf);
-
- if (outfile)
-- msgn(0, "Graph saved as %s", outfile);
-+ msgn(0, _("Graph saved as %s"), outfile);
-
- return 1;
- }
-@@ -754,7 +754,7 @@
- n_buf_free(nbuf);
-
- if (outfile)
-- msgn(0, "LanVi graph saved as %s", outfile);
-+ msgn(0, _("LanVi graph saved as %s"), outfile);
-
- return 1;
- }
---- poldek-0.30-cvs20080820.23/./pkgset-req.c~ 2008-05-24 11:12:25.000000000 +0300
-+++ poldek-0.30-cvs20080820.23/./pkgset-req.c 2009-03-04 00:09:02.085813192 +0200
-@@ -118,7 +118,7 @@
- pkgs = pkgmark_get_packages(pms, PKGMARK_UNMETDEPS);
- if (pkgs) {
- n_assert(n_array_size(pkgs));
-- msgn(4, "Packages with unsatisfied dependencies:");
-+ msgn(4, _("Packages with unsatisfied dependencies:"));
-
- for (i=0; i < n_array_size(pkgs); i++) {
- struct pkg *pkg = n_array_nth(pkgs, i);
-@@ -184,7 +184,7 @@
- matches = n_hash_get(cache, streq);
-
- if (!matches)
-- msgn(4, " req %-35s --> NOT FOUND", streq);
-+ msgn(4, _(" req %-35s --> NOT FOUND"), streq);
- else if (n_array_size(matches) > 0) {
- msg(4, " req %-35s --> ", streq);
- for (ii=0; ii < n_array_size(matches); ii++)
-@@ -213,7 +213,7 @@
- l_err_notfound:
- nerrors++;
- if (poldek_VERBOSE > 3)
-- msgn(4, " req %-35s --> NOT FOUND", capreq_snprintf_s(req));
-+ msgn(4, _(" req %-35s --> NOT FOUND"), capreq_snprintf_s(req));
-
- pkgset_add_unreq(ps, pkg, req, 0);
- pkg_set_unmetdeps(pms, pkg);
-@@ -397,7 +397,7 @@
-
- if (!matched && pkgset_pm_satisfies(ps, req)) {
- matched = 1;
-- msgn(4, " req %-35s --> PM_CAP", capreq_snprintf_s(req));
-+ msgn(4, _(" req %-35s --> PM_CAP"), capreq_snprintf_s(req));
-
- *suspkgs = NULL;
- *npkgs = 0;
-@@ -591,7 +591,7 @@
- }
-
- } else {
-- msgn(4, " cnfl %-35s --> NOT FOUND",capreq_snprintf_s(cnfl));
-+ msgn(4, _(" cnfl %-35s --> NOT FOUND"), capreq_snprintf_s(cnfl));
- }
- }
- }
---- poldek-0.30-cvs20080820.23/./pm/pset/pset.c~ 2008-05-13 18:55:32.000000000 +0300
-+++ poldek-0.30-cvs20080820.23/./pm/pset/pset.c 2009-03-04 00:10:01.492220009 +0200
-@@ -584,7 +584,7 @@
-
- DBGF("in %p(%p) %s\n", pkg, tmp, pkg_id(pkg));
- if (pkg->recno > 0)
-- logn(LOGERR, "%s: recno is set, should not happen", pkg_id(pkg));
-+ logn(LOGERR, _("%s: recno is set, should not happen"), pkg_id(pkg));
-
- pkgset_add_package(db->ps, pkg);
- pkgdir_add_package(pkgdir, pkg);
-@@ -600,7 +600,7 @@
- else if (!do_pkgtslink(db, ts->cachedir, pkg, path))
- return 0;
-
-- msgn(2, "Copying %s to %s", path, pkgdir->path);
-+ msgn(2, _("Copying %s to %s"), path, pkgdir->path);
- }
- //dumpdir(pkgdir);
- return 1;
-@@ -643,7 +643,7 @@
-
- DBGF("un %p(%p) %s\n", pkg, tmp, pkg_id(pkg));
- n_array_push(db->paths_removed, n_strdup(path));
-- msgn(2, "Removing %s", path);
-+ msgn(2, _("Removing %s"), path);
- }
- }
- return 1;
-@@ -677,7 +677,7 @@
- nchanges = 0; /* count real made changes */
- n_assert(n_array_size(db->ps->pkgdirs) == 1);
- pkgdir = n_array_nth(db->ps->pkgdirs, 0);
-- msgn(0, "Operating on %s", pkgdir->path);
-+ msgn(0, _("Operating on %s"), pkgdir->path);
-
- for (i=0; i < n_array_size(db->paths_removed); i++) {
- const char *path = n_array_nth(db->paths_removed, i);
-@@ -688,7 +688,7 @@
-
- if (!ts->getop(ts, POLDEK_OP_JUSTDB)) {
- if (unlink(path) != 0) {
-- logn(LOGERR, "%s: unlink failed: %m", path);
-+ logn(LOGERR, _("%s: unlink failed: %m"), path);
- rc = 0;
- break;
- }
---- poldek-0.30-cvs20080820.23/./pm/rpm/misc.c~ 2008-07-22 18:34:53.000000000 +0300
-+++ poldek-0.30-cvs20080820.23/./pm/rpm/misc.c 2009-03-04 00:10:32.778885699 +0200
-@@ -121,7 +121,7 @@
- };
-
- i = 0;
-- msgn(3, "Loading internal capabilities");
-+ msgn(3, _("Loading internal capabilities"));
- while (functions[i]) {
- functions[i++](&ds, NULL);
- }
---- poldek-0.30-cvs20080820.23/./split.c~ 2008-02-02 23:49:04.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/./split.c 2009-03-04 00:10:58.952242782 +0200
-@@ -313,7 +313,7 @@
- for (i=0; i<n_array_size(stack); i++) {
- struct pkg *pkg = n_array_nth(stack, i);
- pkg_set_color(pkg, PKG_COLOR_WHITE);
-- msgn(3, "%s: rollback", pkg_snprintf_s(pkg));
-+ msgn(3, _("%s: rollback"), pkg_snprintf_s(pkg));
- }
- rc = 0;
- }
-@@ -464,7 +464,7 @@
-
- if (fnmatch(pd->mask, pkg->name, 0) == 0) {
- pri = pd->pri;
-- msgn(2, "split: assign %d pri to %s (mask %s)", pri,
-+ msgn(2, _("split: assign %d pri to %s (mask %s)"), pri,
- pkg_id(pkg), pd->mask);
- nmached++;
- break;
---- poldek-0.30-cvs20080820.23/./uninstall.c~ 2008-03-02 22:05:56.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/./uninstall.c 2009-03-04 00:11:59.532317383 +0200
-@@ -195,12 +195,12 @@
- if (pkg_isset_mf(uctx->pms, dbpkg, DBPKG_REV_ORPHANED))
- continue; /* was there */
-
-- msgn_i(3, indent, " %s requires %s", pkg_id(pkg), pkg_id(dbpkg));
-+ msgn_i(3, indent, _(" %s requires %s"), pkg_id(pkg), pkg_id(dbpkg));
-
- if (pkg_leave_orphans(uctx, dbpkg))
- continue;
-
-- msgn_i(1, indent, "%s marks orphaned %s (req %s)",
-+ msgn_i(1, indent, _("%s marks orphaned %s (req %s)"),
- pkg_id(pkg), pkg_id(dbpkg), capreq_snprintf_s(req));
-
- pkg_set_mf(uctx->pms, dbpkg, DBPKG_REV_ORPHANED);
-@@ -380,7 +380,7 @@
- int i;
- for (i=0; i < n_array_size(uctx->unpkgs); i++) {
- struct pkg *dbpkg = n_array_nth(uctx->unpkgs, i);
-- msgn(1, "freedbset %d %s", dbpkg->_refcnt, pkg_id(dbpkg));
-+ msgn(1, _("freedbset %d %s"), dbpkg->_refcnt, pkg_id(dbpkg));
- }
- #endif
- n_array_free(uctx->unpkgs);
-@@ -395,7 +395,7 @@
-
- for (i=0; i < n_array_size(uctx->unpkgs); i++) {
- struct pkg *dbpkg = n_array_nth(uctx->unpkgs, i);
-- msgn(1, "mark %s", pkg_id(dbpkg));
-+ msgn(1, _("mark %s"), pkg_id(dbpkg));
- pkg_hand_mark(uctx->ts->pms, dbpkg);
- n++;
- }
-@@ -534,7 +534,7 @@
- int32_t e = 0;
- int matched = 0;
-
-- msgn(2, "Trying %s\n", mask);
-+ msgn(2, _("Trying %s\n"), mask);
- if (resolve_package(uctx, ts, mask, NULL))
- return 1;
-
-@@ -546,7 +546,7 @@
- p = strrchr(tmp, '-');
- *p = '#';
-
-- msgn(2, " Trying %s\n", tmp);
-+ msgn(2, _(" Trying %s\n"), tmp);
-
- if (resolve_package(uctx, ts, tmp, NULL))
- return 1;
-@@ -558,7 +558,7 @@
- else
- n_snprintf(nmask, sizeof(nmask), "%s#%s-%s", n, v, r);
-
-- msgn(2, " Trying %s\n", nmask);
-+ msgn(2, _(" Trying %s\n"), nmask);
- DBGF("try %s => %s (%s, %s, %s)\n", mask, nmask, n, v, r);
- matched = resolve_package(uctx, ts, nmask, NULL);
-
-@@ -570,7 +570,7 @@
- n_snprintf(nmask, sizeof(nmask), "%s#%d:%s-%s", n, e, v, r);
- else
- n_snprintf(nmask, sizeof(nmask), "%s#%s-%s", n, v, r);
-- msgn(2, " Trying %s (arch=%s)\n", nmask, p);
-+ msgn(2, _(" Trying %s (arch=%s)\n"), nmask, p);
- matched = resolve_package(uctx, ts, nmask, p);
- }
- }
+++ /dev/null
---- vfile/vfreq.c.orig 2008-02-02 22:49:05.000000000 +0100
-+++ vfile/vfreq.c 2010-01-15 18:08:33.000000000 +0100
-@@ -282,7 +282,7 @@
- else
- req->uri = n_strdupl(tmp, len);
-
-- len = n_snprintf(tmp, sizeof(tmp), "%s://%s/%s", rreq.proto, rreq.host,
-+ len = n_snprintf(tmp, sizeof(tmp), "%s://%s%s", rreq.proto, rreq.host,
- req->uri);
- req->url = n_strdupl(tmp, len);
- req->port = rreq.port;
+++ /dev/null
---- pkg.h-orig 2009-03-31 12:08:29.238718195 +0200
-+++ pkg.h 2009-03-31 12:08:49.843187842 +0200
-@@ -106,7 +106,7 @@
- int32_t itime; /* date of installation */
-
- /* private, don't touch */
-- int16_t _refcnt;
-+ uint16_t _refcnt;
- tn_alloc *na;
- int16_t _buf_size;
- char _buf[0]; /* private, store all string members */
---- pkg.c-orig 2009-03-31 11:37:37.825570800 +0200
-+++ pkg.c 2009-03-31 12:05:24.631861551 +0200
-@@ -1458,7 +1458,7 @@
- pkg->na ? pkg->na->_refcnt : -1,
- pkg->_refcnt, &pkg->_refcnt);
- }
-- n_assert(pkg->_refcnt < INT16_MAX - 1);
-+ n_assert(pkg->_refcnt < UINT16_MAX - 1);
- pkg->_refcnt++;
- return pkg;
- }
+++ /dev/null
-diff --git a/install3/iset.c b/install3/iset.c
-index e891a13..8ecbd7f 100644
---- a/install3/iset.c
-+++ b/install3/iset.c
-@@ -238,6 +238,29 @@ int iset_provides(struct iset *iset, const struct capreq *cap)
- return pkg != NULL;
- }
-
-+// returns how many pkg reqs are in iset
-+int iset_reqs_score(struct iset *iset, const struct pkg *pkg)
-+{
-+ struct pkg_req_iter *it = NULL;
-+ const struct capreq *req = NULL;
-+ unsigned itflags = PKG_ITER_REQIN | PKG_ITER_REQDIR; // | PKG_ITER_REQDIR | PKG_ITER_REQSUG
-+ int score = 0;
-+
-+ n_assert(pkg->reqs);
-+
-+ it = pkg_req_iter_new(pkg, itflags);
-+ while ((req = pkg_req_iter_get(it))) {
-+ if (iset_provides(iset, req)){
-+ score++;
-+ if (capreq_versioned(req))
-+ score +=2;
-+ }
-+ }
-+ pkg_req_iter_free(it);
-+
-+ return score;
-+}
-+
- void iset_dump(struct iset *iset)
- {
- int i;
-diff --git a/install3/iset.h b/install3/iset.h
-index 3946c0e..7b3b08d 100644
---- a/install3/iset.h
-+++ b/install3/iset.h
-@@ -32,7 +32,11 @@ void iset_add(struct iset *iset, struct pkg *pkg, unsigned mflag);
- int iset_remove(struct iset *iset, struct pkg *pkg);
-
- int iset_provides(struct iset *iset, const struct capreq *cap);
-+// returns how many pkg reqs are in iset
-+int iset_reqs_score(struct iset *iset, const struct pkg *pkg);
-+
- int iset_has_pkg(struct iset *iset, const struct pkg *pkg);
-+// return 1st found pkg_is_kind_of from iset or null
- struct pkg *iset_has_kind_of_pkg(struct iset *iset, const struct pkg *pkg);
-
- #endif
-diff --git a/install3/requirements.c b/install3/requirements.c
-index ea9df61..37bb5e2 100644
---- a/install3/requirements.c
-+++ b/install3/requirements.c
-@@ -21,9 +21,8 @@ tn_array *filter_out_olders(struct i3ctx *ictx, tn_array *pkgs,
- const struct pkg *pkg)
- {
- tn_array *tmp = n_array_clone(pkgs);
-- int i;
--
-- for (i=0; i < n_array_size(pkgs); i++) {
-+
-+ for (unsigned int i=0; i < n_array_size(pkgs); i++) {
- struct pkg *p = n_array_nth(pkgs, i);
- int cmprc;
-
-@@ -49,7 +48,8 @@ static struct pkg *select_successor(int indent, struct i3ctx *ictx,
- {
- const struct pkg *selected_pkg = NULL;
- tn_array *pkgs, *tmp;
-- int i, max_score = 0, *scores;
-+ int max_score = 0, *scores;
-+ unsigned int i;
- int nconsidered = 0, nuncolored = 0;
-
- tracef(indent, "%s (c=%d)", pkg_id(pkg), pkg->color);
-@@ -73,13 +73,21 @@ static struct pkg *select_successor(int indent, struct i3ctx *ictx,
- selected_pkg = n_array_nth(pkgs, 0);
- goto l_end;
- }
--
-+
- /* multilib mode */
- scores = alloca(sizeof(*scores) * n_array_size(pkgs));
- for (i=0; i < n_array_size(pkgs); i++) {
- struct pkg *p = n_array_nth(pkgs, i);
- scores[i] = 0;
--
-+
-+ // extra 100 points for arch compatible
-+ if (pkg_is_kind_of(p, pkg) && pkg_is_arch_compat(p, pkg)) {
-+ scores[i] += 100;
-+ }
-+
-+ // extra points for reqs marked to install
-+ scores[i] += iset_reqs_score(ictx->inset, p);
-+
- if (pkg->color == 0 && p->color == 0) { /* both uncolored */
- scores[i] += 1;
- if (pkg_is_kind_of(p, pkg))
-@@ -93,14 +101,14 @@ static struct pkg *select_successor(int indent, struct i3ctx *ictx,
- } else if (pkg_is_colored_like(p, pkg)) {
- scores[i] += 2;
- }
--
-+
- trace(indent, "- %d. %s -> color %d, score %d", i, pkg_id(p),
-- p->color, scores[i]);
--
-- if (max_score < scores[i]) {
-- max_score = scores[i];
-- selected_pkg = p;
-- }
-+ p->color, scores[i]);
-+
-+ if (max_score < scores[i]) {
-+ max_score = scores[i];
-+ selected_pkg = p;
-+ }
-
- nconsidered++;
- }
-@@ -150,9 +158,7 @@ l_end:
- /* detect which package capability has "replaces" meaning, if any */
- static const char *get_replacemeant_capname(const struct pkg *pkg)
- {
-- int i;
--
-- for (i=0; i < n_array_size(pkg->cnfls); i++) {
-+ for (unsigned int i=0; i < n_array_size(pkg->cnfls); i++) {
- struct capreq *cnfl = n_array_nth(pkg->cnfls, i);
-
- if (capreq_versioned(cnfl) || !capreq_is_obsl(cnfl))
-@@ -194,7 +200,7 @@ struct pkg *find_successor_by(int indent, struct i3ctx *ictx,
- {
- struct pkg *bypkg = NULL;
- tn_array *pkgs, *tmp;
-- int i, best_i;
-+ unsigned int i, best_i;
-
- n_assert(tag == PS_SEARCH_OBSL || tag == PS_SEARCH_CAP);
- if ((pkgs = pkgset_search(ictx->ps, tag, pkg->name)) == NULL) {
-@@ -741,7 +747,7 @@ int i3_process_pkg_requirements(int indent, struct i3ctx *ictx,
- asks for suggested package, even though it is required. */
- if (ts->getop(ts, POLDEK_OP_SUGGESTS) && nerrors == 0) {
- tn_array *suggests = NULL;
-- int i;
-+ unsigned int i;
-
- suggests = with_suggests(indent + 2, ictx, pkg);
-
+++ /dev/null
-diff --git a/pkgfetch.c b/pkgfetch.c
-index 049eb0e..b2cffbd 100644
---- a/pkgfetch.c
-+++ b/pkgfetch.c
-@@ -105,11 +105,6 @@ void packages_fetch_summary(struct pm_ctx *pmctx, const tn_array *pkgs,
- msgn(1, _("_ (%s to download)."), buf);
- }
-
-- if (bytesused) {
-- char buf[64];
-- snprintf_size(buf, sizeof(buf), bytesused, 1, 1);
-- msg(1, _("After unpacking %s will be used."), buf);
-- }
- }
-
- msg(1, "_\n");
-diff --git a/poldek_ts.c b/poldek_ts.c
-index a0dd436..a670379 100644
---- a/poldek_ts.c
-+++ b/poldek_ts.c
-@@ -834,9 +834,10 @@ void poldek__ts_update_summary(struct poldek_ts *ts,
- void poldek__ts_display_summary(struct poldek_ts *ts)
- {
- int ninst = 0, ndep = 0, nrm = 0, npkgs = 0, parseable = 0;
-+ long int sinsts = 0, sdeps = 0, srems = 0, sdiff = 0;
- tn_array *ipkgs, *idepkgs, *rmpkgs, *pkgs;
- char ms[1024], *to, *prefix;
-- int n;
-+ int i, n;
-
- ipkgs = n_hash_get(ts->ts_summary, "I");
- idepkgs = n_hash_get(ts->ts_summary, "D");
-@@ -846,16 +847,34 @@ void poldek__ts_display_summary(struct poldek_ts *ts)
- ndep = idepkgs ? n_array_size(idepkgs) : 0;
- nrm = rmpkgs ? n_array_size(rmpkgs) : 0;
-
-- to = _("to install");
-- prefix = "I";
-- pkgs = ipkgs;
-- npkgs = ninst + ndep;
--
-- if (ts->type == POLDEK_TS_UNINSTALL) {
-+ if (ipkgs)
-+ for (i=0; i < ninst; i++) {
-+ struct pkg *pkg = n_array_nth(ipkgs, i);
-+ sinsts += pkg->size;
-+ }
-+ if (idepkgs)
-+ for (i=0; i < ndep; i++) {
-+ struct pkg *pkg = n_array_nth(idepkgs, i);
-+ sdeps += pkg->size;
-+ }
-+ if (rmpkgs)
-+ for (i=0; i < nrm; i++) {
-+ struct pkg *pkg = n_array_nth(rmpkgs, i);
-+ srems += pkg->size;
-+ }
-+
-+ if (ts->type != POLDEK_TS_UNINSTALL) {
-+ to = _("to install");
-+ prefix = "I";
-+ pkgs = ipkgs;
-+ npkgs = ninst + ndep;
-+ sdiff = sinsts + sdeps - srems;
-+ } else {
- to = _("to remove");
- prefix = "R";
- pkgs = rmpkgs;
- npkgs = nrm + ndep;
-+ sdiff = - srems - sdeps;
- nrm = 0;
- }
- n_assert(pkgs);
-@@ -896,6 +915,16 @@ void poldek__ts_display_summary(struct poldek_ts *ts)
- if (rmpkgs)
- packages_display_summary(1, "R", rmpkgs, parseable);
- }
-+
-+ if (sdiff != 0) {
-+ char size[64];
-+ snprintf_size(size, sizeof(size), labs(sdiff), 1, 1);
-+
-+ if (sdiff > 0)
-+ msgn(1, _("This operation will use %s of disk space."), size);
-+ else
-+ msgn(1, _("This operation will free %s of disk space."), size);
-+ }
- }
-
- tn_array *poldek_ts_get_summary(const struct poldek_ts *ts, const char *mark)
+++ /dev/null
-commit e7a7215898ec0c15ac5572d292a378f4a2cffdeb
-Author: Marcin Banasiak <megabajt@pld-linux.org>
-Date: Mon Feb 23 22:42:43 2009 +0100
-
- On upgrade don't suggest packages skipped during instalation.
-
- This change implements future described in this thread:
-
- http://lists.pld-linux.org/mailman/pipermail/pld-devel-pl/2008-June/145262.html
-
- Currently it is enabled by default and there is no way to disable this
- behaviour. Should it be possible?
-
-diff --git a/install3/requirements.c b/install3/requirements.c
-index dbb3092..bfbe481 100644
---- a/install3/requirements.c
-+++ b/install3/requirements.c
-@@ -595,6 +595,7 @@ static int process_req(int indent, struct i3ctx *ictx,
- static tn_array *with_suggests(int indent, struct i3ctx *ictx, struct pkg *pkg)
- {
- tn_array *suggests = NULL, *choices = NULL;
-+ struct pkg *oldpkg = NULL;
- int i, autochoice = 0;
-
- if (pkg->sugs == NULL)
-@@ -618,12 +619,15 @@ static tn_array *with_suggests(int indent, struct i3ctx *ictx, struct pkg *pkg)
-
- tracef(indent, "%s", pkg_id(pkg));
-
-+ /* gets old version of pkg (from marked for removal) */
-+ oldpkg = iset_has_kind_of_pkg(ictx->unset, pkg);
-+
- suggests = capreq_arr_new(4);
- n_array_ctl_set_freefn(suggests, NULL); /* 'weak' ref */
- for (i=0; i < n_array_size(pkg->sugs); i++) {
- struct capreq *req = n_array_nth(pkg->sugs, i);
- struct pkg *tomark = NULL;
--
-+
- if (iset_provides(ictx->inset, req)) {
- trace(indent, "- %s: already marked", capreq_stra(req));
- continue;
-@@ -633,6 +637,13 @@ static tn_array *with_suggests(int indent, struct i3ctx *ictx, struct pkg *pkg)
- trace(indent, "- %s: satisfied by db", capreq_stra(req));
- continue;
- }
-+
-+ /* on upgrade don't suggest package skipped during installation */
-+ if (oldpkg && oldpkg->sugs && capreq_arr_contains(oldpkg->sugs, capreq_name(req))) {
-+ trace(indent, "- %s: skipped on install -> don't suggest on upgrade",
-+ capreq_stra(req));
-+ continue;
-+ }
-
- if (!i3_find_req(indent, ictx, pkg, req, &tomark, NULL)) {
- logn(LOGWARN, _("%s: suggested %s not found, skipped"), pkg_id(pkg),
+++ /dev/null
---- poldek-0.30-cvs20080820.23/pm/rpm/rpminstall.c~ 2008-05-12 18:11:33.000000000 +0200
-+++ poldek-0.30-cvs20080820.23/pm/rpm/rpminstall.c 2008-12-08 13:13:03.226547469 +0100
-@@ -572,5 +572,5 @@
- msgn(1, _("Running%s..."), buf);
- }
-
-- return pm_rpm_execrpm(cmd, argv, 0, 0) == 0;
-+ return pm_rpm_execrpm(cmd, argv, 1, 0) == 0;
- }
+++ /dev/null
-commit 167f7fc08fc8f6aedf864f3fc3c77b4c96a86f84
-Author: Marcin Banasiak <megabajt@pld-linux.org>
-Date: Sat May 30 12:13:31 2009 +0200
-
- Decode strings that may be urlencoded before displaying.
-
-diff --git a/vfile/fetch.c b/vfile/fetch.c
-index 0a4ee5a..88d98dd 100644
---- a/vfile/fetch.c
-+++ b/vfile/fetch.c
-@@ -828,6 +828,39 @@ const char *vf_url_slim_s(const char *url, int maxl)
- return vf_url_slim(buf, sizeof(buf), url, maxl > 50 ? maxl : 60);
- }
-
-+char *vf_url_unescape(const char *url)
-+{
-+ char *unescaped = NULL;
-+ int unesclen = 0;
-+
-+ if (!url)
-+ return NULL;
-+
-+ unescaped = n_malloc(strlen(url) + 1);
-+
-+ while (*url) {
-+ char ch = *url;
-+
-+ if (*url == '%' && isxdigit(url[1]) && isxdigit(url[2])) {
-+ char str[3];
-+
-+ str[0] = url[1];
-+ str[1] = url[2];
-+ str[2] = '\0';
-+
-+ ch = (char)strtol(str, NULL, 16);
-+
-+ url += 2;
-+ }
-+
-+ unescaped[unesclen++] = ch;
-+ url++;
-+ }
-+
-+ unescaped[unesclen] = '\0';
-+
-+ return unescaped;
-+}
-
- int vf_find_external_command(char *cmdpath, int size, const char *cmd,
- const char *PATH)
-diff --git a/vfile/libvfile.sym b/vfile/libvfile.sym
-index c283fcb..d96d3a5 100644
---- a/vfile/libvfile.sym
-+++ b/vfile/libvfile.sym
-@@ -41,6 +41,7 @@ vf_url_proto
- vf_url_slim
- vf_url_slim_s
- vf_url_type
-+vf_url_unescape
- vf_userathost
- vf_valid_path
- vf_vlog
-diff --git a/vfile/vfetch.c b/vfile/vfetch.c
-index 7f23244..cb46dd1 100644
---- a/vfile/vfetch.c
-+++ b/vfile/vfetch.c
-@@ -219,8 +219,8 @@ int vfile__vf_fetch(const char *url, const char *dest_dir, unsigned flags,
- struct vflock *vflock = NULL;
- struct vf_request *req = NULL;
- char destpath[PATH_MAX];
-+ char *url_unescaped = NULL;
- int rc = 0;
--
-
- if (*vfile_verbose <= 0)
- flags |= VF_FETCH_NOLABEL|VF_FETCH_NOPROGRESS;
-@@ -239,11 +239,15 @@ int vfile__vf_fetch(const char *url, const char *dest_dir, unsigned flags,
-
- if ((mod = select_vf_module(url)) == NULL) { /* no internal module found */
- if ((flags & VF_FETCH_NOLABEL) == 0) {
-+ url_unescaped = vf_url_unescape(url);
-+
- if (urlabel)
- vf_loginfo(_("Retrieving %s::%s...\n"), urlabel,
-- n_basenam(url));
-+ n_basenam(url_unescaped));
- else
-- vf_loginfo(_("Retrieving %s...\n"), PR_URL(url));
-+ vf_loginfo(_("Retrieving %s...\n"), PR_URL(url_unescaped));
-+
-+ free(url_unescaped);
- }
-
- rc = vf_fetch_ext(url, destdir);
-@@ -298,11 +302,15 @@ int vfile__vf_fetch(const char *url, const char *dest_dir, unsigned flags,
- }
-
- if ((flags & VF_FETCH_NOLABEL) == 0) {
-+ url_unescaped = vf_url_unescape(req->url);
-+
- if (urlabel)
- vf_loginfo(_("Retrieving %s::%s...\n"), urlabel,
-- n_basenam(req->url));
-+ n_basenam(url_unescaped));
- else
-- vf_loginfo(_("Retrieving %s...\n"), PR_URL(req->url));
-+ vf_loginfo(_("Retrieving %s...\n"), PR_URL(url_unescaped));
-+
-+ free(url_unescaped);
- }
-
- if ((rc = do_vfile_req(REQTYPE_FETCH, mod, req, flags)) == 0) {
-diff --git a/vfile/vfile.h b/vfile/vfile.h
-index 0125a68..13501eb 100644
---- a/vfile/vfile.h
-+++ b/vfile/vfile.h
-@@ -182,6 +182,7 @@ const char *vf_url_hidepasswd_s(const char *url);
- const char *vf_url_slim(char *buf, int size, const char *url, int maxl);
- const char *vf_url_slim_s(const char *url, int maxl);
-
-+char *vf_url_unescape(const char *url);
-
- int vf_valid_path(const char *path);
- int vf_mkdir(const char *path);
+++ /dev/null
---- pkgcmp.c~ 2008-11-19 12:17:09.000000000 +0100
-+++ pkgcmp.c 2008-11-19 14:50:18.440454833 +0100
-@@ -44,7 +44,7 @@
- register int rc = strcmp(pkg->name, candidate->name);
-
- if (rc == 0 && poldek_conf_MULTILIB) {
-- rc = pkg_cmp_arch(pkg, candidate);
-+ rc = 1 - pkg_is_colored_like(candidate, pkg);
- //if (rc == 0)
- // DBGF("%s, %s => YES\n", pkg_id(candidate), pkg_id(pkg));
- }
---- upgrade-dist.c~ 2008-05-12 18:51:38.000000000 +0300
-+++ upgrade-dist.c 2008-11-19 17:20:20.947658293 +0200
-@@ -55,7 +55,7 @@
-
- i = n_array_bsearch_idx_ex(ts->ctx->ps->pkgs, dbpkg, (tn_fn_cmp)pkg_cmp_name);
- if (i < 0) {
-- msgn(3, "%-32s not found in repository", pkg_id(dbpkg));
-+ msgn(3, "%-32s not found in repository", pkg_id(dbpkg));
- return 1;
- }
-
-@@ -73,7 +73,7 @@
- }
-
- if (pkg == NULL) {
-- msgn(3, "%-32s not found in repository", pkg_id(dbpkg));
-+ msgn(3, "%-32s match not found in repository", pkg_id(dbpkg));
- return 1;
- }
-
+++ /dev/null
-Index: configure.in
-===================================================================
-RCS file: /cvsroot/poldek/poldek/configure.in,v
-retrieving revision 1.145
-retrieving revision 1.146
-diff -u -u -r1.145 -r1.146
---- configure.in 12 May 2008 15:51:38 -0000 1.145
-+++ configure.in 13 Feb 2010 22:00:08 -0000 1.146
-@@ -1,6 +1,6 @@
-
- dnl Process this file with autoconf to produce a configure script.
--dnl $Id$
-+dnl $Id$
-
- AC_INIT(poldek,0.30)
- AC_CONFIG_SRCDIR([capreq.c])
-@@ -234,6 +234,8 @@
- dnl Checks for libraries.
- AC_CHECK_LIB(bz2, BZ2_bzCompress)
- AC_CHECK_LIB(z, gzopen)
-+
-+AC_CHECK_FUNCS(gzungetc)
-
- DBLIB=""
- if test "${is_rpm4_0_4}." = "no." ; then
-Index: pkgdir/pkg_restore.c
-===================================================================
-RCS file: /cvsroot/poldek/poldek/pkgdir/pkg_restore.c,v
-retrieving revision 1.25
-retrieving revision 1.26
-diff -u -u -r1.25 -r1.26
---- pkgdir/pkg_restore.c 25 May 2008 09:25:31 -0000 1.25
-+++ pkgdir/pkg_restore.c 14 Feb 2010 16:10:26 -0000 1.26
-@@ -11,7 +11,7 @@
- */
-
- /*
-- $Id$
-+ $Id$
- */
-
- #ifdef HAVE_CONFIG_H
-@@ -149,7 +149,7 @@
- struct pkg tmpkg;
- off_t offs;
- unsigned long ul_offs;
-- char linebuf[4096];
-+ char linebuf[PATH_MAX];
- int nerr = 0, nread, pkg_loaded = 0;
- int tag, tag_binsize = PKG_STORETAG_SIZENIL;
- const char *errmg_double_tag = "%s:%lu: double '%c' tag";
-Index: pkgdir/pdir/pdir.c
-===================================================================
-RCS file: /cvsroot/poldek/poldek/pkgdir/pdir/pdir.c,v
-retrieving revision 1.31
-retrieving revision 1.32
-diff -u -u -r1.31 -r1.32
---- pkgdir/pdir/pdir.c 2 Feb 2008 21:49:04 -0000 1.31
-+++ pkgdir/pdir/pdir.c 14 Feb 2010 16:10:26 -0000 1.32
-@@ -11,7 +11,7 @@
- */
-
- /*
-- $Id$
-+ $Id$
- */
-
- #ifdef HAVE_CONFIG_H
-@@ -577,7 +577,7 @@
- int do_open(struct pkgdir *pkgdir, unsigned flags)
- {
- struct vfile *vf;
-- char linebuf[1024 * 256];
-+ char linebuf[PATH_MAX];
- int nline;
- int nerr = 0, nread;
- struct pkgroup_idx *pkgroups = NULL;
-Index: pkgdir/pdir/pdir_pkg_restore.c
-===================================================================
-RCS file: /cvsroot/poldek/poldek/pkgdir/pdir/pdir_pkg_restore.c,v
-retrieving revision 1.11
-retrieving revision 1.12
-diff -u -u -r1.11 -r1.12
---- pkgdir/pdir/pdir_pkg_restore.c 25 May 2008 09:25:31 -0000 1.11
-+++ pkgdir/pdir/pdir_pkg_restore.c 14 Feb 2010 16:10:26 -0000 1.12
-@@ -11,7 +11,7 @@
- */
-
- /*
-- $Id$
-+ $Id$
- */
-
- #ifdef HAVE_CONFIG_H
-@@ -135,7 +135,7 @@
- {
- struct pkgtags_s pkgt;
- off_t offs;
-- char linebuf[4096];
-+ char linebuf[PATH_MAX];
- int nerr = 0, nread, with_pkg = 0;
-
- const char *errmg_double_tag = "%s:%ld: double '%c' tag";
-Index: pkgdir/yum/yum.c
-===================================================================
-RCS file: /cvsroot/poldek/poldek/pkgdir/yum/yum.c,v
-retrieving revision 1.19
-retrieving revision 1.20
-diff -u -u -r1.19 -r1.20
---- pkgdir/yum/yum.c 2 Feb 2008 21:49:05 -0000 1.19
-+++ pkgdir/yum/yum.c 14 Feb 2010 16:10:26 -0000 1.20
-@@ -11,7 +11,7 @@
- */
-
- /*
-- $Id$
-+ $Id$
- */
-
- #ifdef HAVE_CONFIG_H
-@@ -128,7 +128,7 @@
- int do_open(struct pkgdir *pkgdir, unsigned flags)
- {
- struct vfile *vf;
-- char linebuf[1024 * 16];
-+ char linebuf[PATH_MAX];
- int nline, nerr = 0, nread, n;
- struct pkgroup_idx *pkgroups = NULL;
- struct idx idx;
-Index: write.c
-===================================================================
-RCS file: /cvsroot/poldek/tndb/write.c,v
-retrieving revision 1.11
-retrieving revision 1.12
-diff -u -u -r1.11 -r1.12
---- tndb/write.c 22 Jun 2007 18:20:58 -0000 1.11
-+++ tndb/write.c 14 Feb 2010 08:20:52 -0000 1.12
-@@ -45,7 +45,7 @@
-
- struct tndb *tndb_creat(const char *name, int comprlevel, unsigned flags)
- {
-- char path[PATH_MAX], mode[32] = "w+b";
-+ char path[PATH_MAX], mode[32] = "wb";
- tn_stream *st;
- struct tndb *db = NULL;
- int fd, n, type = TN_STREAM_STDIO;
-@@ -69,7 +69,7 @@
- if (n > 3 && strcmp(&name[n - 3], ".gz") == 0) {
- type = TN_STREAM_GZIO;
- if (comprlevel >= 0 && comprlevel < 10)
-- snprintf(mode, sizeof(mode), "w+b%d", comprlevel);
-+ snprintf(mode, sizeof(mode), "wb%d", comprlevel);
- }
-
- if ((st = n_stream_dopen(fd, mode, type)) == NULL)
---- vfile/vfile.c~ 2007-07-06 00:28:53.000000000 +0200
-+++ vfile/vfile.c 2010-02-23 17:47:55.496578466 +0100
-@@ -262,7 +262,7 @@
- char *mode = NULL;
-
- if ((vfmode & VFM_APPEND) == VFM_APPEND)
-- mode = "a+";
-+ mode = "a";
- else if (vfmode & VFM_RW)
- mode = "w";
- else
---- vfile/vfile.c~ 2010-02-23 17:47:55.496578466 +0100
-+++ vfile/vfile.c 2010-02-28 09:50:39.839991093 +0100
-@@ -288,7 +288,7 @@
- char *mode = NULL;
-
- if ((vfmode & VFM_APPEND) == VFM_APPEND)
-- mode = "a+";
-+ mode = "a";
- else if (vfmode & VFM_RW)
- mode = "w";
- else