summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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;