summaryrefslogtreecommitdiff
path: root/lib/libalpm/deps.c
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2007-07-17 14:23:18 +0200
committerDan McGee <dan@archlinux.org>2007-07-17 10:06:26 -0400
commitc68d3cc38a78a7eb80f88981ddfdc6db690038aa (patch)
tree8fdb26261bbd877b4a075455cf012d24dc4a166b /lib/libalpm/deps.c
parent466d289e6a3e7dbaf567b39485c49d67eac5b362 (diff)
downloadpacman-c68d3cc38a78a7eb80f88981ddfdc6db690038aa.tar.xz
libalpm/deps.c : split sortbydeps function.
The _alpm_sortbydeps function has two main part : 1) initialization of the graph structure 2) the sorting itself So it didn't seem bad to move the first part to a second function. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/deps.c')
-rw-r--r--lib/libalpm/deps.c68
1 files changed, 41 insertions, 27 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 30c505dd..cd20dd5c 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -107,6 +107,46 @@ int _alpm_depmiss_isin(pmdepmissing_t *needle, alpm_list_t *haystack)
return(0);
}
+/* Convert a list of pmpkg_t * to a graph structure,
+ * with a edge for each dependency.
+ * Returns a list of vertices (one vertex = one package)
+ * (used by alpm_sortbydeps)
+ */
+static alpm_list_t *_alpm_graph_init(alpm_list_t *targets)
+{
+ alpm_list_t *i, *j, *k;
+ alpm_list_t *vertices = NULL;
+ /* We create the vertices */
+ for(i = targets; i; i = i->next) {
+ pmgraph_t *vertex = _alpm_graph_new();
+ vertex->data = (void *)i->data;
+ vertices = alpm_list_add(vertices, vertex);
+ }
+
+ /* We compute the edges */
+ for(i = vertices; i; i = i->next) {
+ pmgraph_t *vertex_i = i->data;
+ pmpkg_t *p_i = vertex_i->data;
+ /* TODO this should be somehow combined with _alpm_checkdeps */
+ for(j = vertices; j; j = j->next) {
+ pmgraph_t *vertex_j = j->data;
+ pmpkg_t *p_j = vertex_j->data;
+ int child = 0;
+ for(k = alpm_pkg_get_depends(p_i); k && !child; k = k->next) {
+ pmdepend_t *depend = alpm_splitdep(k->data);
+ child = alpm_depcmp(p_j, depend);
+ free(depend);
+ }
+ if(child) {
+ vertex_i->children =
+ alpm_list_add(vertex_i->children, vertex_j);
+ }
+ }
+ vertex_i->childptr = vertex_i->children;
+ }
+ return(vertices);
+}
+
/* Re-order a list of target packages with respect to their dependencies.
*
* Example (PM_TRANS_TYPE_ADD):
@@ -125,7 +165,6 @@ int _alpm_depmiss_isin(pmdepmissing_t *needle, alpm_list_t *haystack)
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
{
alpm_list_t *newtargs = NULL;
- alpm_list_t *i, *j, *k;
alpm_list_t *vertices = NULL;
alpm_list_t *vptr;
pmgraph_t *vertex;
@@ -138,32 +177,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
_alpm_log(PM_LOG_DEBUG, "started sorting dependencies");
- /* We create the vertices */
- for(i = targets; i; i = i->next) {
- pmgraph_t *vertex = _alpm_graph_new();
- vertex->data = (void *)i->data;
- vertices = alpm_list_add(vertices, vertex);
- }
-
- /* We compute the edges */
- for(i = vertices; i; i = i->next) {
- pmgraph_t *vertex_i = i->data;
- pmpkg_t *p_i = vertex_i->data;
- /* TODO this should be somehow combined with _alpm_checkdeps */
- for(j = vertices; j; j = j->next) {
- pmgraph_t *vertex_j = j->data;
- pmpkg_t *p_j = vertex_j->data;
- int child = 0;
- for(k = alpm_pkg_get_depends(p_i); k && !child; k = k->next) {
- pmdepend_t *depend = alpm_splitdep(k->data);
- child = alpm_depcmp(p_j, depend);
- free(depend);
- }
- if(child) vertex_i->children =
- alpm_list_add(vertex_i->children, vertex_j);
- }
- vertex_i->childptr = vertex_i->children;
- }
+ vertices = _alpm_graph_init(targets);
vptr = vertices;
vertex = vertices->data;