poldek: poldek/install3/ictx.h, poldek/install3/misc.c, poldek/install3/req...
mis
mis at pld-linux.org
Sun May 25 00:56:45 CEST 2008
Author: mis Date: Sat May 24 22:56:45 2008 GMT
Module: poldek Tag: HEAD
---- Log message:
- fixed bug #143#c5
- improved select_successor()
- code cleanups
---- Files affected:
poldek/poldek/install3:
ictx.h (1.3 -> 1.4) , misc.c (1.8 -> 1.9) , requirements.c (1.9 -> 1.10)
---- Diffs:
================================================================
Index: poldek/poldek/install3/ictx.h
diff -u poldek/poldek/install3/ictx.h:1.3 poldek/poldek/install3/ictx.h:1.4
--- poldek/poldek/install3/ictx.h:1.3 Sat Feb 2 16:38:37 2008
+++ poldek/poldek/install3/ictx.h Sun May 25 00:56:40 2008
@@ -135,9 +135,6 @@
int i3_is_pkg_installable(struct poldek_ts *ts, struct pkg *pkg,
int is_hand_marked);
-struct pkg *i3_select_successor(int indent, struct i3ctx *ictx,
- const struct pkg *pkg);
-
int i3_select_best_pkg(int indent, struct i3ctx *ictx,
const struct pkg *marker, tn_array *candidates);
================================================================
Index: poldek/poldek/install3/misc.c
diff -u poldek/poldek/install3/misc.c:1.8 poldek/poldek/install3/misc.c:1.9
--- poldek/poldek/install3/misc.c:1.8 Tue May 13 17:52:49 2008
+++ poldek/poldek/install3/misc.c Sun May 25 00:56:40 2008
@@ -145,24 +145,25 @@
return 0;
}
-static void prepare_arch_scores(int *scores, const tn_array *pkgs)
+/* scores must be the same size of n_array_size(pkgs) */
+static void add_arch_scores(int *scores, const tn_array *pkgs)
{
- int i, min_score = INT_MAX;
-
+ int i, min_score = INT_MAX, nscore;
+ int *arch_scores;
+
+ arch_scores = alloca(n_array_size(pkgs) * sizeof(*arch_scores));
for (i=0; i < n_array_size(pkgs); i++) {
struct pkg *pkg = n_array_nth(pkgs, i);
- scores[i] = pkg_arch_score(pkg);
- if (min_score > scores[i])
- min_score = scores[i];
+ arch_scores[i] = pkg_arch_score(pkg);
+ if (min_score > arch_scores[i])
+ min_score = arch_scores[i];
}
-
+
for (i=0; i < n_array_size(pkgs); i++) {
- if (scores[i] == min_score)
- scores[i] = 1; /* 1 point for best fit */
- else
- scores[i] = 0;
- DBGF("%s %d\n", pkg_id(n_array_nth(pkgs, i)), scores[i]);
+ if (arch_scores[i] == min_score)
+ scores[i] += 1; /* 1 point for best fit */
+ DBGF("%s %d\n", pkg_id(n_array_nth(pkgs, i)), arch_scores[i]);
}
}
@@ -171,7 +172,7 @@
static int do_select_best_pkg(int indent, struct i3ctx *ictx,
const struct pkg *marker, tn_array *candidates)
{
- int *conflicts, min_nconflicts, j, i_best, *scores, *arch_scores = NULL;
+ int *conflicts, min_nconflicts, j, i_best, *scores;
int i, max_score, npkgs, same_packages_different_arch = 0;
npkgs = n_array_size(candidates);
@@ -186,11 +187,6 @@
conflicts = alloca(npkgs * sizeof(*conflicts));
min_nconflicts = 0;
- /* marker noarch -> suggests architecture not */
- if (poldek_conf_MULTILIB && marker && n_str_eq(pkg_arch(marker), "noarch")) {
- arch_scores = alloca(npkgs * sizeof(*arch_scores));
- prepare_arch_scores(arch_scores, candidates);
- }
i_best = -1;
for (i=0; i < n_array_size(candidates); i++) {
@@ -223,8 +219,6 @@
scores[i] += 2;
else if (pkg_cmp_arch(pkg, marker) == 0)
scores[i] += 1;
- else if (arch_scores)
- scores[i] += arch_scores[i];
}
//DBGF_F("xxx %s %d %d\n", pkg_id(pkg), pkg_arch_score(pkg), arch_scores[i]);
@@ -270,6 +264,10 @@
}
DBGF("%d %d %d\n", i, scores[i], conflicts[i]);
}
+
+ /* marker noarch -> suggests architecture not */
+ if (poldek_conf_MULTILIB && marker && n_str_eq(pkg_arch(marker), "noarch"))
+ add_arch_scores(scores, candidates);
max_score = scores[0];
i_best = 0;
@@ -326,53 +324,6 @@
return i;
}
-struct pkg *i3_select_successor(int indent, struct i3ctx *ictx,
- const struct pkg *pkg)
-{
- const struct pkg *selected_pkg = NULL;
- tn_array *pkgs;
- int i;
-
-
- if ((pkgs = pkgset_search(ictx->ps, PS_SEARCH_NAME, pkg->name)) == NULL) {
- tracef(indent + 2, "%s not found, return", pkg_id(pkg));
- return NULL;
- }
-
- selected_pkg = pkg;
- for (i=0; i < n_array_size(pkgs); i++) {
- struct pkg *p = n_array_nth(pkgs, i);
- int cmprc;
-
- if (pkg->color == 0) { /* no color -> use arch */
- if (!pkg_is_kind_of(p, pkg)) {
- tracef(indent + 2, "%s is not like %s, skipped", pkg_id(p), pkg_id(pkg));
- continue;
- }
-
- } else if (!pkg_is_colored_like(p, pkg)) {
- tracef(indent + 2, "%s is not colored like %s, skipped", pkg_id(p), pkg_id(pkg));
- continue;
- }
-
- if (selected_pkg == NULL)
- selected_pkg = pkg;
-
- cmprc = pkg_cmp_evr(p, selected_pkg);
- if (cmprc < 0 && poldek_ts_issetf(ictx->ts, POLDEK_TS_DOWNGRADE))
- selected_pkg = p;
- else if (cmprc > 0)
- selected_pkg = p;
- }
-
- if (selected_pkg == pkg)
- selected_pkg = NULL;
-
- tracef(indent, "RET %s (for %s)",
- selected_pkg ? pkg_id(selected_pkg) : "NULL", pkg_id(pkg));
-
- return (struct pkg*)selected_pkg;
-}
static inline int any_is_marked(struct i3ctx *ictx, tn_array *pkgs)
{
================================================================
Index: poldek/poldek/install3/requirements.c
diff -u poldek/poldek/install3/requirements.c:1.9 poldek/poldek/install3/requirements.c:1.10
--- poldek/poldek/install3/requirements.c:1.9 Tue May 13 18:25:09 2008
+++ poldek/poldek/install3/requirements.c Sun May 25 00:56:40 2008
@@ -16,6 +16,137 @@
#include "ictx.h"
+static
+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++) {
+ struct pkg *p = n_array_nth(pkgs, i);
+ int cmprc;
+
+ if ((cmprc = pkg_cmp_evr(p, pkg)) == 0)
+ continue;
+
+ if (cmprc > 0 && poldek_ts_issetf(ictx->ts, POLDEK_TS_DOWNGRADE))
+ continue;
+
+ if (cmprc < 0)
+ continue;
+
+ n_array_push(tmp, pkg_link(p));
+ }
+ if (n_array_size(tmp) == 0)
+ n_array_cfree(&tmp);
+
+ return tmp;
+}
+
+static struct pkg *select_successor(int indent, struct i3ctx *ictx,
+ const struct pkg *pkg)
+{
+ const struct pkg *selected_pkg = NULL;
+ tn_array *pkgs, *tmp;
+ int i, max_score = 0, *scores;
+ int nconsidered = 0, nuncolored = 0;
+
+ tracef(indent, "%s (c=%d)", pkg_id(pkg), pkg->color);
+ indent += 2;
+
+ if ((pkgs = pkgset_search(ictx->ps, PS_SEARCH_NAME, pkg->name)) == NULL) {
+ tracef(indent, "%s not found, return", pkg->name);
+ return NULL;
+ }
+
+ if ((tmp = filter_out_olders(ictx, pkgs, pkg)) == NULL) {
+ n_array_free(pkgs);
+ tracef(indent, "%s not found, return", pkg->name);
+ return NULL;
+ }
+
+ n_array_free(pkgs);
+ pkgs = tmp;
+
+ if (!poldek_conf_MULTILIB) {
+ 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;
+
+ if (pkg->color == 0 && p->color == 0) { /* both uncolored */
+ scores[i] += 1;
+ if (pkg_is_kind_of(p, pkg))
+ scores[i] += 2;
+ nuncolored++;
+
+ } else if (pkg->color == 0) { /* no color -> use arch */
+ if (pkg_is_kind_of(p, pkg))
+ scores[i] += 1;
+
+ } 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;
+ }
+
+ nconsidered++;
+ }
+
+ if (max_score == 0) /* noone fits */
+ selected_pkg = NULL;
+
+ /* if all candidates are pair-uncolored and scored the same
+ then use arch score */
+ if (nuncolored == nconsidered) {
+ int all_scores_equal = 1;
+ int v = scores[0], best_arch_score = INT_MAX;
+
+ n_assert(max_score > 0);
+ for (i=1; i < n_array_size(pkgs); i++) {
+ if (v != scores[i]) {
+ all_scores_equal = 0;
+ break;
+ }
+ }
+
+ if (!all_scores_equal)
+ goto l_end;
+
+ /* add arch_score */
+ for (i=0; i < n_array_size(pkgs); i++) {
+ struct pkg *p = n_array_nth(pkgs, i);
+ int v = pkg_arch_score(p);
+
+ if (v < best_arch_score) {
+ best_arch_score = v;
+ selected_pkg = p;
+ }
+
+ trace(indent + 2, "-- %d. %s -> archscore %d", i, pkg_id(p), v);
+ }
+ }
+
+l_end:
+ n_array_cfree(&pkgs);
+ tracef(indent, "RET %s (for %s)",
+ selected_pkg ? pkg_id(selected_pkg) : "NULL", pkg_id(pkg));
+
+ return (struct pkg*)selected_pkg;
+}
+
/* detect which package capability has "replaces" meaning, if any */
static const char *get_replacemeant_capname(const struct pkg *pkg)
{
@@ -106,19 +237,7 @@
return NULL;
}
- for (i=best_i; i < n_array_size(pkgs); i++) {
- struct pkg *p = n_array_nth(pkgs, i);
-
- if (strcmp(pkg->name, p->name) == 0) /* same packages */
- continue;
-#if 0 /* needless here */
- if (poldek_conf_MULTILIB) {
- if (!pkg_is_colored_like(p, pkg))
- continue;
- }
-#endif
- bypkg = p;
- }
+ bypkg = n_array_nth(pkgs, best_i);
n_array_free(pkgs);
DBGF("%s -> %s\n", pkg_id(pkg), bypkg ? pkg_id(bypkg) : "NONE");
@@ -140,7 +259,7 @@
memset(succ, 0, sizeof(*succ));
- if ((p = i3_select_successor(indent, ictx, pkg)) == NULL) {
+ if ((p = select_successor(indent, ictx, pkg)) == NULL) {
if (ictx->ts->getop(ictx->ts, POLDEK_OP_OBSOLETES)) {
/* anybody provides, or obsoletes me? */
p = find_successor_by(indent, ictx, pkg, PS_SEARCH_CAP);
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/install3/ictx.h?r1=1.3&r2=1.4&f=u
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/install3/misc.c?r1=1.8&r2=1.9&f=u
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/poldek/poldek/install3/requirements.c?r1=1.9&r2=1.10&f=u
More information about the pld-cvs-commit
mailing list