From 0229051f07b90163342768d974cc7472b146bbc1 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 21 Nov 2010 15:38:46 -0300 Subject: [PATCH] qpkg: change prerequisite resolution order to be fully depth-first Until now, when considering adding a package, we processed its dependencies after completing the current list of dependencies. E.g., if we had a package A that depended on B and C, B depended on D, and C depended on E, then the sequence would have been A, B, C, ... We now process the dependencies of a package immediately after considering the package, so the sequence above would become A, B, D, C, ... The advantage of the new order is that it becomes easier to follow the dependency tree, which will be beneficial for loop detection and for ordering packages by installation order. - prereq.c (resolve): change prerequisite resolution order such that the dependencies of the package being considered are processed immediately, instead of deferring them until the end of the current dependency list - prereq.c (prereq): we can now pass the list of dependencies directly, without needing a list of lists element - test/resorder: test resolution order --- qpkg/prereq.c | 12 +++--------- qpkg/test/resorder | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) create mode 100755 qpkg/test/resorder diff --git a/qpkg/prereq.c b/qpkg/prereq.c index 1ddc125..cf9c7bd 100644 --- a/qpkg/prereq.c +++ b/qpkg/prereq.c @@ -210,12 +210,11 @@ static void resolve(struct list *next_dep, const struct ref *dep, continue; level++; append_install(pkg); - more_deps.refs = pkg->depends; + more_deps.refs = dep->next; more_deps.next = next_dep; more_conf.refs = pkg->conflicts; more_conf.next = conf; - resolve(&more_deps, dep->next, &more_conf); - next_dep = more_deps.next; + resolve(&more_deps, pkg->depends, &more_conf); backtrack(); level--; } @@ -224,13 +223,8 @@ static void resolve(struct list *next_dep, const struct ref *dep, struct pkg **prereq(struct pkg *pkg) { - struct list deps = { - .refs = pkg->depends, - .next = NULL - }; - /* @@@ make list of pre-existing conflicts */ - resolve(&deps, NULL, NULL); + resolve(NULL, pkg->depends, NULL); free(installs); return best; } diff --git a/qpkg/test/resorder b/qpkg/test/resorder new file mode 100755 index 0000000..7b1c943 --- /dev/null +++ b/qpkg/test/resorder @@ -0,0 +1,40 @@ +#!/bin/sh +. ./Common + +############################################################################### + +qpkg "resolution order" prereq A <