From c68d3cc38a78a7eb80f88981ddfdc6db690038aa Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Tue, 17 Jul 2007 14:23:18 +0200 Subject: 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 Signed-off-by: Dan McGee --- lib/libalpm/deps.c | 68 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 27 deletions(-) (limited to 'lib') 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; -- cgit v1.2.3-24-g4f1b