diff --git a/qpkg/gobble.c b/qpkg/gobble.c index 7f75d88..76aeb28 100644 --- a/qpkg/gobble.c +++ b/qpkg/gobble.c @@ -241,7 +241,7 @@ package: WHITESPACE; pkg = alloc_type(struct pkg); pkg->id = ID(packages); - pkg->more = pkg->id->value ? pkg->id->value : NULL; + pkg->more = pkg->id->value; pkg->id->value = pkg; pkg->version = NULL; pkg->filename = NULL; diff --git a/qpkg/prereq.c b/qpkg/prereq.c index c503d9d..a6865b9 100644 --- a/qpkg/prereq.c +++ b/qpkg/prereq.c @@ -111,6 +111,7 @@ static void push(struct pkg *pkg) } stack[n_stack++] = pkg; + assert(!pkg->mark && !pkg->installed); pkg->mark = 1; } @@ -158,6 +159,7 @@ static int conflicts(const struct pkg *pkg, const struct list *conf) static void resolve(struct list *next_dep, const struct ref *dep, struct list *conf) { +static int level = 0; struct list more_deps; struct list more_conf = { .next = conf @@ -173,14 +175,27 @@ static void resolve(struct list *next_dep, const struct ref *dep, next_dep = next_dep->next; } for (pkg = dep->pkg->value; pkg; pkg = pkg->more) { + if (best && n_stack == n_best) + return; +#if 0 +fprintf(stderr, "%*s", level, ""); +fprintf(stderr, "%.*s %p", ID2S(pkg->id), pkg); +if (pkg->version) +fprintf(stderr, " %.*s", ID2S(pkg->version)); +if (pkg->mark) fprintf(stderr, " +"); +if (pkg->installed) fprintf(stderr, " ***"); +fprintf(stderr, "\n"); +#endif + if (!satisfies(pkg, dep)) + continue; if (pkg->installed || pkg->mark) { + assert(!conflicts(pkg, conf)); resolve(next_dep, dep->next, conf); continue; } - if (!satisfies(pkg, dep)) - continue; if (conflicts(pkg, conf)) continue; +level++; push(pkg); more_deps.refs = pkg->depends; more_deps.next = next_dep; @@ -189,6 +204,7 @@ static void resolve(struct list *next_dep, const struct ref *dep, resolve(&more_deps, dep->next, &more_conf); next_dep = more_deps.next; pop(); +level--; } }